What is Django?
Django is a toolkit for building websites with Python. Python is a popular programming language. A toolkit saves time because it has ready parts for logins, forms and databases.
cPanel has a tool named Setup Python App. It may not be on every plan. Ask Hostvento support if you cannot see it.
Part 1: Create the Python app
- Log in to cPanel.
- In the Software section, click Setup Python App.
- Click Create Application.
- Choose a Python version. Pick one that your Django version supports.
- In Application root, type a folder name, for example
mydjango. - In Application URL, choose your domain.
- Leave the startup file and entry point boxes empty for now.
- Click Create.
cPanel makes a virtual environment for you. This is a private box of Python add-ons for one project. It keeps projects from mixing. The page shows a command to enter it. Copy that command.
Part 2: Install Django
- Open Terminal in cPanel. Or connect by SSH.
- Paste the command you copied. It starts with
source. It enters the virtual environment. - Install Django.
pip is Python's tool for adding packages.pip install django - Start a project in your app folder.
This makes the starter files. The dot at the end puts them right here.cd ~/mydjango django-admin startproject mysite .
Part 3: Connect Django to the web server
- Open the file
passenger_wsgi.pyin your app folder. cPanel made it. If it is missing, create it. - Replace its contents with this.
This tells the server where your Django app starts.from mysite.wsgi import application - Open
mysite/settings.pyin File Manager. - Find
ALLOWED_HOSTSand add your domain.
Django will answer only for these names.ALLOWED_HOSTS = ['yourdomain.com', 'www.yourdomain.com'] - Add a static files folder.
STATIC_ROOT = BASE_DIR / 'static' - Back in the terminal, run these.
The first sets up the database tables. The second gathers your CSS and images.python manage.py migrate python manage.py collectstatic - Back in Setup Python App, click Restart.
- Open your domain. You should see Django's welcome page.
Set DEBUG = False before you go live. Debug mode shows secret details when errors happen.
Tip: Restart the app each time you change code. If you see errors, check the
stderr.log file in the app folder.Quick recap
- Create the app with Setup Python App.
- Install Django with pip inside the virtual environment.
- Link it through
passenger_wsgi.pyand setALLOWED_HOSTS. - Run migrate and collectstatic, then restart.