Django: how to handle imports in a reusable application

I am just starting with django. I don’t quite understand how I can write an application that I could use later. In every tutorial I read, I see the same piece of code:

view.py from project.app.models import MyModel 

So, if I transfer my applications to another project, I will have to change “project.app.models” so that it looks like “project2.app.models” for every application that I am moving. Is there any way to avoid this?

Thanks in advance.

+3
source share
1 answer

You must update your Python path with the directory containing your applications.

So you just need to:

 from app.models import MyModel 
+4
source

Source: https://habr.com/ru/post/1382848/


All Articles