0

Possible Duplicate:
Where should i create django apps in django 1.4?

In Django version 1.4, the structure has changed, the manage.py get out to the top level. Use the tutorial in the django webiste, the project's name is mysite, the structure is like this:

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

and I want to create a app. In the tutorial, It place the app right next to the manage.py, so the app is on the top level too, just like this:

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

so:

  1. what is the different if I create the app in the secend level(as right next to the settings.py) ?

  2. if I create the app on the top level, and there is some static file, the mysite and the polls all should to use, so where to place the static/ directory ?

Community
  • 1
  • 1
Tanky Woo
  • 4,906
  • 9
  • 44
  • 75

2 Answers2

2

Django changed the project layout to end the dreaded era of myproject.myapp.something imports. When you have those type of imports scattered around your codebase, you can't move anything around or re-use the app(s) in another project. The new layout (apps at the same level as project), makes the imports app-relative, rather than project-relative, simplifying things greatly.

The only thing that should go in the root directoy of your code is your app directories, your project directory and manage.py. Anything project-wide (settings, templates, static files, etc, should go in the project directory.

That said, STATIC_ROOT should point to myproject/static, but you should not manually create that directory, nor manually put anything in it. Static files tied to a particular app, should go in that app's static directory. Any project-wide static files should go in an entirely different directory (not the same as either STATIC_ROOT or MEDIA_ROOT). You then add that directory to STATICFILES_DIRS, so Django will include it in development and when running the collectstatic management command.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
1

You can use a template to start the project, like this:

https://github.com/goinnn/django-base-template

In these templates the place of the applications is defined already

Goin
  • 3,856
  • 26
  • 44