· 7 years ago · Dec 12, 2018, 08:22 PM
1"""
2Django settings for django_project project.
3
4For more information on this file, see
5https://docs.djangoproject.com/en/1.8/topics/settings/
6
7"""
8
9# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
10import os
11import netifaces
12
13# Find out what the IP addresses are at run time
14# This is necessary because otherwise Gunicorn will reject the connections
15def ip_addresses():
16 ip_list = []
17 for interface in netifaces.interfaces():
18 addrs = netifaces.ifaddresses(interface)
19 for x in (netifaces.AF_INET, netifaces.AF_INET6):
20 if x in addrs:
21 ip_list.append(addrs[x][0]['addr'])
22 return ip_list
23
24BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
25
26
27# Quick-start development settings - unsuitable for production
28# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
29
30# SECURITY WARNING: keep the secret key used in production secret!
31SECRET_KEY = 'helloworld'
32
33# SECURITY WARNING: don't run with debug turned on in production!
34DEBUG = False
35
36# Discover our IP address
37ALLOWED_HOSTS = ['example.com']
38
39# Application definition
40
41INSTALLED_APPS = (
42 'django.contrib.admin',
43 'django.contrib.auth',
44 'django.contrib.contenttypes',
45 'django.contrib.sessions',
46 'django.contrib.messages',
47 'django.contrib.staticfiles',
48 'blog',
49 'personal',
50
51)
52
53MIDDLEWARE_CLASSES = (
54 'django.contrib.sessions.middleware.SessionMiddleware',
55 'django.middleware.common.CommonMiddleware',
56 'django.middleware.csrf.CsrfViewMiddleware',
57 'django.contrib.auth.middleware.AuthenticationMiddleware',
58 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
59 'django.contrib.messages.middleware.MessageMiddleware',
60 'django.middleware.clickjacking.XFrameOptionsMiddleware',
61 'django.middleware.security.SecurityMiddleware',
62)
63
64ROOT_URLCONF = 'django_project.urls'
65
66TEMPLATES = [
67 {
68 'BACKEND': 'django.template.backends.django.DjangoTemplates',
69 'DIRS': [],
70 'APP_DIRS': True,
71 'OPTIONS': {
72 'context_processors': [
73 'django.template.context_processors.debug',
74 'django.template.context_processors.request',
75 'django.contrib.auth.context_processors.auth',
76 'django.contrib.messages.context_processors.messages',
77 ],
78 },
79 },
80]
81
82WSGI_APPLICATION = 'django_project.wsgi.application'
83
84
85# Database
86# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
87
88DATABASES = {
89 'default': {
90 'ENGINE': 'django.db.backends.sqlite3',
91 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
92 }
93}
94
95
96# Internationalization
97# https://docs.djangoproject.com/en/1.8/topics/i18n/
98
99LANGUAGE_CODE = 'en-us'
100
101TIME_ZONE = 'UTC'
102
103USE_I18N = True
104
105USE_L10N = True
106
107USE_TZ = True
108
109
110# Static files (CSS, JavaScript, Images)
111# https://docs.djangoproject.com/en/1.8/howto/static-files/
112
113STATIC_ROOT = '/home/django/django_project/django_project/static'
114STATIC_URL = '/static/'
115# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
116# Allow Django from all hosts. This snippet is installed from
117# /var/lib/digitalocean/allow_hosts.py
118
119import os
120import netifaces
121
122# Find out what the IP addresses are at run time
123# This is necessary because otherwise Gunicorn will reject the connections
124def ip_addresses():
125 ip_list = []
126 for interface in netifaces.interfaces():
127 addrs = netifaces.ifaddresses(interface)
128 for x in (netifaces.AF_INET, netifaces.AF_INET6):
129 if x in addrs:
130 ip_list.append(addrs[x][0]['addr'])
131 return ip_list
132
133# Discover our IP address
134ALLOWED_HOSTS = ip_addresses()