The Perfect Django Settings File


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. """
  2. Here's my sample Django settings for a project I recently did. Visit http://damonjablons.wordpress.com to see the explanation.
  3. """
  4.  
  5. import os
  6. import socket
  7.  
  8. # Set DEBUG = True if on the production server
  9. if socket.gethostname() == 'your.domain.com':
  10. DEBUG = False
  11. else:
  12. DEBUG = True
  13.  
  14. TEMPLATE_DEBUG = DEBUG
  15.  
  16. ADMINS = (
  17. ('Damon Jablons', '[email protected]'),
  18. )
  19.  
  20. MANAGERS = ADMINS
  21.  
  22. # The database settings are left blank so to force the use of local_settings.py below
  23. DATABASE_ENGINE = '' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
  24. DATABASE_NAME = '' # Or path to database file if using sqlite3.
  25. DATABASE_USER = '' # Not used with sqlite3.
  26. DATABASE_PASSWORD = '' # Not used with sqlite3.
  27. DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
  28. DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
  29.  
  30. # Local time zone for this installation. Choices can be found here:
  31. # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
  32. # although not all choices may be available on all operating systems.
  33. # If running in a Windows environment this must be set to the same as your
  34. # system time zone.
  35. TIME_ZONE = 'America/New_York'
  36.  
  37. # Language code for this installation. All choices can be found here:
  38. # http://www.i18nguy.com/unicode/language-identifiers.html
  39. LANGUAGE_CODE = 'en-us'
  40.  
  41. SITE_ID = 1
  42.  
  43. # If you set this to False, Django will make some optimizations so as not
  44. # to load the internationalization machinery.
  45. USE_I18N = False
  46.  
  47. # This dynamically discovers the path to the project
  48. PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
  49.  
  50. # Absolute path to the directory that holds media.
  51. # Example: "/home/media/media.lawrence.com/"
  52. MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media')
  53.  
  54. # URL that handles the media served from MEDIA_ROOT. Make sure to use a
  55. # trailing slash if there is a path component (optional in other cases).
  56. # Examples: "http://media.lawrence.com", "http://example.com/media/"
  57. MEDIA_URL = '/media/'
  58.  
  59. # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
  60. # trailing slash.
  61. # Examples: "http://foo.com/media/", "/media/".
  62. ADMIN_MEDIA_PREFIX = '%sadmin-media/' % MEDIA_URL
  63.  
  64. # Make this unique, and don't share it with anybody.
  65. SECRET_KEY = 'OH_NOES!'
  66.  
  67. # List of callables that know how to import templates from various sources.
  68. TEMPLATE_LOADERS = (
  69. 'django.template.loaders.filesystem.load_template_source',
  70. 'django.template.loaders.app_directories.load_template_source',
  71. # 'django.template.loaders.eggs.load_template_source',
  72. )
  73.  
  74. # Context Processors
  75. TEMPLATE_CONTEXT_PROCESSORS = (
  76. 'django.core.context_processors.auth',
  77. 'django.core.context_processors.media',
  78. 'django.core.context_processors.request',
  79. )
  80.  
  81. if DEBUG:
  82. TEMPLATE_CONTEXT_PROCESSORS += ('django.core.context_processors.debug',)
  83. if USE_I18N:
  84. TEMPLATE_CONTEXT_PROCESSORS += ('django.core.context_processors.i18n',)
  85.  
  86. MIDDLEWARE_CLASSES = (
  87. 'django.middleware.common.CommonMiddleware',
  88. 'django.contrib.sessions.middleware.SessionMiddleware',
  89. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  90. )
  91.  
  92. if DEBUG:
  93. MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
  94.  
  95. ROOT_URLCONF = 'urls'
  96.  
  97. TEMPLATE_DIRS = ()
  98. for root, dirs, files in os.walk(PROJECT_PATH):
  99. if 'templates' in dirs: TEMPLATE_DIRS += (os.path.join(root, 'templates'),)
  100.  
  101. INSTALLED_APPS = (
  102.  
  103. # Django Applications
  104. 'django.contrib.auth',
  105. 'django.contrib.contenttypes',
  106. 'django.contrib.sessions',
  107. 'django.contrib.sites',
  108. 'django.contrib.admin',
  109. 'django.contrib.admindocs',
  110.  
  111. # Third Party Django Applications
  112. 'django_extensions',
  113. 'sorl.thumbnail',
  114. 'filebrowser',
  115. 'chunks',
  116. 'registration',
  117.  
  118. # Project Applications
  119. 'use',
  120. 'wsgi',
  121. 'and',
  122. 'dont',
  123. 'include',
  124. 'the',
  125. 'project',
  126. 'name',
  127. )
  128.  
  129. if DEBUG:
  130. INSTALLED_APPS += ('debug_toolbar',)
  131.  
  132. TEMPLATE_TAGS = (
  133. 'sorl.thumbnail.templatetags.thumbnail',
  134. 'scribblitt.general.templatetags.rotator_includes',
  135. 'chunks.templatetags.chunks',
  136. )
  137.  
  138. # SORL Settings
  139. THUMBNAIL_EXTENSION = 'png'
  140.  
  141. # Filebrowser Settings
  142. FILEBROWSER_URL_WWW = os.path.join(MEDIA_URL, 'uploads%s' % os.sep)
  143. FILEBROWSER_PATH_SERVE = os.path.join(MEDIA_ROOT, 'uploads')
  144. FILEBROWSER_URL_FILEBROWSER_MEDIA = os.path.join(MEDIA_URL, 'filebrowser%s' % os.sep)
  145. FILEBROWSER_PATH_FILEBROWSER_MEDIA = os.path.join(MEDIA_ROOT, 'filebrowser')
  146.  
  147. # Registration App Settings
  148. ACCOUNT_ACTIVATION_DAYS = 3
  149. LOGIN_REDIRECT_URL = '/'
  150.  
  151. INTERNAL_IPS = (
  152. '127.0.0.1',
  153. )
  154.  
  155. DEBUG_TOOLBAR_CONFIG = {
  156. 'INTERCEPT_REDIRECTS': False,
  157. }
  158.  
  159. try:
  160. from local_settings import *
  161. except ImportError:
  162. pass

URL: http://blog.damonjablons.com/2009/10/15/the-perfect-django-settings-file/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.