3
votes

I am new to Django and using Pycharm from IntelliJ as my IDE. When typing:

$ django-admin startproject mysite

the following project structure is generated:

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

This doesn't quite make sense since the files settings.py, urls.py, and wsgi.py are project specific, not app or package specific. Hence, they should go in the root folder just like manage.py. Please advise. Thanks.

2
the structure you listed did not make much sense - can you reformat it. I would expect that the startproject command is correct, and therefore the settings.py is in the right place. I know you can have urls.py for each app - as each app can have it's own set of urls & sub-urls.Tony Suffolk 66

2 Answers

0
votes

That is the typical project layout, as you can see in the tutorial.

You can change the layout if you want, but I recommend that you don't. If you moved settings.py that would confuse manage.py, if you moved urls.py then you'd have to update ROOT_URLCONF in settings.py, and so on.

0
votes

If you wish to store your settings.py, url.py and wsgi.py files in the root project directory with manage.py you can do so, but you will have to make a couple of alterations to the settings.py file and the way you run your project locally.

  • use python manage.py runserver --settings=settings (instead of the default python manage.py runserver -settings=mysite.settings) to tell Django to use a settings file in the root project directory.

  • change ROOT_URLCONF in settings.py from 'mysite.urls' to 'urls'.

  • change WSGI_APPLICATION in settings.py from 'mysite.wsgi.application' to 'wsgi.application'.

Depending on preferences, it is actually relatively common to change the structure of your project (within reason). For example, the well-read Django book Two Scoops of Django suggests that you store different versions of your settings.py files in a mysite/settings as follows (ignoring urls/wsgi/apps for the moment):

mysite/
    manage.py
    settings/
        base.py
        local.py
        staging.py
        production.py