Recently, I wanted to put one of my WSGI applications into a subdirectory, so that the other directories that cointain various scripts would work as before. In order to do that, I added the following directive to my httpd.conf in global namespace (also tried to put it in the VirtualHost, which gave the same effects):

WSGIScriptAlias /hello/ /var/www/hello/hello.wsgi

Then, I ran django-admin startproject hello. After reloading Apache configs, I can confirm that http://localhost/hello/ points to a Django "welcome" screen. Then, I edited hello/urls.py to add the following line in the urlpatterns tuple:

url(r'^hello/', 'hello.views.home'),

Next, I created hello/views.py with the following contents:

from django.http import HttpResponse

def hello(request):
    return HttpResponse("Hello world")

Unfortunately, when I try to visit http://localhost/hello/hello, I get a standard Apache 404 message and the following entry in the error log:

[Mon Dec 23 19:49:44 2013] [error] [client] Target WSGI script not found or unable to stat: /var/www/hello/hello.wsgihello

Note the hello.wsgihello. The second hello is the text that appears after /hello/ in the URL. For http://localhost/hello/unknown, it would be hello.wsgiunknown. Here's my hello.wsgi:

import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'hello.settings'

path = '/var/www/hello'
if path not in sys.path:

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

Did I do something wrong? How do I fix it?


The file syntax in /var/www/hello/hello.wsgi confused me. Apparently, if one points to /var/www/hello/hello.wsgi/ instead, the configuration works fine.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.