What is Django?
Django is a free toolkit for building websites with Python. Python is a popular programming language. A framework is like a box of ready-made parts. You build your site faster because you do not start from zero.
Before you start
- You need SSH access to your server. SSH lets you type commands on a remote computer.
- You need Python 3 installed. Check with
python3 --version.
Steps
- Log in to your server over SSH.
- Install pip and the virtual environment tool. On Ubuntu or Debian use this command.
sudo apt update
sudo apt install -y python3-pip python3-venv
On CentOS or RHEL use sudo yum install -y python3-pip instead. Pip is the tool that downloads Python add-ons.
- Make a folder for your project and go into it.
mkdir mysite
cd mysite
- Create a virtual environment. This is a private box for your project's add-ons. It keeps them apart from the rest of the server.
python3 -m venv venv
- Switch it on.
source venv/bin/activate
Your prompt now starts with (venv).
- Install Django.
pip install django
- Check the version.
python -m django --version
- Start a new project. The dot at the end puts the files in the current folder.
django-admin startproject config .
- Create the starting database tables.
python manage.py migrate
- Start the test server.
python manage.py runserver 0.0.0.0:8000
Open http://YOUR-SERVER-IP:8000 in your browser. You should see the Django welcome page. If the page does not load, your firewall may block port 8000.
If the browser says "DisallowedHost", open config/settings.py. Add your server address to the ALLOWED_HOSTS list.
runserver command is only for testing. For a live site, use a proper setup such as Gunicorn behind a web server. Ask Hostvento support if you are not sure how your plan handles Python apps.Quick recap
- Install Python 3, pip and venv.
- Create and activate a virtual environment.
- Install Django with
pip install django. - Start a project and run
migrate. - Use
runserverfor testing only.