Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 1.4 (MEDIA_ROOT, STATIC_ROOT, TEMPLATE_DIRS)

Tags:

django

I have a Django 1.3 project with this options in settings.py

SITE_ROOT = os.path.dirname(os.path.realpath(__file__))

STATIC_ROOT = os.path.join(SITE_ROOT, 'static')

MEDIA_ROOT = os.path.join(SITE_ROOT, 'media')

TEMPLATE_DIRS = ( os.path.join(SITE_ROOT, 'templates'), )

But in Django 1.4 by default settings.py is moved in subdirectory with name that is equal to project name. Because of that static, media and templates directories now have to be moved in the same subdirectory?

Is this what I have to do, or just change STATIC_ROOT, MEDIA_ROOT and TEMPLATE_DIRS options?

I know that both variants are OK, but what is best practice for this in Django 1.4?

And also I know that every app can have it's own templates and static directories.

And is it better to put all other application directories inside the same subdirectory? This is not what is happening by default using manage.py startapp

like image 883
Julian Popov Avatar asked May 29 '12 12:05

Julian Popov


1 Answers

OK the scheme that I follow is this:

myproject/requirements.txt - pip installable packages

myproject/deployment - Deployment stuff like server config files, fixtures(dummy data), etc.

myproject/docs - project's docs

myproject/tests - project's tests

myproject/myproject - project's operational code(and settings.py, urls.py)

Expanding myproject/myproject folder:

myproject/myproject/app1 - a regular app(encompassing its specific templates/static files)

myproject/myproject/app2 - another regular app(same as above)

myproject/myproject/website - semi special app, by convention.

This website app houses basically 4 things:

1) an empty models.py(so that django will consider it as a valid app)

2) a views.py with the entry point index view. Maybe some other views that don't fit in any other specific app.

3) a management dir with custom django commands which apply to the whole project.

4) a templates dir that has the 404.html and 505.html. Also it has a subdir called website that includes universal/base html templates that every other app extends, plus the index.html.

5) a static dir with subsequent subdirs named css, js and media for global static files.

Nothing exotic I guess. I think that most people follow a similar pattern, but I would like to here any inefficiencies with this, if any.

EDIT: with regards to settings for production VS development I use the popular settings_local pattern, which you can read here and eventually will lead you here, which describes a better pattern.

like image 95
rantanplan Avatar answered Sep 30 '22 16:09

rantanplan