1

My question is rather difficult to wrap in words, but let's try:

I reckon it's easier to explain my problem with a chart demonstrating my django project structure:

Project1 -------- /Project1

                        settings.py
                        urls.py
                        models.py
                        views.py
            manage.py

            /App1
                        urls.py
                        models.py
                        views.py

Now, in my views.py in App1, how could I do "project1.models import *" without hard coding "project1"? Instead, I would need to have a dynamic name of the main project (project1 in this case).

My goal is that I could use this same structure also in my next project with as little changes in the code as possible. In this case, at the moment I would need to change that one line in my App1 views to whatever is the name of my project.

Thanks!

4

1 回答 1

4

You can use relative imports:

from ..models import *
于 2012-08-31T13:37:39.777 回答