How to Deploy and Host Python Flask or Django Applications
Python web frameworks like Flask and Django are among the most popular choices for building modern web applications. Once your application is ready, the next step is deploying it to a live server so users can access it online.
In this guide, you’ll learn how to deploy and host Flask and Django applications, including deployment using Webuzo Application Manager and other popular hosting platforms.
What is Flask?
Flask is a lightweight Python web framework that provides flexibility and simplicity for building web applications and APIs.
Key Features
- Lightweight and easy to learn
- Minimal setup requirements
- Great for APIs and small-to-medium projects
- Highly customizable
What is Django?
Django is a high-level Python framework designed for rapid development and clean architecture.
Key Features
- Built-in admin panel
- Authentication system
- ORM (Object Relational Mapper)
- Security features
- Scalable architecture
Requirements Before Deployment
Before hosting your application, ensure you have:
- Python installed
- Virtual environment configured
- Application tested locally
- Domain name (optional)
- VPS, Cloud Server, or hosting account
- Git installed (recommended)
Deploying a Flask Application
We provides an Application Manager that allows users to host Python applications using Passenger.
Step 1: Prepare Your Flask Project
Example structure:
myflaskapp/
│
├── app.py
├── requirements.txt
└── passenger_wsgi.py
Install dependencies:
pip install flask
pip freeze > requirements.txt
Step 2: Create passenger_wsgi.py
Passenger requires a WSGI entry file.
Example:
from app import app as application
Webuzo documentation also demonstrates creating a passenger_wsgi.py file for Flask applications.
Step 3: Upload Application Files
Upload your Flask project to your hosting account using:
- File Manager
- Git Clone
- FTP/SFTP
Step 4: Add Application
- Login to Webuzo Enduser Panel
- Open Applications
- Click Add Application
- Select Passenger
- Choose Python
- Enter:
- Application Path
- Startup File
- Port Number
Step 5: Install Dependencies
Open terminal:
pip install -r requirements.txt
Step 6: Start Application
Restart the application from Webuzo Application Manager.
Official Flask Guide:
Deploying a Django Application
Step 1: Create Django Project
pip install django
django-admin startproject myproject
Run locally:
python manage.py runserver
Step 2: Configure Port
According to documentation, you should modify the default Django development port.
Example:
from django.core.management.commands.runserver import Command as runserver
runserver.default_port = "30001"
Replace the port with the one provided.
Step 3: Upload Project
Upload all project files to your hosting account.
Step 4: Add Django Application
In :
- Open Applications
- Click Add Application
- Select Python/Django
- Configure:
- Application Path
- Startup Command
- Port
Step 5: Install Dependencies
pip install -r requirements.txt
Step 6: Configure Production Settings
Edit:
ALLOWED_HOSTS = ['yourdomain.com']
DEBUG = False
Collect static files:
python manage.py collectstatic
Step 7: Restart Application
Restart the application using Application Manager.
Official Django Guide:
Host on Nivohost
Features:
- Full server control
- High scalability
- Enterprise-level hosting
Website:
Best Practices for Production Deployment
Use Virtual Environments
python -m venv venv
source venv/bin/activate
Store Secrets in Environment Variables
Avoid:
SECRET_KEY = "mypassword"
Use:
import os
SECRET_KEY = os.getenv("SECRET_KEY")
Enable HTTPS
Use:
- Let’s Encrypt
- Cloudflare SSL
- Hosting provider SSL
Use Gunicorn
For Flask:
gunicorn app:app
For Django:
gunicorn myproject.wsgi
Configure Reverse Proxy
Use:
- Nginx
- Apache
- Passenger
Useful Video Tutorials
Flask Deployment Tutorials
- Flask Deployment on Nivohost
https://www.youtube.com/nivohost1
Django Deployment Tutorials
- Django Deployment for Beginners
https://www.youtube.com/nivohost1
Conclusion
Deploying Flask and Django applications has become easier thanks to platforms like Nivohost, shared hosting ( that supports python) and cloud VPS providers. If you’re already using Nivohost hosting, its Application Manager offers a convenient way to deploy Python applications without manually configuring complex server settings.