First, enter domain folder (eg. example.com)
cd example.com
Create a virtualenv and install Django (eg. using python 3.5).
pyvenv-3.5 venv source venv/bin/activate pip install django
Create (or install from a repo) your django project (eg. my_project).
Create a file passenger_wsgi.py in the root of your website directory (eg. example.com). Replace ‘my_project’ with your project name.
import sys, os cwd = os.getcwd() sys.path.append(cwd) sys.path.append(cwd + '/my_project') INTERP = os.path.abspath(cwd + '/venv/bin/python') if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv) sys.path.insert(0,cwd+'/venv/bin') #sys.path.insert(0,cwd+'/venv/lib/python3.5/site-packages/django') sys.path.insert(0,cwd+'/venv/lib/python3.5/site-packages') os.environ['DJANGO_SETTINGS_MODULE'] = "my_project.settings" from django.core.wsgi import get_wsgi_application application = get_wsgi_application()
Create the restart file to start your passenger site
mkdir tmp touch tmp/restart.txt
Create folder for static files
mkdir public/static
Set up Django’s static file settings in order to correctly serve images, CSS, and JavaScript as you will need this for the admin interface to work. Edit my_project/settings.py to configure STATIC_ROOT
STATIC_ROOT = os.path.dirname(BASE_DIR) + '/public/static/'
Run the collectstatic command to set up the static items for the admin interface
cd $HOME/example.com/my_project python manage.py collectstatic
Start django project via
python passenger_wsgi.py
To restart django project, for example after some modifications
touch $HOME/example.com/tmp/restart
MySQL backend
Activate virtualenv and install mysqlclient driver
pip install mysqlclient
Create a MysQL database in DreamHost panel.
Edit my_project/settings.py to configure database
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': '<db_name>', 'USER': '<user>', 'PASSWORD': '<password>', 'HOST': '<mysql.example.com>', 'PORT': '', } }