3
The second approach assumes that .
is in sys.path
before any other directories that may contain a models
module. There is no requirement that .
be in it at all, so importing either via relative imports or via the app is best.
3
I personally, try to keep the convention of always importing from the app.
Don’t import from the project, because project name can change; your app can be used in some other project (at least you are supposed to make apps like that).
Don’t import from models
directly because, as Ignacio rightly mentions, it is not necessary that .
is in the python path.
But, App names are always on the python path. Django adds them to the python path (via set_environ(settings)
), on the top of the list, so you can be rest assured that the right files are always picked up.
- [Django]-Alias for app URI in Django project urls.py
- [Django]-How do I limit a text length and add dots to show continuation python django
- [Django]-How do I pass custom variable values to the django admin interface?
- [Django]-Deleting periodic task for celery scheduler in `settings.py` will not delete the actual task