Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Django's built in web server in a production environment

Tags:

django

I'm going to setup a simple Django app running in a production environment on a Linux box. The app will have very little traffic - less that 100 page loads per day. Is it okay to use the builtin Django webserver for this or should I install Apache and mod_wsgi? If so, what are the reasons for this? Security perhaps?

UPDATE

OK it is clear I shouldn't be using the builtin server. Some of the alternatives to Apache look interesting. Is there one that is more popular/more frequently used with Django perhaps?

like image 352
paperplane Avatar asked Feb 01 '11 20:02

paperplane


People also ask

Can you use Django in production?

If you want to run Django in production, be sure to use a production-ready web server like Nginx, and let your app be handled by a WSGI application server like Gunicorn. If you plan on running on Heroku, a web server is provided implicitly. You don't have to take care of it.

Does Django have built in webserver?

Django is an extremely popular and fully featured server-side web framework, written in Python. This module shows you why Django is one of the most popular web server frameworks, how to set up a development environment, and how to start using it to create your own web applications.

What is the command to start Django's built in development server?

python manage.py runserver The runserver command is a built-in subcommand of Django's manage.py file that will start up a development server for this specific Django project.


2 Answers

Is it okay to use the builtin Django webserver for this

No.

Should I install Apache and mod_wsgi?

Yes.

If so, what are the reasons for this? Security perhaps?

Partly.

More importantly, the little toy Django server is single-threaded and any hangup in your code hangs the server. This means that when two users click almost at the same time, user one's query must go all the way through Django before user two's query can even starts.

And this will have to include the insanely slow download speed to the desktop.

Apache (like all the alternatives, lighttpd or nginx) is multi-threaded. The slowest part of the transaction is the download from Apache to the desktop. You don't want Python code (and Django) handling this in a single-threaded manner. Even for just a few users.

Also, you don't what Django serving static media (i.e., CSS and JS library files.)

A single slow spot in your application won't effect the overall system throughput if Apache and mod_wsgi are in place. One request 's output page can be slowly downloading to a PC desktop in parallel with another user's output.

like image 70
S.Lott Avatar answered Oct 12 '22 23:10

S.Lott


DO NOT USE THIS (the builtin Django webserver) SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests.

http://docs.djangoproject.com/en/dev/ref/django-admin/#runserver-port-or-address-port

But you don't have use Apache if you don't want to. You could directly use Spawning, Gunicorn etc.

Cherokee is also easy to setup.

like image 31
Epeli Avatar answered Oct 12 '22 23:10

Epeli