How do you access models from other installed apps in Django when in the same subdirectory?

后端 未结 2 1520
借酒劲吻你
借酒劲吻你 2021-01-29 04:17

I have the following structure for my project:

myproject/
|-- myproject/
|   |-- __init__.py
|   |-- settings.py
|   |-- urls.py
|   |-- wsgi.py
|-- apps/
|   |-         


        
2条回答
  •  失恋的感觉
    2021-01-29 04:39

    From the top of my head I can advise a few things:

    1. Check your __init__.py files if they are not empty you'll have access to only whats imported in them.
    2. Check if you are not running into circular imports - if in dashboard.models you import from data.models when it imports from dashboard.models.
    3. from apps.data import models or from apps.data.models import ModelName seems the right way to go - knowing this look for solutions.

提交回复
热议问题