Django configuration

Body

Django

To run Django on the Engineering web server, use the following instructions. Replace the name samplewebsite with the name of your website.

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 website:

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 website'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!"

Details

Details

Article ID: 2030
Created
Tue 12/16/25 10:37 AM
Modified
Tue 12/16/25 10:38 AM

Related Services / Offerings

Related Services / Offerings (1)

Submit a General Support request using the "Purdue IT Request" button to the right. The Purdue IT Service Desk will examine, follow-up and route as needed.