pythondjangoimport

Importing between two applications in a django project


I've got two applications (app1 and app2) in my django project.

I'm curious if there is a way to import things between applications.

baseProject  
--app1
----models.py  
----etc..
--app2
----models.py
----etc..

I'd like to be able, while in app2, to import something from the models section of app1. Is there an intended method to do this or am I planning bad architecture.


Solution

  • You can definitely do that, just import it as usual. Many authentication/registration-related apps import models from the "django.contrib.auth" app that comes with Django. You are free to import from any app, whether you wrote it or not.

    You just need to make sure the apps are on your PYTHONPATH, so that they can be imported.

    That said, it's always good to consider your design before importing things across apps. Make sure you're not creating a situation where you have a circular dependency between apps.