I use the following project structure. A project for me is all that PyCharm sees. Those. the project is not only django startproject but also all sorts of documentation files, docker-compose configs, etc. It looks like this:

 . (Папка ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π° PyCharm) β”œβ”€β”€ env β”œβ”€β”€ site_proj (Π‘Π°ΠΌ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚ Django) β”‚  β”œβ”€β”€ chat_app β”‚  β”‚  β”œβ”€β”€ migrations β”‚  β”‚  β”œβ”€β”€ __pycache__ β”‚  β”‚  β”œβ”€β”€ templates β”‚  β”‚  β”œβ”€β”€ admin.py β”‚  β”‚  β”œβ”€β”€ apps.py β”‚  β”‚  β”œβ”€β”€ consumers.py β”‚  β”‚  β”œβ”€β”€ __init__.py β”‚  β”‚  β”œβ”€β”€ models.py β”‚  β”‚  β”œβ”€β”€ routing.py β”‚  β”‚  β”œβ”€β”€ tests.py β”‚  β”‚  β”œβ”€β”€ urls.py β”‚  β”‚  └── views.py β”‚  β”œβ”€β”€ site_proj β”‚  β”‚  β”œβ”€β”€ __pycache__ β”‚  β”‚  β”œβ”€β”€ __init__.py β”‚  β”‚  β”œβ”€β”€ routing.py β”‚  β”‚  β”œβ”€β”€ settings.py β”‚  β”‚  β”œβ”€β”€ urls.py β”‚  β”‚  └── wsgi.py β”‚  β”œβ”€β”€ db.sqlite3 β”‚  └── manage.py β”œβ”€β”€ docker-compose.yml └── README.md 

Those. Everything related to the Django project lies in site_proj and does not interfere with files that do not belong to Django.

From here there are problems with import:

one)

 # ./site_proj/site_proj/routing.py from ..site_proj import chat_app 

ValueError: attempted relative import beyond top-level package

2)

 # ./site_proj/site_proj/routing.py from site_proj import chat_app # PyCharm autocomplete 

django.core.exceptions.ImproperlyConfigured: Cannot import ASGI_APPLICATION module 'site_proj.routing'

IDE: enter image description here

3)

 # ./site_proj/site_proj/routing.py from site_proj.chat_app import routing 

django.core.exceptions.ImproperlyConfigured: Cannot import ASGI_APPLICATION module 'site_proj.routing'

If the root folder for the IDE is the Django project folder, then everything will be ok, but I don’t want to. What is the problem and how to solve it?

  • I have a suspicion that the text of the ImproperlyConfigured error is not given in its entirety - andreymal
  • I don’t know what is there with PyCharm, but judging by the structure, the usual import chat_app should work fine - andreymal
  • @andreymal yes, as it turned out works. IDE swears, paints red, but it works. It remains to deal with IDE ... Do not know what could be the problem here? - Ivan Blohin

0