Advertisement
Guest User

Example settings.py

a guest
Feb 17th, 2018
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.80 KB | None | 0 0
  1. import os
  2. from myapp import config
  3. from django.utils.translation import ugettext_lazy as _
  4.  
  5. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  6. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  7.  
  8. # SECURITY WARNING: keep the secret key used in production secret!
  9. SECRET_KEY = config.SECRET_KEY
  10.  
  11. # SECURITY WARNING: don't run with debug turned on in production!
  12. DEBUG = config.DEBUG
  13.  
  14. ALLOWED_HOSTS = config.ALLOWED_HOSTS
  15.  
  16. # Application definition
  17.  
  18. INSTALLED_APPS = (
  19.     'modeltranslation',
  20.     'django.contrib.admin',
  21.     'django.contrib.auth',
  22.     'django.contrib.contenttypes',
  23.     'django.contrib.sessions',
  24.     'django.contrib.messages',
  25.     'whitenoise.runserver_nostatic',
  26.     'django.contrib.staticfiles',
  27.     'myapp',
  28. )
  29.  
  30. MIDDLEWARE = (
  31.     'django.middleware.security.SecurityMiddleware',
  32.     'whitenoise.middleware.WhiteNoiseMiddleware',
  33.     'django.contrib.sessions.middleware.SessionMiddleware',
  34.     'django.middleware.common.CommonMiddleware',
  35.     'django.middleware.csrf.CsrfViewMiddleware',
  36.     'django.contrib.auth.middleware.AuthenticationMiddleware',
  37.     'django.contrib.messages.middleware.MessageMiddleware',
  38.     # 'django_country.middleware.CountryMiddleware',
  39.     'django.middleware.clickjacking.XFrameOptionsMiddleware',
  40. )
  41.  
  42. ROOT_URLCONF = 'project.urls'
  43.  
  44. TEMPLATES = [
  45.     {
  46.         'BACKEND': 'django.template.backends.django.DjangoTemplates',
  47.         'DIRS': [],
  48.         'APP_DIRS': True,
  49.         'OPTIONS': {
  50.             'context_processors': [
  51.                 'django.template.context_processors.debug',
  52.                 'django.template.context_processors.request',
  53.                 'django.contrib.auth.context_processors.auth',
  54.                 'django.contrib.messages.context_processors.messages',
  55.                 'django_settings_export.settings_export',
  56.             ],
  57.         },
  58.     },
  59. ]
  60.  
  61. WSGI_APPLICATION = 'project.wsgi.application'
  62.  
  63. # Settings for email sending
  64. try:
  65.     EMAIL_HOST = os.environ['EMAIL_HOST']
  66. except KeyError:
  67.     EMAIL_HOST = config.EMAIL_HOST
  68. try:
  69.     EMAIL_HOST_PASSWORD = os.environ['EMAIL_HOST_PASSWORD']
  70. except KeyError:
  71.     EMAIL_HOST_PASSWORD = config.EMAIL_HOST_PASSWORD
  72. try:
  73.     EMAIL_HOST_USER = os.environ['EMAIL_HOST_USER']
  74. except KeyError:
  75.     EMAIL_HOST_USER = config.EMAIL_HOST_USER
  76. try:
  77.     EMAIL_USE_TLS = os.environ['EMAIL_USE_TLS'] or False
  78. except KeyError:
  79.     EMAIL_USE_TLS = config.EMAIL_USE_TLS
  80. try:
  81.     EMAIL_PORT = os.environ['EMAIL_PORT']
  82. except KeyError:
  83.     EMAIL_PORT = config.EMAIL_PORT
  84.  
  85. try:
  86.     DKIM_SELECTOR = os.environ['DKIM_SELECTOR']
  87. except KeyError:
  88.     DKIM_SELECTOR = config.DKIM_SELECTOR
  89. try:
  90.     DKIM_DOMAIN = os.environ['DKIM_DOMAIN']
  91. except KeyError:
  92.     DKIM_DOMAIN = config.DKIM_DOMAIN
  93. try:
  94.     DKIM_PRIVATE_KEY = os.environ['DKIM_PRIVATE_KEY']
  95. except KeyError:
  96.     DKIM_PRIVATE_KEY = config.DKIM_PRIVATE_KEY
  97. if DKIM_PRIVATE_KEY:
  98.     EMAIL_BACKEND = 'email_backend.DKIMBackend'
  99.  
  100. try:
  101.     SITE_HOST = os.environ['SITE_HOST']
  102. except KeyError:
  103.     SITE_HOST = config.SITE_HOST
  104.  
  105. DEFAULT_FROM_EMAIL = 'info@project.net'
  106. DEFAULT_ACCOUNT_EMAIL = 'accounts@project.net'
  107.  
  108. # Database
  109.  
  110. DATABASES = {
  111.     'default': {
  112.         'ENGINE': 'django.db.backends.sqlite3',
  113.         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  114.     }
  115. }
  116.  
  117. # Bring database configuration from database url if dj_database_url is installed
  118. try:
  119.     import dj_database_url
  120.     db_url = config.DATABASE_URL
  121.     DATABASES['default'] = dj_database_url.config(default=db_url)
  122. except:
  123.     pass
  124.  
  125.  
  126. # Internationalization
  127.  
  128. LANGUAGE_CODE = 'en'
  129.  
  130. LANGUAGES = (
  131.     ('en', _('English')),
  132. )
  133.  
  134. LOCALE_PATHS = (
  135.     os.path.join(BASE_DIR, 'locale/'),
  136. )
  137.  
  138. TIME_ZONE = 'UTC'
  139.  
  140. USE_I18N = True
  141.  
  142. USE_L10N = True
  143.  
  144. USE_TZ = True
  145.  
  146. USE_S3 = config.USE_S3
  147.  
  148. if USE_S3:  # Only use Amazon S3 in production
  149.  
  150.     # Amazon AWS Specific settings:
  151.  
  152.     AWS_HEADERS = {  # see http://developer.yahoo.com/performance/rules.html#expires
  153.             'Expires': 'Thu, 31 Dec 2099 20:00:00 GMT',
  154.             'Cache-Control': 'max-age=94608000',
  155.         }
  156.  
  157.     AWS_STORAGE_BUCKET_NAME = config.AWS_STORAGE_BUCKET_NAME
  158.     AWS_ACCESS_KEY_ID = config.AWS_ACCESS_KEY_ID
  159.     AWS_SECRET_ACCESS_KEY = config.AWS_SECRET_ACCESS_KEY
  160.  
  161.     # Tell django-storages that when coming up with the URL for an item in S3 storage, keep
  162.     # it simple - just use this domain plus the path. (If this isn't set, things get complicated).
  163.     # This controls how the `static` template tag from `staticfiles` gets expanded, if you're using it.
  164.     # We also use it in the next setting.
  165.     AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
  166.  
  167.     MEDIAFILES_LOCATION = 'media'
  168.     MEDIA_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, MEDIAFILES_LOCATION)
  169.     DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
  170.  
  171. # Braintree settings
  172. try:
  173.     BRAINTREE_MERCHANT_ID = os.environ['BRAINTREE_MERCHANT_ID']
  174. except KeyError:
  175.     BRAINTREE_MERCHANT_ID = config.BRAINTREE_MERCHANT_ID
  176. try:
  177.     BRAINTREE_PUBLIC_KEY = os.environ['BRAINTREE_PUBLIC_KEY']
  178. except KeyError:
  179.     BRAINTREE_PUBLIC_KEY = config.BRAINTREE_PUBLIC_KEY
  180. try:
  181.     BRAINTREE_PRIVATE_KEY = os.environ['BRAINTREE_PRIVATE_KEY']
  182. except KeyError:
  183.     BRAINTREE_PRIVATE_KEY = config.BRAINTREE_PRIVATE_KEY
  184. try:
  185.     BRAINTREE_SANDBOX_MODE = os.environ['BRAINTREE_SANDBOX_MODE']
  186. except KeyError:
  187.     BRAINTREE_SANDBOX_MODE = config.BRAINTREE_SANDBOX_MODE
  188. try:
  189.     PAYMENT_HOST = os.environ['BRAINTREE_PAYMENT_HOST']
  190. except KeyError:
  191.     PAYMENT_HOST = config.BRAINTREE_PAYMENT_HOST
  192.  
  193. PAYMENT_USES_SSL = False
  194. PAYMENT_MODEL = 'mysite.Payment'
  195. PAYMENT_VARIANTS = {'default': ('payments.dummy.DummyProvider', {})}
  196. PAYMENT_VARIANTS = {'default': ('payments.braintree.BraintreeProvider', {'merchant_id': BRAINTREE_MERCHANT_ID,
  197.                                                                          'public_key': BRAINTREE_PUBLIC_KEY,
  198.                                                                          'private_key': BRAINTREE_PRIVATE_KEY,
  199.                                                                          'sandbox': BRAINTREE_SANDBOX_MODE})}
  200.  
  201.  
  202. # Static files (CSS, JavaScript, Images)
  203.  
  204. try:
  205.     STATIC_ROOT = os.environ['STATIC_ROOT']kijk
  206. except KeyError:
  207.     STATIC_ROOT = config.STATIC_ROOT
  208.  
  209. STATIC_URL = '/static/'
  210.  
  211. MEDIA_DIR_NAME = 'media'
  212.  
  213. MEDIA_ROOT = os.path.join(BASE_DIR, MEDIA_DIR_NAME)
  214. if not USE_S3:  # Use local filesystem in development mode
  215.     MEDIA_URL = '/media/'
  216.  
  217. try:
  218.     GOOGLE_MAPS_V3_APIKEY = config.GOOGLE_MAPS_V3_APIKEY
  219. except:
  220.     GOOGLE_MAPS_V3_APIKEY = ''
  221.  
  222. # For enabling HTTPS in the production server
  223. PRODUCTION_SERVER = False
  224. try:
  225.     if config.PRODUCTION_SERVER == True:
  226.         SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
  227.         PRODUCTION_SERVER = True
  228. except:
  229.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement