1

What would be a good structure (best practise) for the folders in a Django application (1.7)? I'm not sure where to put the static data and file Uploads.

In all my projects it turns out different, but currently I have something like this (I left out a few obvious folders/files):

project/ bin/ include/ ... src/ manage.py main/ - settings.py - urls.py signup/ static/ static_/ + css + img + js static/ templates/ - index.html - base.html - ... uploads/ 

And also, I'd prefer to see url's like for example site.com/css/file.css instead of site.com/static/css/file.css , but somehow thats more complicated then it seems. How can that be accomplished?

2 Answers 2

2

I use the the following in setting.py (using Django v1.6.8 at the moment)

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.dirname(os.path.dirname(__file__)) STATIC_ROOT = os.path.join(BASE_DIR, 'static') MEDIA_ROOT = os.path.join(BASE_DIR, 'media') #TEMPLATE_DIRS = (os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "static", "templates"),) TEMPLATE_DIRS = ( os.path.join(BASE_DIR, 'templates'),) 

This gives me a folder layout

project/ manage.py project_app/ - settings.py - urls.py someother_app/ - admin.py - models.py - views.py static/ css/ javascript/ templates admin/ someother_app/ - base.html - index.html media/ 

I'm not sure what you mean when you say site.com/css/file.css. Something like <link rel="stylesheet" href="{{ STATIC_URL }}css/jquery.asmselect.css"> in the <head> of base.html uses the Django Framework to present your .css files. Why not use what is there? Saves time and effort.

Tommy.

Sign up to request clarification or add additional context in comments.

Comments

1

Here is a recommendation for the Django project layout from the book Two Scoops of Django:

repo_root/ .gitignore Makefile docs/ README.rst requirements.txt django_project_root/ manage.py media/ django_app_root/ static/ templates/ config/ __init__.py settings/ urls.py wsgi.py 

and is considered a three level project layout where:

  • Top Level (repo_root): high-level files required for deployment
  • Second Level (django_project_root): actual django project
  • Third Level (config): the django project configuration files.

Regarding file Uploads I would upload them from the browser directly to Amazons S3 file storage (or similar service). Otherwise you're hogging bandwidth and CPU time. Or if you must then in the media folder ^ and for security reasons please validate the file types uploaded.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.