I am trying to deploy a Django application for the first time using mod_wsgi
with Apache
on a Ubuntu 12.04
VM. I have been following several tutorials, especially Ayman Farhat blog, this excellent YouTube video and of course the official Django Documentation
This follows an earlier question I posted here wondering why my Django survey did not simply work when I uploaded it to the /var/www/ (blush!) I have since been looking into mod_wsgi
as per the answers.
I'm not sure what stage I am missing. The project is able to start on the server via python manage.py runserver
with no errors. I have also ran python manage.py collectstatic
with no errors.
I then restart Apache with
sudo service apache2 restart
However when I go the URL http://phaedrus.scss.tcd.ie/bias_experiment/surveythree/ where I expect to see the survey nothing is there. I just see the standard 404 error.
I am really not sure what I have to do next or why this is not working.
Below is my setup and what I have tried so far.
NOTE: I have a Bias_Experiment Django Project created in Pydev. It has three applications contained within an src
folder.
- survey (my working project)
- polls (a tutorial i was following)
- bias_experiment (the root application with my settings file etc)
My Project Structure
My virtual host located at /etc/apache2/sites-available/bias_experiment
<VirtualHost *:80>
ServerAdmin admin@email.com
ServerName kdeg-vm-18.scss.tcd.ie
ServerAlias http://collegeserver.ie/bias_experiment
WSGIScriptAlias / var/www/bias_experiment/src/bias_experiment/index.wsgi
Alias /static/ /var/www/bias_experiment/src/bias_experiment/static/
<Location "/static/">
Options -Indexes
</Location >
</VirtualHost >
My WSGI file located at /var/www/bias_experiment/src/bias_experiment/index.wsgi
import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('~/var/www/bias_experiment/lib/python2.7/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('/var/www/bias_experiment')
sys.path.append('/var/www/bias_experiment/src/bias_experiment')
os.environ['DJANGO_SETTINGS_MODULE'] = 'bias_experiment/src/bias_experiment.settings'
# Activate your virtual env
activate_env=os.path.expanduser("~/var/www/bias_experiment/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
My URL patterns from bias_experiment/src/bias_experiment/urls.py
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls', namespace="polls")),
url(r'^admin/', include(admin.site.urls)),
url(r'^surveythree/$', SurveyWizard.as_view([SurveyForm1, SurveyForm2, SurveyForm3, SurveyForm4, SurveyForm5])),
)