Skip to content
Browse files

Updated for use with --template option in Django 1.4. Made project la…

…yout a little more 'railsy' too.
  • Loading branch information...
1 parent c6f62bc commit dcbc6b3df85856631104a89c369bd8d05cd1a63c @martinogden committed Mar 31, 2012
View
5 .gitignore
@@ -1,7 +1,6 @@
*.pyc
+*.pyo
.DS_Store
*~
-settings/local.py
+config/environments/local.py
media
-development.sqlite3
-
View
19 README.md
@@ -1,21 +1,24 @@
-Django Boilerplate
-==================
+Django Boilerplate (Updated for Django 1.4)
+===========================================
-A barebones default layout for organised Django development.
+A barebones default layout for organised Django development. Inspired a little by Ruby on Rails and 'Django Project Conventions by Zachary Voase (link below).
-### Quick install
+### Usage
-This assumes you have pip installed (if not, try `$ sudo easy_install pip`)
+This assumes you have pip and django installed (if not, try `$ sudo easy_install pip`)
- $ git clone git://github.com/martinogden/django-boilerplate.git
+ $ django-admin.py startproject --template http://github.com/martinogden/django-boilerplate/zipball/master project_name
+ $ cd project_name
$ pip install -r REQUIREMENTS
- $ python manage.py syncdb --settings=settings.development
+ $ python manage.py syncdb --migrate
### Settings
-There is a separate file for each environment `settings` (development, staging, production). These import the django default settings from settings.common and are intended to be used directly, e.g. `python manage.py validate --settings=settings.production` or `export PYTHONPATH=settings.development`.
+There is a separate file for each environment inside `config/environments` (development, staging, production). These import the django default settings from config.settings and are intended to be used directly, e.g. `python manage.py validate --settings=config.environments.production` or `export PYTHONPATH=config.environments.development`.
+
+Any settings added in `environments/local.py` will be picked up and override any previously defined settings. This is useful for sensitive information such as database credentials or the `SECRET_KEY` etc. By default this file will *NOT* be checked into git.
### Preinstalled Apps
View
0 settings/__init__.py → config/__init__.py
File renamed without changes.
View
0 __init__.py → config/environments/__init__.py
File renamed without changes.
View
19 config/environments/development.py
@@ -0,0 +1,19 @@
+from path import path
+from ..settings import *
+
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'NAME': PROJECT_ROOT / 'db/development.sqlite3',
+ }
+}
+
+DEBUG = True
+
+# config/environments/local.py is ignored to allow for easy settings
+# overrides without affecting others environments / developers
+try:
+ from local import *
+except ImportError:
+ pass
View
4 settings/production.py → config/environments/production.py
@@ -1,4 +1,4 @@
-from .common import *
+from ..settings import *
DATABASES = {
'default': {
@@ -13,8 +13,6 @@
DEBUG = False
TEMPLATE_DEBUG = DEBUG
-THUMBNAIL_DEBUG = DEBUG
-
# settings/local.py is ignored to allow for easy settings
# overrides without affecting others
View
3 settings/staging.py → config/environments/staging.py
@@ -1,4 +1,4 @@
-from .common import *
+from ..settings import *
DATABASES = {
'default': {
@@ -13,7 +13,6 @@
DEBUG = True
TEMPLATE_DEBUG = DEBUG
-THUMBNAIL_DEBUG = DEBUG
# settings/local.py is ignored to allow for easy settings
# overrides without affecting others
View
74 settings/common.py → config/settings.py
@@ -1,18 +1,16 @@
"""
-Common settings for all environments
+Django settings for {{ project_name }} project.
-Don't directly use this settings file, use
- development.py or production.py and import this file
+Common settings for all environments. Don't directly use this settings file,
+use environments/development.py or environments/production.py and import this
+file from there.
"""
import sys
from path import path
from django.conf import global_settings
PROJECT_ROOT = path(__file__).abspath().dirname().dirname()
-SITE_ROOT = PROJECT_ROOT.dirname()
-
-sys.path.insert(0, SITE_ROOT)
-sys.path.insert(0, PROJECT_ROOT / 'lib')
+sys.path.insert(0, PROJECT_ROOT / 'libs')
sys.path.insert(0, PROJECT_ROOT / 'apps')
DEBUG = True
@@ -27,15 +25,12 @@
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
-# On Unix systems, a value of None will cause Django to use the same
-# timezone as the operating system.
-# If running in a Windows environment this must be set to the same as your
-# system time zone.
-TIME_ZONE = 'Europe/London'
+# In a Windows environment this must be set to your system time zone.
+TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
-LANGUAGE_CODE = 'en-gb'
+LANGUAGE_CODE = 'en-us'
SITE_ID = 1
@@ -44,12 +39,15 @@
USE_I18N = False
# If you set this to False, Django will not format dates, numbers and
-# calendars according to the current locale
+# calendars according to the current locale.
USE_L10N = False
+# If you set this to False, Django will not use timezone-aware datetimes.
+USE_TZ = True
+
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
-MEDIA_ROOT = PROJECT_ROOT / 'media'
+MEDIA_ROOT = PROJECT_ROOT / 'public/media'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
@@ -60,23 +58,18 @@
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
-STATIC_ROOT = PROJECT_ROOT / 'static'
+STATIC_ROOT = PROJECT_ROOT / 'public/static'
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
-# URL prefix for admin static files -- CSS, JavaScript and images.
-# Make sure to use a trailing slash.
-# Examples: "http://foo.com/static/admin/", "/static/admin/".
-ADMIN_MEDIA_PREFIX = STATIC_URL + 'grappelli/'
-
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
- PROJECT_ROOT / 'staticfiles',
+ PROJECT_ROOT / 'static',
)
# List of finder classes that know how to find static files in
@@ -87,8 +80,13 @@
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
+# URL prefix for admin static files -- CSS, JavaScript and images.
+# Make sure to use a trailing slash.
+# Examples: "http://foo.com/static/admin/", "/static/admin/".
+ADMIN_MEDIA_PREFIX = STATIC_URL + 'grappelli/'
+
# Make this unique, and don't share it with anybody.
-SECRET_KEY = '76j-vbt4-51gwb&!kphe46*e@g#egf%%y8o##rc6o&dl4l((i@'
+SECRET_KEY = '{{ secret_key }}'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
@@ -103,9 +101,14 @@
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
+ # Uncomment the next line for simple clickjacking protection:
+ # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
-ROOT_URLCONF = 'urls'
+ROOT_URLCONF = 'config.urls'
+
+# Python dotted path to the WSGI application used by Django's runserver.
+WSGI_APPLICATION = 'config.wsgi.application'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
@@ -124,7 +127,6 @@
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
- # Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
@@ -134,20 +136,27 @@
'django_extensions',
'compressor',
- # Project specific apps
+ # Project specific apps go here
+ # 'my_app',
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
-# the site admins on every HTTP 500 error.
+# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
+ 'filters': {
+ 'require_debug_false': {
+ '()': 'django.utils.log.RequireDebugFalse'
+ }
+ },
'handlers': {
'mail_admins': {
'level': 'ERROR',
+ 'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
@@ -166,4 +175,13 @@
'compressor.finders.CompressorFinder',
)
-from .misc import *
+
+# Third-party app settings
+
+# django-compressor
+COMPRESS_ROOT = STATIC_ROOT
+COMPRESS_CSS_FILTERS = ['compressor.filters.cssmin.CSSMinFilter']
+COMPRESS_JS_FILTERS = ['compressor.filters.jsmin.JSMinFilter']
+
+# django-grappelli
+GRAPPELLI_ADMIN_TITLE = "{{ project_name|title }} Admin"
View
0 urls.py → config/urls.py
File renamed without changes.
View
28 config/wsgi.py
@@ -0,0 +1,28 @@
+"""
+WSGI config for {{ project_name }} project.
+
+This module contains the WSGI application used by Django's development server
+and any production WSGI deployments. It should expose a module-level variable
+named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
+this application via the ``WSGI_APPLICATION`` setting.
+
+Usually you will have the standard Django WSGI application here, but it also
+might make sense to replace the whole Django WSGI application with a custom one
+that later delegates to the Django one. For example, you could introduce WSGI
+middleware here, or combine a Django application with an application of another
+framework.
+
+"""
+import os
+
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.environments.development")
+
+# This application object is used by any WSGI server configured to use this
+# file. This includes Django's development server, if the WSGI_APPLICATION
+# setting points here.
+from django.core.wsgi import get_wsgi_application
+application = get_wsgi_application()
+
+# Apply WSGI middleware here.
+# from helloworld.wsgi import HelloWorldApplication
+# application = HelloWorldApplication(application)
View
1 db/.gitignore
@@ -0,0 +1 @@
+*.sqlite3
View
16 manage.py
@@ -1,14 +1,8 @@
#!/usr/bin/env python
-from django.core.management import execute_manager
-import imp
-try:
- imp.find_module('settings') # Assumed to be in the same directory.
-except ImportError:
- import sys
- sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
- sys.exit(1)
+import os, sys
-import settings
+if __name__ == '__main__':
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.environments.development')
-if __name__ == "__main__":
- execute_manager(settings)
+ from django.core.management import execute_from_command_line
+ execute_from_command_line(sys.argv)
View
3 public/.gitignore
@@ -0,0 +1,3 @@
+javascripts
+stylesheet
+media
View
21 settings/development.py
@@ -1,21 +0,0 @@
-from path import path
-from .common import *
-
-
-DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.sqlite3',
- 'NAME': PROJECT_ROOT / 'development.sqlite3',
- }
-}
-
-DEBUG = True
-THUMBNAIL_DEBUG = True
-
-
-# settings/local.py is ignored to allow for easy settings
-# overrides without affecting others
-try:
- from local import *
-except ImportError:
- pass
View
8 settings/misc.py
@@ -1,8 +0,0 @@
-from path import path
-
-from .common import STATIC_ROOT
-
-# django-compressor
-COMPRESS_ROOT = STATIC_ROOT
-COMPRESS_CSS_FILTERS = ['compressor.filters.cssmin.CSSMinFilter']
-COMPRESS_JS_FILTERS = ['compressor.filters.jsmin.JSMinFilter']
View
0 ...files/javascripts/libs/modernizr-2.0.6.js → static/javascripts/libs/modernizr-2.0.6.js
File renamed without changes.
View
0 staticfiles/javascripts/main.js → static/javascripts/main.js
File renamed without changes.
View
0 staticfiles/stylesheets/main.css → static/stylesheets/main.css
File renamed without changes.
View
0 staticfiles/stylesheets/reset.css → static/stylesheets/reset.css
File renamed without changes.

1 comment on commit dcbc6b3

@KingScooty

Such a ledge, Martino!

Please sign in to comment.
Something went wrong with that request. Please try again.