Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

manage.py - not in project folder?

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.

like image 831
holyredbeard Avatar asked Dec 20 '22 09:12

holyredbeard


2 Answers

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.

like image 70
katy lavallee Avatar answered Jan 31 '23 08:01

katy lavallee


@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
like image 31
Glyn Jackson Avatar answered Jan 31 '23 07:01

Glyn Jackson