Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django deployment

### 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
Comment

PREVIOUS NEXT
Code Example
Python :: How to select parts of a numpy array 
Python :: python json web request 
Python :: numpy moving average 
Python :: python loop back to start 
Python :: map and filter in python 
Python :: python not equal multiple values 
Python :: edit pandas row value 
Python :: How to Merge train and Test dataset in python 
Python :: legend matplotlib 
Python :: numpy calculate standard deviation 
Python :: Custom x, y-ticks using plt 
Python :: python argparse lists flags as optional even with required 
Python :: font in tkinter 
Python :: Write a program that prints #pythoniscool, followed by a new line, in the standard output. Your program should be maximum 2 lines long You are not allowed to use print or eval or open or import sys in your file 
Python :: how to take date as input in python 
Python :: Find Files With a Certain Extension in the Directory and Its Subdirectories in Python 
Python :: dataframe python unique values rows 
Python :: python read values from file 
Python :: how to make gtts text to speech converter 
Python :: append object python 
Python :: python distilled 
Python :: how to concatenate dataframe in python 
Python :: django model form 
Python :: udp server python 
Python :: replace list 
Python :: extract name of file from path python 
Python :: new column with multiple conditions 
Python :: python easygui 
Python :: print with no newline 
Python :: python async function 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =