Django install on a shared host, .htaccess help
Posted
by
redconservatory
on Stack Overflow
See other posts from Stack Overflow
or by redconservatory
Published on 2011-01-03T00:51:32Z
Indexed on
2011/01/03
0:53 UTC
Read the original article
Hit count: 253
I am trying to install Django on a shared host using the following instructions: docs.google.com/View?docid=dhhpr5xs_463522g
My problem is with the following line on my root .htaccess:
RewriteRule ^(.*)$ /cgi-bin/wcgi.py/$1 [QSA,L]
When I include this line I get a 500 error with almost all of my domains on this account.
My cgi-bin directory is home/my-username/public_html/cgi-bin/
The wcgi.py file contains:
#!/usr/local/bin/python
import os, sys
sys.path.insert(0, "/home/username/django/")
sys.path.insert(0, "/home/username/django/projects")
sys.path.insert(0, "/home/username/django/projects/newprojects")
import django.core.handlers.wsgi
os.chdir("/home/username/django/projects/newproject") # optional
os.environ['DJANGO_SETTINGS_MODULE'] = "newproject.settings"
def runcgi():
environ = dict(os.environ.items())
environ['wsgi.input'] = sys.stdin
environ['wsgi.errors'] = sys.stderr
environ['wsgi.version'] = (1,0)
environ['wsgi.multithread'] = False
environ['wsgi.multiprocess'] = True
environ['wsgi.run_once'] = True
application = django.core.handlers.wsgi.WSGIHandler()
if environ.get('HTTPS','off') in ('on','1'):
environ['wsgi.url_scheme'] = 'https'
else:
environ['wsgi.url_scheme'] = 'http'
headers_set = []
headers_sent = []
def write(data):
if not headers_set:
raise AssertionError("write() before start_response()")
elif not headers_sent:
# Before the first output, send the stored headers
status, response_headers = headers_sent[:] = headers_set
sys.stdout.write('Status: %s\r\n' % status)
for header in response_headers:
sys.stdout.write('%s: %s\r\n' % header)
sys.stdout.write('\r\n')
sys.stdout.write(data)
sys.stdout.flush()
def start_response(status,response_headers,exc_info=None):
if exc_info:
try:
if headers_sent:
# Re-raise original exception if headers sent
raise exc_info[0], exc_info[1], exc_info[2]
finally:
exc_info = None # avoid dangling circular ref
elif headers_set:
raise AssertionError("Headers already set!")
headers_set[:] = [status,response_headers]
return write
result = application(environ, start_response)
try:
for data in result:
if data: # don't send headers until body appears
write(data)
if not headers_sent:
write('') # send headers now if body was empty
finally:
if hasattr(result,'close'):
result.close()
runcgi()
Only I changed the "username" to my username...
© Stack Overflow or respective owner