Migrating production infrastructure? Get up to ₹10,000 in migration credits. Apply now
voroaBlog
Web Services

Django Hosting in India Without Managing a Server

· · 3 min read

Django Hosting in India Without Managing a Server

Django hosting in India usually means one of two things: a shared plan with a control panel, or a VPS where you set up Gunicorn, Nginx and systemd yourself. There is a third way. You push your code to GitHub and a platform builds and runs it for you. This post explains what that third way needs from your Django project, step by step.

A Django project on GitHub built and started as a web service in India

Advertisement

What your Django project needs

A requirements file

Keep requirements.txt at the root of the repository, with versions pinned. The build installs from it, so an unpinned package cannot change between two builds.

A production server

Django’s own runserver is for development only - the Django deployment checklist says so plainly. Use Gunicorn:

bash
gunicorn myproject.wsgi --bind 0.0.0.0:$PORT

On Voroa you set this as the start command, and you can change it later without recreating the service. Voroa sets PORT for you. The build and start commands guide explains both fields.

Settings from the environment

Read SECRET_KEY, DEBUG, ALLOWED_HOSTS and DATABASE_URL from environment variables, not from settings.py. Then the same code runs on your laptop and in production, and no secret sits in Git.

The database

Django needs a database. Create a managed PostgreSQL database on the same account, add its connection URL as DATABASE_URL, and redeploy.

Run migrations on every release

Run python manage.py migrate as part of the release, so the schema is ready before the new version takes traffic. Doing it by hand is how a deploy ends up running new code against an old schema.

Moving an existing database

Already have data elsewhere? You can import an existing database and point DATABASE_URL at it.

Static files

Collect static files during the build:

bash
python manage.py collectstatic --noinput

Then serve them with a library such as WhiteNoise. That keeps the whole app to one service, with no separate file server to run.

Deploying on every push

Once the repository is connected, every push to your branch builds a new release. The old release keeps serving until the new one is ready, so users do not see an error page during a deploy. If a release is wrong, roll back to the previous version from the deploy history. The full steps are in our Python and Django guide.

Background work in Django

Sending email or generating reports inside a request makes pages slow. Put that work on a queue (Celery or RQ) and run the consumer as a background worker, with the same code and environment as the web service.

Is it cheaper than a VPS?

A small VPS can cost less on paper. The difference is your time: patches, restarts, certificates and log rotation are yours to handle on a VPS. On Voroa you can start on the free size (Rs 0, subject to free capacity), and paid sizes start at Rs 298 a month plus GST, billed in rupees with a GST invoice.

Django errors you will meet on the first deploy

  • DisallowedHost: add your Voroa URL and domain to ALLOWED_HOSTS.
  • Static files return 404: collectstatic did not run in the build, or WhiteNoise is not in MIDDLEWARE.
  • The app starts, then the URL does not answer: Gunicorn is bound to 127.0.0.1 instead of 0.0.0.0:$PORT.

Deploy Django on Voroa

Using Flask or FastAPI instead? Read Python hosting in India. To see everything a Django web service includes, see Django and Python hosting on Voroa.

Advertisement