use local_settings, create random secret on first launch
This commit is contained in:
parent
9b75543f86
commit
559fd536e6
2 changed files with 27 additions and 15 deletions
|
@ -2,3 +2,5 @@ host_settings/*
|
|||
media/*
|
||||
dev.sqlite
|
||||
*.pyc
|
||||
local_settings.py
|
||||
secret.txt
|
||||
|
|
40
settings.py
40
settings.py
|
@ -6,7 +6,7 @@ import os
|
|||
from os.path import join
|
||||
from django.conf import global_settings
|
||||
|
||||
PROJECT_PATH = os.path.normpath(os.path.dirname(__file__))
|
||||
PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__))
|
||||
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
@ -43,8 +43,8 @@ USE_I18N = True
|
|||
|
||||
# Absolute path to the directory that holds media.
|
||||
# Example: "/home/media/media.lawrence.com/"
|
||||
MEDIA_ROOT = join(PROJECT_PATH, 'media')
|
||||
STATIC_ROOT = join(PROJECT_PATH, 'static')
|
||||
MEDIA_ROOT = join(PROJECT_ROOT, 'media')
|
||||
STATIC_ROOT = join(PROJECT_ROOT, 'static')
|
||||
|
||||
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
|
||||
# trailing slash if there is a path component (optional in other cases).
|
||||
|
@ -56,9 +56,6 @@ MEDIA_URL = '/texts/'
|
|||
# Examples: "http://foo.com/media/", "/media/".
|
||||
ADMIN_MEDIA_PREFIX = '/admin/media/'
|
||||
|
||||
# Make this unique, and don't share it with anybody.
|
||||
SECRET_KEY = '@8+=n)(@(gv0ogqm6pnvs6ag@&qa3syb^qy8@#x7f68)cyrs(*'
|
||||
|
||||
# List of callables that know how to import templates from various sources.
|
||||
TEMPLATE_LOADERS = (
|
||||
'django.template.loaders.filesystem.load_template_source',
|
||||
|
@ -76,7 +73,7 @@ MIDDLEWARE_CLASSES = (
|
|||
ROOT_URLCONF = 'texts.urls'
|
||||
|
||||
TEMPLATE_DIRS = (
|
||||
join(PROJECT_PATH, 'templates'),
|
||||
join(PROJECT_ROOT, 'templates'),
|
||||
)
|
||||
|
||||
INSTALLED_APPS = (
|
||||
|
@ -88,13 +85,26 @@ INSTALLED_APPS = (
|
|||
'texts.text',
|
||||
)
|
||||
|
||||
#overwrite default settings with local settings
|
||||
try:
|
||||
import socket
|
||||
# hostname = socket.gethostname().replace('.','_')
|
||||
# exec "from host_settings.%s import *" % hostname
|
||||
local_settings_module = socket.gethostname().split(".")[0]
|
||||
if local_settings_module:
|
||||
execfile(os.path.join(PROJECT_PATH, "host_settings", "%s.py" % local_settings_module))
|
||||
except ImportError, e:
|
||||
raise e
|
||||
from local_settings import *
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# Make this unique, creates random key first at first time.
|
||||
try:
|
||||
SECRET_KEY
|
||||
except NameError:
|
||||
SECRET_FILE = os.path.join(PROJECT_ROOT, 'secret.txt')
|
||||
try:
|
||||
SECRET_KEY = open(SECRET_FILE).read().strip()
|
||||
except IOError:
|
||||
try:
|
||||
from random import choice
|
||||
SECRET_KEY = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])
|
||||
secret = file(SECRET_FILE, 'w')
|
||||
secret.write(SECRET_KEY)
|
||||
secret.close()
|
||||
except IOError:
|
||||
Exception('Please create a %s file with random characters to generate your secret key!' % SECRET_FILE)
|
||||
|
||||
|
|
Loading…
Reference in a new issue