0

I have this file structure in Django project:

project
├── app
    └── __init__.py
        views.py
        ...
        tasks
        └── __init__.py
            server_tasks.py

In views.py I tried to import project/app/tasks/server_tasks.py by typing following statements

from tasks import server_tasks
or
from tasks.server_tasks import *

And python3 manage.py runserver gives me following output

  File "/home/user-unix/python/django_projects/project/app/views.py", line 6, in <module>
    from tasks import server_tasks
ModuleNotFoundError: No module named 'tasks'

How can I import server_tasks.py into views.py?

Here is a github repository containing a project

I tried answers from very similar question on stackoverflow but it doesn't work for me.

rad2
  • 13
  • 3
  • If `apps` is treated as a module by Django (I'm not sure of that), then you should be able to add one period to that: `from .tasks import server_tasks`. – Tim Roberts Jul 29 '23 at 18:58
  • @tim-roberts It gives me following output: `ModuleNotFoundError: No module named 'app.tasks.models'` – rad2 Jul 29 '23 at 19:05
  • Where did `models` come from? That's not in your description. The fact that it knows about `app.tasks` suggests this is the right road to go down. – Tim Roberts Jul 29 '23 at 19:09
  • @tim-roberts I added a link to repository containing project in question. I imported some View Classes from `.models` file, but i don't think `models` is the problem here. – rad2 Jul 29 '23 at 19:30
  • The error says `app.tasks.models`, but `models` is not INSIDE `tasks`, it is at the same level. – Tim Roberts Jul 29 '23 at 19:37

1 Answers1

0

Try

from app.tasks import server_tasks

Also, checked your repo. The server tasks file imports from .models, which is not in the same directory. Change that to

from app.models import Asset, AssetPriceHistory

Hope this helps.

devyneX
  • 16
  • 2