Installing and configuring Django on unmanaged servers

This guide explains how to install and configure Django on an unmanaged server.


Installing Django

  1. Create a virtual environment for Python using virtualenv and install Django.

  2. Log in to your server using SSH.

  3. Install Python, pip, and virtualenv (as root):

Debian / Ubuntu:

apt-get install python3
apt-get install python3-pip
pip3 install virtualenv

AlmaLinux / Fedora:

yum install python34
yum install python34-pip
pip3 install virtualenv
  1. Create and activate a virtual environment as a regular user:

cd ~
mkdir django-apps
cd django-apps
virtualenv env
source env/bin/activate
pip install django
  1. Check the installed Django version:

django-admin --version

Configuring Django

  1. Create a new Django project:

cd ~/django-apps
django-admin startproject mysite
  1. Edit the settings file /home/username/django-apps/mysite/mysite/settings.py:

  • Ensure debug mode is enabled:

DEBUG = True
  • Set allowed hosts (replace with your server’s IP address):

ALLOWED_HOSTS = ['xxx.xxx.xxx.xxx']
  1. Start the development web server (replace with your server IP):

python ~/django-apps/mysite/manage.py runserver xxx.xxx.xxx.xxx:8000
  1. Visit the site in your browser: http://xxx.xxx.xxx.xxx:8000
    You should see: "The install worked successfully! Congratulations!"


Configuring the administration interface

  1. Run migrations and create a superuser:

cd ~
python ~/django-apps/mysite/manage.py migrate
python ~/django-apps/mysite/manage.py createsuperuser
  1. Provide the admin username, e-mail, and password when prompted.

  2. If the development server is not running, start it:

python ~/django-apps/mysite/manage.py runserver xxx.xxx.xxx.xxx:8000
  1. Access the admin interface at http://xxx.xxx.xxx.xxx:8000/admin
    Log in with the username and password you created.


More information

هل كانت المقالة مفيدة ؟ 0 أعضاء وجدوا هذه المقالة مفيدة (0 التصويتات)

Powered by WHMCompleteSolution