The setup of a Django application on Webfaction is really easy using their one-click-installer. But this setup is really static and surely not the best option to use for Django. Luke Plant wrote about setting up Django with gunicorn on Webfaction in his blog, I will write about setting up Django 1.5 with Apache and mod_wsgi without the Django one-click-installer but the mod_wsgi one (mod_wsgi 3.4 / Python 2.7). The setup won't be the fastest Django setup in the world, but it will work.
It's basically an update for my old blog post covering Django 1.3:
Set up a mod_wsgi application and create a website in the Webfaction control panel. Log into shell and goto your newly created app. Create a virtualenv and a folder for your project files (maybe you want to check out from a VCS), activate the virtualenv and install Django an whatever you need. Edit the default wsgi.py create by the django-admin.py startproject command:
""" WSGI config for tools_project project. This module contains the WSGI application used by Django's development server and any production WSGI deployments. It should expose a module-level variable named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover this application via the ``WSGI_APPLICATION`` setting. Usually you will have the standard Django WSGI application here, but it also might make sense to replace the whole Django WSGI application with a custom one that later delegates to the Django one. For example, you could introduce WSGI middleware here, or combine a Django application with an application of another framework. """ import os # set paths correctly on webfaction if os.environ['STAGE'] == 'webfaction': import site import sys site.addsitedir('/home/<username>/webapps/<app>/<virtualenv-folder>/lib/python2.7/site-packages') sys.path.append('/home/<username>/webapps/<app>/project') # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks # if running multiple sites in the same mod_wsgi process. To fix this, use # mod_wsgi daemon mode with each site in its own daemon process, or use # os.environ["DJANGO_SETTINGS_MODULE"] = "tools_project.settings" os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tools_project.settings") # This application object is used by any WSGI server configured to use this # file. This includes Django's development server, if the WSGI_APPLICATION # setting points here. from django.core.wsgi import get_wsgi_application application = get_wsgi_application() # Apply WSGI middleware here. # from helloworld.wsgi import HelloWorldApplication # application = HelloWorldApplication(application)
You can leave out the check of the STAGE environment variable if you haven't set it. I use it to run a project on different hosts and identify each host.
Now adjust the Apache2 config by editing /home/<username>/webapps/<app>/apache2/conf/httpd.conf. Remove the following lines on the bottom:
<Directory /home/<username>/webapps/<app>/htdocs> AddHandler wsgi-script.py </Directory>
Instead, add the following line that tell the WSGI daemon to run the wsgi.py of Django:
WSGIScriptAlias / /home/<username>/webapps/<app>/project/<projectname>/wsgi.py
Then restart the Apache and you're done.