Jump to content

Can't get Django to work


J..

Recommended Posts

I've followed the instructions here, but I just see the dispatch.wsgi file's source code, even though its permissions are set to 755. The project is just something simple to see if I could get it to work, and it runs fine locally. Have I done something wrong?

Link to comment
Share on other sites

Okay, sorry to bother you again, but urllib2.urlopen doesn't seem to be working in Django. If I put the following script in cgi-bin:

#!/usr/bin/python
print "Content-type:text/html\n"
from urllib2 import urlopen, URLError
out = ""
try:
    urlopen("http://google.com")
except URLError, e:
    print "<p>"+str(e.reason)+"</p>"
print "<p>done</p>"

The output is '<p>done</p>'. But if I use this in Django (views.py):

from django.shortcuts import HttpResponse
from urllib2 import urlopen, URLError

def sample (request):
    out = ""
    try:
        urlopen("http://google.com")
    except URLError, e:
        out += "<p>"+str(e.reason)+"</p>"
    out += "<p>done</p>"
    return HttpResponse(out)

The output is '<p>unable to select on socket</p><p>done</p>'.

 

Is there any reason this might be happening? These are located here and here respectively

Link to comment
Share on other sites

Unfortunately, I barely know any Python. Here's what I can tell you: when you access Python through the cgi-bin method, it loads as CGI through Apache's mod_cgi. On the other hand, when you access Python through the Django method, it loads as WSGI through Apache's mod_wsgi. We only have one version of Python installed, but perhaps different Python eggs are preloaded for each system. Perhaps you should try manually added a Python egg for urlopen in your Django app? Also, try installing SnakeCharmer (looks like this) to check if urlopen is installed.

 

I would probably try to direct this question at a Python-specific forum. If they tell you that your host is at fault, make sure to ask them exactly what I need to do to fix the problem and I'll do my best to help.

Link to comment
Share on other sites

It's definitely there, it's just not working right through Django. Thanks anyway; I'll see what I can find out.

 

Wait, what do you mean, 'try installing SnakeCharmer'? What is it, and why would it help?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...