Insights from Our Experts

Blog image

How to host your Django project to production server

Author Image

Ranju Rajendran,Web Lead

Django’s practical design and ease of use make it a highly popular choice for web development applications. It wouldn't be wrong to say Django is a better-evolved framework for web development than its counterparts. Django offers many advantages such as better documentation, compatibility with SEO practices, scalability, and security that makes it a top preference among startups for web development. 

Once you have successfully developed and demonstrated your Django project, the very next step is to deploy it to the production server- the final step to take your project live. Django supports numerous ways to deploy the project to production. You can use your preferred web server, database, proxy, and so on.

Read also: When should you choose Django Framework

Read also: What is the Future Scope for Python Django Web Development?

What are the elements of a Django Production Server Architecture?

Below shown is a Django Production Server Architecture. There could be many iterations of the architecture. The below one covers all the entities and requirements of the Production Server setup.

Django-host

Core stack

  1. Apache, nginx, lighttpd, cherokee

  2. mod_python, mode_wsgi, Gunicorn, uwsgi, FastCGI

  3. Supervisor 

  4. MySQL/ Postgres/ Other databases 

  5. Celery, cron

  6. RabbitMQ, Redis

  7. Memcached

Web Server

A Web server uses the client/server model and the World Wide Web's Hypertext Transfer Protocol ( HTTP ) to serve the files from Web pages to Web users. We can use any of Apache, Nginx, or Lighttpd. But when we choose a web server, we need to select an appropriate submodule compatible with it from mod_python, mode_wsgi, Gunicorn, uWSGI, FastCGI. For example, we can use apache with mod_python or mode_wsgi, Nginx with uWSGI, or Gunicorn.

Background Tasks

Some tasks will take a very long time to finish and a user need not to wait for its result. In such cases, we can make the background task to work in a different thread or maybe in a different server altogether. We can make use of celery here. 

  1. Celery - Celery is an asynchronous task/job queue based on distributed message passing. Celery is written in Python, but the protocol can be implemented in any language.

  2. Workers - Used to process the messages sent by Celery. we can set multiple workers.

  3. Supervisor - It is a client/server system that allows its users to monitor and control several processes on UNIX-like operating systems. We can start/ stop Celery using this.

  4. Broker - We have to run some brokers on servers to process our tasks. We can use RabbitMQ or Redis for this

Monitoring

When our project is hosted, we need to monitor it using some tools to check its performance, its error logs, and user interactions. Following are some of the tools that we can utilize:

Graphite - Graphite provides real-time visualization and storage of numeric time-series data on an enterprise level.

Statsd - A network daemon that runs on the Node.js platform and listens for statistics, like counters and timers, sent over UDP or TCP, and sends aggregates to one or more pluggable backend services (e.g., Graphite).

Sentry - logging - Sentry is a modern error logging and aggregation platform.

New Relic - A software analytics tool suite used by developers, ops, and software companies to understand how your applications are performing in development and production. 

Deployment automation

Our live project needs continuous development and deployment. So, we need some deployment automation tool that simplifies our deployment. One of them is Fabric - Fabric is a Python (2.5-2.7) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks. 

Read also: 5 Tips to Ensure Great Performance with Python

There are deployment checklists available that Django mentions, it's a good way to ensure that the deployment is done right.

Get We build software solutions in Django that makes your business more efficient Get in touch for a FREE  consultation.

I Need

Help for