Django app not visible
I am trying to deploy a Django app for the first time using
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
according to the answers.
I'm not sure at what stage I miss. The project can run on the server through
python manage.py runserver
without errors. I also ran
python manage.py collectstatic
Then I restart Apache with
sudo service apache2 restart
However, when I go to the URL http://phaedrus.scss.tcd.ie/bias_experiment/surveythree/ 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
- overview (my working draft)
- polls (tutorial I followed)
- bias_experiment (root application with my settings file, etc.)
My project structure
My virtual host located at
<VirtualHost *:80> ServerAdmin firstname.lastname@example.org 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
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 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
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])), )
source to share
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:
ServerAlias phaedrus.scss.tcd.ie 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
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
is in the Python path, you can simply set it to 'bias_experiment.settings'.
source to share