2

I'm currently trying to set up a Django project using passenger wsgi. I followed the instructions laid out on this post:

Update new Django and Python 2.7.* with virtualenv on Dreamhost (with passenger)

However, I'm receiving an error "An error occurred importing your passenger_wsgi.py"

I am able to successfully receive a hello word message if I put this as my passenger_wsgi.py:

def application(environ, start_response):
    start_response('200 OK', [('Content-type', 'text/plain')])
    return ["Hello, world!"]

But for some reason if I use the following (outlined in the above post), I am unable to get past the error. I replace the word 'project' with my named project on the path.append and os.environ lines and with subdomain.domain.com on the path.insert lines. Am I missing something? I am very new to this stuff and would appreciate any help I can get! Thanks.

Below is the current passenger_wsgi.py that receives the error on importing.

import sys, os
cwd = os.getcwd()
sys.path.append(cwd)
sys.path.append(cwd + '/project')

if sys.version < "2.7.3": os.execl("$HOME/<site>/env/bin/python",
"python2.7.3", *sys.argv)

sys.path.insert(0,'$HOME/<site>/env/bin')
sys.path.insert(0,'$HOME/<site>/env/lib/python2.7/site-packages/django')
sys.path.insert(0,'$HOME/<site>/env/lib/python2.7/site-packages')

os.environ['DJANGO_SETTINGS_MODULE'] = "project.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

UPDATE I was able to get a passenger wsgi that imports but now I'm getting a 500 error. Here is what I'm sitting at right now:

import sys, os
sys.path.append(os.getcwd())
sys.path.append(os.path.join(os.getcwd(), 'project'))

sys.path.insert(0, 'home/<site>/env/bin')
sys.path.insert(0, 'home/<site>/env/lib/python2.7/site- packages/django')
sys.path.insert(0, 'home/<site>/env/lib/python2.7/site-packages')
sys.path.insert(0, 'home/<site>/roommates')

os.environ['DJANGO_SETTINGS_MODULE'] = "project.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Once again I'm stuck though. I can't seem to find why I'm getting this error. The current errors that are showing up in the error logs are as follows per attempt:

Premature end of script headers:
Premature end of script headers: internal_error.html
Community
  • 1
  • 1
sailboatlie
  • 346
  • 1
  • 6
  • 18

1 Answers1

0

You should change this line:

sys.path.append(os.path.join(os.getcwd(), 'project'))

into

sys.path.append(os.path.join(os.getcwd() + 'project'))

and make sure you change project with the name of your real project (or django app)

gcatalfamo
  • 243
  • 2
  • 14