Django_registration

apps

#1

Hi DH’ers-
I’m having a strange problem where my django app running via the normal webserver for my domain throws error messages; but when I run the django test web server no errors occur.

I’ve got passenger_wsgi on my domain, and setup django according to the wiki instructions. It seems to be working fine except under this weird circumstance.

I downloaded the django_registration application and set it up. It doesn’t work, instead it gives me a 500 error; so I figure something is wrong with the app and I need to debug it.

The first problem is, I don’t get any error messages, just 500’s in the browser and “Premature end of script headers: …” in the error logs at /home/…/logs/…/error.log . Not helpful.

But, I can work around that by SSH’ing in and running the django test server in my actual project directory, and connecting to it using the w3m text-mode browser. And when doing this, the code works fine, and no errors.

I searched in the wiki and found that sometimes the 500 errors occur because of a file permissions thing under PHP. Though this isn’t PHP I tried changing the file permissions and no difference.

So it appears to me that there is something amiss with passenger_wsgi.

If anyone has had a similar experience and fixed it, i’d really like to know!

thank you,
quietlyconfident


#2

Hi All-
I found a fix for this. I put it in the wiki here: http://wiki.dreamhost.com/Passenger_WSGI#500_Errors_with_Passenger_WSGI_Workaround

That text (this bboard will mangle the spacing of the below python code, near the end everything from status to return should be indented)

Passenger WSGI at the moment has trouble dealing with errors. Namely, if your WSGI application (for example - but not limited to - Django) raises an uncaught exception Passenger will die, a 500 page will be displayed in the browser, and the error message will not be recorded in the /home/username/logs/sitename/http/error.log file. This makes debugging really tricky.

One solution is to use Python Paste as a WSGI middleware between passenger and your application (django for me). Here is how I did it:

  1. Grab Paste from here: http://pypi.python.org/pypi/Paste . Unzip, all you need is the “paste” directory; put it into your application directory (for example, /home/username/sitename/myapp/paste)
  2. Edit your passenger_wsgi.py file to include that directory in the python path, and load paste up. Here is what your passenger_wsgi.py file might look like:

import sys, os
cwd = os.getcwd()
myapp_directory = cwd + '/myapp’
sys.stdout = sys.stderr
sys.path.insert(0,myapp_directory)
sys.path.append(os.getcwd())
os.environ[‘DJANGO_SETTINGS_MODULE’] = "myapp.settings"
import django.core.handlers.wsgi
from paste.exceptions.errormiddleware import ErrorMiddleware
application = django.core.handlers.wsgi.WSGIHandler()

To cut django out of the loop, comment the above application = … line ,

and remove “test” from the below function definition.

def testapplication(environ, start_response):
status = '200 OK’
output = 'Hello World! Running Python version ’ + sys.version + '\n\n’
response_headers = [(‘Content-type’, ‘text/plain’),
(‘Content-Length’, str(len(output)))]

to test paste’s error catching prowess, uncomment the following line

while this function is the “application”

#raise(“error”)
start_response(status, response_headers)
return [output]
application = ErrorMiddleware(application, debug=True)


#3

I’ve still not gotten this to work. I can’t figure out if there’s something wrong with the wiki or with my config.
Here’s my passenger_wsgi.py :
import sys, os
cwd = os.getcwd()
myapp_directory = cwd + '/myapp’
sys.path.append(os.getcwd())
sys.stdout = sys.stderr
sys.path.insert(0,myapp_directory)
sys.path.append(os.getcwd())
os.environ[‘DJANGO_SETTINGS_MODULE’] = "mysite.settings"
import django.core.handlers.wsgi
from paste.exceptions.errormiddleware import ErrorMiddleware
application = django.core.handlers.wsgi.WSGIHandler()
def testapplication(environ, start_response):
[tab]status = ‘200 OK’
[tab]output = 'Hello World! Running Python version ’ + sys.version + ‘\n\n’
[tab]response_headers = [(‘Content-type’, ‘text/plain’),(‘Content-Length’, str(len(output)))]
[tab]start_response(status, response_headers)
[tab]return [output]
application = ErrorMiddleware(application, debug=True)

the error message i get when accessing any url is:
An error occurred importing your passenger_wsgi.py

The entire reason for me to use paste is that i used the dreamhost Django setup wizard but I could not even bring up /admin (that’s step 2 in the Django tutorials).


#4

I’m having the exact same problem. Been through the same steps.

I just cant deploy an existing django application on dreamhost. It works find locally, it works fine on “runserver”, but I get this 500 error on the web.

Any instructions on how to correctly deploy an existing django application?


#5

Same problem here. Django works fine for me with the default passenger script, but when I try using the python paste workaround, I’m getting “An error occurred importing your passenger_wsgi.py”

It’s not a very helpful error message, and I couldn’t find anything useful in my site’s logs. If anybody has figured out an answer to this issue, please enlighten us :slight_smile:


#6

I just went through this same exercise, and initially got the same errors as described by the most recent posters in this forum. I then simply ran python in an interactive shell and imported my passenger_wsgi.py module. I got the same errors, and was able to correct them (I did, indeed, have an error in my passenger_wsgi.py module). Once it worked in an interactive shell, it worked fine when invoked through dreamhost’s web server.

The net result was that I got my django application to run with passenger on my dreamhost account. And the “paste” hack was exactly what I needed in order to find the bug in my django app (that caused me to apply this paste-based config).


#7

The python path is wrong. For at least some of us, it is using the systems python path, and not including our virtaulenv.

If you put this as your passenger_wsgi.py - you will see what your current python path is (make sure you have your spaces right for the def application). If you set your python path yourself by uncommenting sys.path and filling it in correctly, things should work. if you arent sure what the “correct” python path should be, go to a python shell and type “import sys; print sys.path” and try using that value.

import sys, os
#sys.path = [SET THIS TO WHAT IT SHOULD BE AND UNCOMMENT IT AFTER YOU RUN THIS TEST]
os.environ['DJANGO_SETTINGS_MODULE'] = "YOUR SETTINGS FILE GOES HERE" # see your original file, and set this correctly, eg djangoproj.settings
import django.core.handlers.wsgi
#application = django.core.handlers.wsgi.WSGIHandler()
#uncomment above and remove below when you are done running this test and explicitly added your path
def application(environ, start_response):
   status = '200 OK'
   output = "Hello World! Running Python version %s with path: %s\n\n" % (sys.version, sys.path)
   response_headers = [('Content-type', 'text/plain'),
                       ('Content-Length', str(len(output)))]
   start_response(status, response_headers)
   return [output]

It’s kludgy to have to do this. I wonder what the “right” way is to get passenger to use our virtual env’s properly.