I need to import a model from my application, then make a request, and send a sms, but I can not import my model, although the name is specified correctly, who can help ask, I will wait, thank you all!
Full traceback
> Traceback (most recent call last): File
> "c:\users\p.a.n.d.e.m.i.c\appdata\local\programs\python\python36-32\Lib\runpy.py",
> line 193, in _run_module_as_main
> "__main__", mod_spec) File "c:\users\p.a.n.d.e.m.i.c\appdata\local\programs\python\python36-32\Lib\runpy.py",
> line 85, in _run_code
> exec(code, run_globals) File "C:\Users\P.A.N.D.E.M.I.C\Desktop\td11\Scripts\celery.exe\__main__.py",
> line 9, in <module> File
> "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\celery\__main__.py",
> line 30, in main
> main() File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\celery\bin\celery.py",
> line 81, in main
> cmd.execute_from_commandline(argv) File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\celery\bin\celery.py",
> line 769, in execute_from_commandline
> super(CeleryCommand, self).execute_from_commandline(argv))) File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\celery\bin\base.py",
> line 311, in execute_from_commandline
> return self.handle_argv(self.prog_name, argv[1:]) File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\celery\bin\celery.py",
> line 761, in handle_argv
> return self.execute(command, argv) File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\celery\bin\celery.py",
> line 693, in execute
> ).run_from_argv(self.prog_name, argv[1:], command=argv[0]) File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\celery\bin\worker.py",
> line 179, in run_from_argv
> return self(*args, **options) File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\celery\bin\base.py",
> line 274, in __call__
> ret = self.run(*args, **kwargs) File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\celery\bin\worker.py",
> line 212, in run
> state_db=self.node_format(state_db, hostname), **kwargs File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\celery\worker\__init__.py",
> line 95, in __init__
> self.app.loader.init_worker() File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\celery\loaders\base.py",
> line 128, in init_worker
> self.import_default_modules() File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\celery\loaders\base.py",
> line 116, in import_default_modules
> signals.import_modules.send(sender=self.app) File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\celery\utils\dispatch\signal.py",
> line 166, in send
> response = receiver(signal=self, sender=sender, **named) File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\celery\fixups\django.py",
> line 73, in on_import_modules
> self.worker_fixup.validate_models() File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\celery\fixups\django.py",
> line 158, in validate_models
> django_setup() File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\django\__init__.py",
> line 27, in setup
> apps.populate(settings.INSTALLED_APPS) File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\django\apps\registry.py",
> line 108, in populate
> app_config.import_models() File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\site-packages\django\apps\config.py",
> line 202, in import_models
> self.models_module = import_module(models_module_name) File "c:\users\p.a.n.d.e.m.i.c\desktop\td11\lib\importlib\__init__.py",
> line 126, in import_module
> return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 978, in _gcd_import File
> "<frozen importlib._bootstrap>", line 961, in _find_and_load File
> "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
> File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
> File "<frozen importlib._bootstrap_external>", line 678, in
> exec_module File "<frozen importlib._bootstrap>", line 205, in
> _call_with_frames_removed File "C:\Users\P.A.N.D.E.M.I.C\Desktop\td11\newstudio\serials\models.py",
> line 11, in <module>
> from asynctasks.tasks import notification_for_new_series_task File
> "C:\Users\P.A.N.D.E.M.I.C\Desktop\td11\newstudio\asynctasks\tasks.py",
> line 7, in <module>
> from serials.models import FavoriteSerial ImportError: cannot import name 'FavoriteSerial'
celery app
from __future__ import absolute_import
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'newstudio.settings')
from django.conf import settings
from celery import Celery
app = Celery('newstudio',
backend='amqp',
broker='amqp://guest@127.0.0.1//')
# This reads, e.g., CELERY_ACCEPT_CONTENT = ['json'] from settings.py:
app.config_from_object('django.conf:settings')
# For autodiscover_tasks to work, you must define your tasks in a file called 'tasks.py'.
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print("Request: {0!r}".format(self.request))
this is tasks.py
from celery import Celery
from celery.decorators import task
from celery import shared_task
from django.conf import settings
from django.contrib.auth.models import User
from django.core.mail import send_mail
from serials.models import FavoriteSerial
@task(name="notification_for_new_series_task")
def notification_for_new_series_task(name_of_serial, number_of_season, number_of_series):
fav_serials_of_users = FavoriteSerial.objects.filter(favorite_serial__rus_name_of_seriall=name_of_serial)
for i in fav_serials_of_users:
email = i.user.email
subject = 'Вышел {1}x{2} эпизод сериала {0}'.format(name_of_serial, number_of_season, number_of_series)
from_email = settings.DEFAULT_FROM_EMAIL
message = 'Вышла новая серия, сериала {0} - {1}x{2} '.format(name_of_serial, number_of_season, number_of_series)
recipient_list = [email]
html_message = '<h1>Вышел {1}x{2} эпизод сериала <b>{0}</b><br></h1>'.format(name_of_serial, number_of_season, number_of_series)
send_mail(subject, message, from_email, recipient_list, fail_silently=False, html_message=html_message)
return