priestc
priestc

Reputation: 35280

'app' level imports with django 1.4?

I have a django app that I developed in the 1.2 days. I'm now trying to port it over to the 1.4 project format.

The old way my project was set up was as follows:

django_project/
    settings.py
    manage.py
    urls.py
    app1/
    app2/
    app3/

I'm changing it to use the new manage.py and my directories look like this:

django_project/
    manage.py
    project
        urls.py
        wsgi.py
        app1/
        app2/
        app3/

The problem is that all over my code I import stuff like this:

from app1.models import SomeModel

which now gives me an import error. Doing this fixes it:

from project.app1.models import SomeModel

I really don't want to have to go all through my project to change all those imports. Is there something I'm missing? Is there an easier way? Or is this how you're supposed to do it?

Upvotes: 3

Views: 1067

Answers (2)

Ricardo Silva
Ricardo Silva

Reputation: 834

You can keep your current layout, since it will works fine. For new projects I think you can start to put your apps inside the 'project' module. If you check the 1.4 Release Notes you'll see it's the recommended layout. But if you are developing generics apps (that you can use in more than one project) probably the better place is project root.

Upvotes: 1

ilvar
ilvar

Reputation: 5841

You should not put your apps into the project module. Django's startapp puts them in the project root, as it was before. project module is a place for project-wide settings, urls and such stuff only. Your apps should stay outside, in project root.

Upvotes: 4

Related Questions