Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Deploy a django app to apache2 server

Deploying a django application to an apache server should be straight forward as there are quite alot of tutorials out there on how to do it, but as i found out it was not as straight forward.

here is a link to get you started. https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04

once you have got your server setup, below is something to watch out for.

1)when you add your site to Apache's sites available make sure that the python version in the virtual environment on your production server matches what you used on your development server. you can check this by navigating to your virtual environment and typing in python to enter the shell where you should see your python version.

2) In your settings.py file make sure allowed_hosts is set as follows.

ALLOWED_HOSTS = [' * ' ]

here is an example of my apache config file setup for a live server

<VirtualHost *:80>
  ServerName  yourapp.com
  ServerAdmin admin@yourapp.com


Alias /static  /var/www/yourapp/static_in_env/static_root
    <Directory /var/www/yourapp/src/static_in_env/static_root>
        Order deny,allow
        Allow from all
    </Directory>


WSGIScriptAlias / /var/www/yourapp/src/yourapp/wsgi.py
WSGIDaemonProcess yourapp python-path= /var/www/yourapp/src:/var/www/yourapp/lib/python2.7/site-packages
WSGIProcessGroup yourapp

<Directory /var/www/yourapp/src/yourapp>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>



</VirtualHost>

hope this helps someone else from not having to pull their hair out with a 500 server error!

2 Answers

thanks Kenneth look forward to the course, also looking forward to the Rest API course coming soon.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Great post!

I'll be doing a course/workshop on deploying Django eventually but this will hopefully tide people over until that time.

Anyone that has the option, it's generally a bit simpler to deploy Django with nginx than with Apache, but not every host provides that.

Do you have any tutorials you'd recommend for deploying a site to a real server?

not sure what you mean by real server, this post shows you how to deploy to a apache server on https://www.digitalocean.com. A droplet on digital ocean is a real server ?