500 errors from Django admin url with tutorial app [SOLVED]

software development


I’m hoping someone ran into a similar issue and has a fix/workaround for this:

I’m trying to setup my first Django app on dreamhost, and am running into 500 errors when attempting to load /admin/
the errors seem to be coming from Apache and not Python/Django. the error log contains the following 2 lines for each page load attempt:

[font=Courier][Sun Feb 13 21:25:03 2011] [error] [client ] Premature end of script headers: admin
[Sun Feb 13 21:25:03 2011] [error] [client ] Premature end of script headers: internal_error.html[/font]

and the access log this:
[font=Courier] - - [13/Feb/2011:21:25:03 -0800] “GET /admin/ HTTP/1.1” 500 691 “-” “Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13”
- - [13/Feb/2011:21:25:03 -0800] “GET /favicon.ico HTTP/1.1” 304 172 “-” “Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13”[/font]

I’ve even tried a clean install of Django on a new sub-domain - using passenger, as describe here: http://wiki.dreamhost.com/Django - and followed the ‘Polls’ tutorial app instructions through to the top of this section: http://docs.djangoproject.com/en/dev/intro/tutorial02/ and still get the same error. If I remove the
[font=Courier] ‘polls’,[/font]
line from INSTALLED_APPS in settings.py, the admin site load correctly.

If I leave the ‘polls’ line in settings.py and launch a server via:
[font=Courier]$ ./manage.py runserver :8080[/font]
and load :8080/admin/ then the admin site also loads correctly, with Polls correctly installed, etc. So the same code works via runserver and does not work via passenger_wsgi.

Does anyone have any ideas how to fix or further diagnose this?


Mystery solved. In case anyone runs into the same:

I ran django-setup.py in my [font=Courier]~//[/font] directory, which created a sub directory for my project… [font=Courier]~//[/font]

I placed polls in this new sub-directory: [font=Courier]~///polls[/font]

passenger_wsgi.py was adding the current working dir (e.g.: [font=Courier]~//[/font]) to the path, so polls was not in the path.

So the solution was any one of the following 3 changes:
[]change settings.py to [font=Courier].polls[/font] instead of just polls in INSTALLED_APPS
]bring polls up a level to [font=Courier]~//polls[/font]
[*]change passenger_wsgi.py to add [font=Courier]~///[/font] to the path


Thank you so much for posting this. Was exactly my problem.


Thanks, this was helpful.
I’m having the same problem with south.
If I put the south directory under my_proj then the site loads but manage.py cannot run south.
If I move south anywhere else, the site does not load, unless i remove south from my installed apps.
I tried placing south in home/user/lib/python and setting PYTHONPATH but that does not work and PYTHONPATH seems to get deleted when I do a pkill python.
Also tried adding south to passenger_wsgi.py (i.e. sys.path.insert(0,’/home/my_site/lib/python/South-0.7.6-py2.6.egg’)) without success.

Any suggestions?


Any chance you live in Ireland DjinnE, because I most definitely owe you a pint. I don’t think that I would have come up with that solution myself, even though I should really have considered it. It’s a bit ridiculous that you get no error feedback but there you go, you solved it without it and you are now owed one beer token!

Thanks very much!

If anyone is seeking advice in relation to which solution to use, I would advise solution one as it requires only one change and will ensure that future added application don’t fall prey to the same problem, for example if you forget to add the mysite.new app in the settings and models files.

To implement this solution I added the line: sys.path.append("/home/user_name/my_site/my_project/")
immediately after: sys.path.append(os.getcwd())

I wasn’t sure if it was possible to add them on the same sys.path.append() call so I just separated them out for certainty.

(As you can see from my post count, I registered especially to say thank you)