Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Python :: vim run python current file 
Python :: django environment variables 
Python :: numpy rolling average 
Python :: how to count things in a list python 
Python :: write lines python with line breaks 
Python :: python dictionary delete by value 
Python :: primary key auto increment python django 
Python :: how to create python file in powershell 
Python :: timer 1hr 
Python :: print in python 
Python :: np array to list 
Python :: joins in pandas 
Python :: Sending POST request in Django 
Python :: print in python without using print 
Python :: django get_user_model() function 
Python :: open tar file pandas 
Python :: how to delete an item from a list python 
Python :: python strip 
Python :: how to print keys and values of dictionary together in python? 
Python :: list square python 
Python :: uploading folder in google colab 
Python :: discord.py embed 
Python :: python get substring between strings 
Python :: socketserver python 
Python :: replace list python 
Python :: python user input to tuple 
Python :: DLL Injection in python 
Python :: python copy a dictionary to a new variable 
Python :: import all csv as append dataframes python 
Python :: how to merge rows in pandas dataframe 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =