Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Deploy a Django App on Your Server

This guide shows you the main steps to put a Python Django site on a Linux server. It fits a VPS or dedicated server where you have root access.

How-To Guides2 min read12 steps

What is Django?

Python is a popular programming language. Django is a framework for it. A framework is a ready-made base for building websites. To deploy means to move your app to a server and start it for the public. Django's built-in test server is only for practice. For a real site you need a proper setup: Gunicorn and Nginx. Gunicorn runs your Python code. Nginx faces the visitors and passes requests to Gunicorn.

Some shared plans offer a Python app tool in the control panel. Ask Hostvento support what your plan has.

Warning: Back up your project and database before you deploy.

Steps

  1. Log in to your server with SSH.
  2. Install Python tools. On Ubuntu:
    sudo apt update
    sudo apt install python3-venv python3-pip nginx
  3. Copy your project to the server, for example into /var/www/myproject. Use Git or SFTP.
  4. Create a virtual environment. This is a private box for your project's packages.
    cd /var/www/myproject
    python3 -m venv venv
    source venv/bin/activate
  5. Install the packages.
    pip install -r requirements.txt
    pip install gunicorn
  6. Edit settings.py for production.
    • Set DEBUG = False.
    • Set ALLOWED_HOSTS = ['yourdomain.com'].
    • Set STATIC_ROOT to a folder for static files.
    • Keep SECRET_KEY out of public code.
  7. Prepare the database and static files.
    python manage.py migrate
    python manage.py collectstatic
  8. Test Gunicorn.
    gunicorn --bind 127.0.0.1:8000 myproject.wsgi
    Replace myproject with the folder that holds wsgi.py. Stop it with Ctrl+C.
  9. Run Gunicorn as a service, so it starts by itself. Create /etc/systemd/system/gunicorn.service with a ExecStart line that runs the command above, then run sudo systemctl enable --now gunicorn.
  10. Add an Nginx site that passes requests to 127.0.0.1:8000 with proxy_pass, and serves your static folder directly.
  11. Test and reload Nginx.
    sudo nginx -t
    sudo systemctl reload nginx
  12. Open your domain in a browser.

Final checks

  • Add HTTPS with a free certificate, such as Let's Encrypt.
  • Check logs with journalctl -u gunicorn if the site fails.

Quick recap

  • Use a virtual environment, Gunicorn and Nginx.
  • Set DEBUG = False and ALLOWED_HOSTS.
  • Run migrate and collectstatic.
  • Run Gunicorn as a service and test Nginx before reloading.