Question

I'm trying out Django for the first time, and I'm trying to follow the tutorial provided by the django team.

After I've created a new project I get the following folder/file structure, just as the tutorial says I should:

mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py

When I create an app I run:

python manage.py startapp polls

...which creates the app 'polls' in the same folder as the manage.py file - which gives me:

mysite/
    manage.py
    polls/
        __init__.py
        admin.py
        models.py
        tests.py
        views.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py

This means the app I created gets created outside my project folder, which, of course, should not be the case. I have tried to move manage.py inside the project folder. But when I do that and run:

python manage.py syncdb

...I get the following error:

raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" %     (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'testproject.settings' (Is it on sys.path?): No     module named testproject.settings

I guess I could move the app manually to the project folder, but this is something I shouldn't have to do.

So, either something is wrong in the tutorial (which I have very hard to believe), or I'm missing something out here (more likely).

Thanks in advance.

Was it helpful?

Solution

This is the new proper layout. "mysite/mysite" is an app, and "mysite/polls" is an app. The "mysite" parent folder is your project folder.

OTHER TIPS

@holyredbeard that is the correct layout are you reading the older documentation?

Useful reading: http://www.tdd-django-tutorial.com/blog/articles/2012/tutorials-updated-django-14-and-its-weird-new-fold/

Don't move the manage.py it should sit outside the apps and the project folder.

since 1.4 common layout example...

project_root/
   project_name/
       media/
       static/
       static_root/ (in production)
       templates/some_app/foo.html (overriding some_app at project level)
                /admin/some_app/some_model/change_list.html
                (overriding admin changelist for some_app.models.some_model)
       settings.py
       settings_deployment.py
       urls.py
   some_app/
       templates/some_app/foo.html
       urls.py
       views.py
       models.py
   manage.py

This is the official layout since version 1.4.

The rationale behind is explained well in the release notes: https://docs.djangoproject.com/en/dev/releases/1.4/#updated-default-project-layout-and-manage-py

Do not move manage.py. In general you can expect that Django's own scripts always do the right thing, you never need to move any files just to get it working.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top