manage.py - not in project folder?
Asked Answered
O

3

5

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.

Overly answered 27/2, 2013 at 21:41 Comment(1)
Is the site structure you posted the actual structure, or an example?Osculate
C
7

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.

Cayenne answered 27/2, 2013 at 21:43 Comment(4)
Whether it's correct or not, Django's not finding his settings file. That's indicative of something being wrong somewhere.Osculate
he said it can't find it after he moved manage.py into mysite/mysite.Cayenne
Ok, now I understand. Got really confused there for awhile. Thanks!Overly
For some additional details see the Docs here (the layout changed in version 1.5): docs.djangoproject.com/en/1.5/intro/tutorial01/…Fillander
L
3

@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
Lavation answered 27/2, 2013 at 21:45 Comment(0)
K
1

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.

Khoury answered 27/2, 2013 at 21:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.