Django app not visible

I am trying to deploy a Django app for the first time using mod_wsgi

c Apache

to Ubuntu 12.04

VM. I follow several tutorials, especially Ayman Farhat blog , this excellent YouTube video and of course the official Django documentation

This follows a previous question I posted here , wondering why my Django poll didn't just work when I uploaded it to / var / www / (blush!) I have since researched mod_wsgi

according to the answers.

I'm not sure at what stage I miss. The project can run on the server through python runserver

without errors. I also ran python collectstatic

without error.

Then I restart Apache with

sudo service apache2 restart


However, when I go to the URL where I expect to see an overview, there is nothing there. I just see a standard 404 error.

I'm really not sure what I need to do next or why this isn't working.

Below is my setup and what I have tried so far.

NOTE. I have a Django Bias_Experiment project created in Pydev. It contains three applications contained in a folder src


  • overview (my working draft)
  • polls (tutorial I followed)
  • bias_experiment (root application with my settings file, etc.)

My project structure

enter image description here

My virtual host located at/etc/apache2/sites-available/bias_experiment

<VirtualHost *:80>
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

# Add the app directory to the PYTHONPATH

os.environ['DJANGO_SETTINGS_MODULE'] = 'bias_experiment/src/bias_experiment.settings'

# Activate your virtual env
execfile(activate_env, dict(__file__=activate_env))

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()    


My URL patterns frombias_experiment/src/bias_experiment/

urlpatterns = patterns('',
    url(r'^polls/', include('polls.urls', namespace="polls")),
    url(r'^admin/', include(,        
    url(r'^surveythree/$', SurveyWizard.as_view([SurveyForm1, SurveyForm2, SurveyForm3, SurveyForm4, SurveyForm5])),   



source to share

1 answer

The address you intend to use in your browser does not match the ServerName or ServerAlias ​​directives in your Apache configuration, so virtualhost will not know to respond to this request.

Note that ServerAlias ​​should be like ServerName - the hostname, not the URL, without the http prefix or path. Also note that you can have multiple values ​​for ServerAlias ​​if you need this virtual host to answer many hostnames.

If you want your Django app to be served under / bias_experiment, it must be part of WSGIScriptAlias.

So it should be:

WSGIScriptAlias /bias_experiment /var/www/bias_experiment/src/bias_experiment/index.wsgi


Also I am confused about the location of your code. Is it in / var / www / ... or / home / whoever / var / www? Your wsgi file is the latter, but the Apache conf is the same.

Next, virtualenv should take care of setting up all Python paths. Since you are running the activate script, you can remove the lines that modify sys.path and site.addsitedir. Although you may need to keep the one that adds the directory src


Another issue is related to your DJANGO_SETTINGS_MODULE. It should be a Python module, not a file path - in fact, what you have is a cross between the two. Since it src

is in the Python path, you can simply set it to 'bias_experiment.settings'.



All Articles