Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

django production

### 1- hide SECURITY_KEY, DBs info and other important variables ###
### 2- install SSL certificate ###
https://selmi.tech/blog/post/install-lets-encrypt-for-django-with-nginx-automate-renewal-with-cron861366

### 3- set debug to false in settings.py ###
DEBUG = False

### 4- add HTTPs settings in settings.py ###
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
SECURE_SSL_REDIRECT = True

### 5- add HSTS settings in settings.py ###
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_PRELOAD = True
SECURE_HSTS_SECONDS = 3153600 # 1 year

### 6- add allowed hosts in settings.py ###
ALLOWED_HOSTS = ['localhost', '127.0.0.1', www.mysite.com] # where mysite is the url of my hosted django project

### 7- add STATIC_ROOT and MEDIA_ROOT in settings.py and run collectstaic command ###
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') # STATIC_ROOT is the path to your static files
run command >> python manage.py collectstatic

MEDIA_ROOT = os.path.join(BASE_DIR, 'data/') # 'data' is your media folder where user files will uploaded
MEDIA_URL = '/media/'
# check this library for Media
# https://django-storages.readthedocs.io/en/latest/

### 8- run deployment checklist command ###
run command >> python manage.py check --deploy
 
PREVIOUS NEXT
Tagged: #django #production
ADD COMMENT
Topic
Name
4+9 =