Yusif Mammadov
Yusif Mammadov

Reputation: 53

Why my_task.delay() works only within tasks module, not in models or views modules?

I have created tasks.py in my app. Celery tasks I have created can be called in cmd or inside tasks.py itself. But it is not possible to call them in views.py or models.py.

Upvotes: 0

Views: 32

Answers (1)

Diego Vinícius
Diego Vinícius

Reputation: 2243

Where you file at? it should be inside your django project to be use.

If you place it in some folder keep in mind to make one file __init__.py so django can see that folder as part of the project

project
- app1
- - __init__.py
- - models.py
- - admin.py
- - ...
- app2
- - __init__.py
- - models.py
- - admin.py
- - ...
- tasks
- - __init__.py
- - my_task_file.py

Or you can use as command line:

import os

os.system('<code to call your script>');

Upvotes: 1

Related Questions