Build a small Django site on your computer, then deploy it to a real domain. The example starts with a single page and Django’s built-in admin. Use a supported release such as Django 5.2 LTS, and check that your host offers a compatible Python version before choosing a plan. Django release and support table
1. Create and run a Django project locally
Open a terminal in a new project folder. Create a virtual environment so the project has its own Python dependencies.
python -m venv .venv
Activate it with source .venv/bin/activate on macOS or Linux, or .\.venv\Scripts\Activate.ps1 in Windows PowerShell. If your system uses python3 or py, use that command to create the environment. With it active, run:
python -m pip install "Django>=5.2,<5.3"
python -m django startproject mysite .
python manage.py migrate
python -m pip freeze > requirements.txt
python manage.py runserver
Open http://127.0.0.1:8000/. To replace the starter screen with your own homepage, put this in mysite/urls.py:
from django.contrib import admin
from django.http import HttpResponse
from django.urls import path
def home(request):
return HttpResponse("Hello from Django!")
urlpatterns = [
path("", home),
path("admin/", admin.site.urls),
]
Refresh the page. The empty URL pattern sends the homepage request to home(). Run python manage.py createsuperuser and open /admin/ to try the admin. When you add your own models, run makemigrations to create migration files and migrate to apply them. Django’s first-app tutorial
2. Deploy Django on cPanel
- On a plan with Setup Python App, create an application with a compatible Python version. Choose the domain or subdomain and an application directory outside the public document root.
- Upload the project files, including
manage.py,requirements.txtandmysite/. Use the activation command shown in cPanel to enter the server’s virtual environment, then runpython -m pip install -r requirements.txtfrom the project directory. - For a Passenger setup, point the startup file
passenger_wsgi.pyto Django’s WSGI application. Replacemysiteif you named the project differently.from mysite.wsgi import application - If you are using the host’s database service, create the database and its user, grant that user access to the database, and configure Django with the matching database backend and credentials. Keep the password and
SECRET_KEYin environment variables. In your production settings, use the real domain and define where Django will collect static files. Set the environment variable before loading these settings.import os SECRET_KEY = os.environ["SECRET_KEY"] DEBUG = False ALLOWED_HOSTS = ["example.com"] STATIC_ROOT = BASE_DIR / "staticfiles" - Run the commands below using the production settings, then restart the Python app. Run
createsuperuseron the server if you need a production admin account.
python manage.py migrate
python manage.py collectstatic --noinput
python manage.py check --deploy
Configure the host to serve STATIC_URL from the directory set as STATIC_ROOT. Keep uploaded media, such as article covers, in a separate backed-up location. Open the site and its admin over HTTPS and check that the CSS and images load. If the site returns a 500 error, start with the application error log. If the page opens without styling, check the static URL mapping. Namecheap’s cPanel walkthrough · Django’s deployment checklist
3. Choose a Django hosting provider
- Namecheap shared hosting fits a small site if you already use cPanel. Before buying, confirm that the exact plan offers Setup Python App, the Python version you need, terminal or SSH access, and a suitable database. Shared hosting setup
- PythonAnywhere is a good starting point for a first Django deployment. Its dashboard lets you configure a WSGI app, virtual environment and static file mappings. Check the plan’s domain and resource limits if you want to use it for a public site. PythonAnywhere deployment guide
- Render fits a project you deploy from Git and want to pair with managed PostgreSQL. Set your secrets in the dashboard and plan where uploads will live. Render’s default filesystem is temporary, so use object storage or a supported persistent disk for uploaded files. Render’s Django guide · Persistent storage options
Comments 0
Be the first to comment!