Print this article Edit this article
Django configuration
Django
To run Django on the Engineering web server, use the following instructions. Replace the name samplewebsite with the name of your web site.
Prerequisites
To prepare your site to run Django, log into charlotte.ecn.purdue.edu via SSH using the account that runs your site. This will usually be a special purpose account separate from your career account. Use the web shell to enable mod_wsgi:
webshell_samplewebsite
add mod_wsgi
restart
exit
Install the latest Django 5.2 release in the web account's home directory:
pip install --user django~=5.2.0
Starting a project
To start a new project, go to the top directory for the web site:
cd /web/groups/samplewebsite/public_html
~/.local/bin/django-admin startproject myproject .
Edit manage.py using your preferred editor, e.g. nano:
nano manage.py
On line 1, change 'python' to 'python3' and save.
Edit the settings:
nano myproject/settings.py
Add this line below the multiline comment at the top of the file:
import os
Change the allowed hosts to any host:
ALLOWED_HOSTS = ['*']
Set the static directory's root directory:
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
Change the static URL to the web site's name:
STATIC_URL = '/samplewebsite/static/'
Initialize the project and create the superuser account and static directory:
./manage.py makemigrations
./manage.py migrate
./manage.py createsuperuser
./manage.py collectstatic
Final touches
Create a file named .htaccess:
nano .htaccess
Add these lines to the file and save:
RewriteEngine On
RewriteRule ^db\.sqlite3 - [F]
RewriteRule ^manage\.py - [F]
Create a symlink to the WSGI script created by Django:
ln -s myproject/wsgi.py index.wsgi
Go to the local Python package directory and create a symlink to your Django project:
cd ~/.local/lib/python3.10/site-packages
ln -s /web/groups/samplewebsite/public_html/myproject
Visit your site and you should now see a page that says "The install worked successfully! Congratulations!"
Last Modified:
Jun 9, 2025 11:47 am GMT-4
Created:
Oct 10, 2018 1:18 pm GMT-4
by
admin
JumpURL:
Categories
- Knowledge Base > Web > Apache