WSGIServer errors when trying to run Django app

前端 未结 2 1183
我寻月下人不归
我寻月下人不归 2020-12-15 12:26

Firstly, here\'s my script:

#!/usr/bin/python
import sys, os

sys.path.append(\'/home/username/python\')
sys.path.append(\"/home/username/python/flup\")
sys.         


        
相关标签:
2条回答
  • 2020-12-15 12:38

    Solved it. This .htaccess file did the trick, for whatever reason. I swear I tried all this before...

    AddHandler fcgid-script .fcgi
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteRule ^(media/.*)$ - [L]
    RewriteRule ^(adminmedia/.*)$ - [L]
    RewriteCond %{REQUEST_URI} !(cgi-bin/myproject.fcgi)
    RewriteRule ^(.*)$ cgi-bin/myproject.fcgi/$1 [L]
    
    0 讨论(0)
  • 2020-12-15 12:46

    The script expects those params to be passed as environment variables. Since they are not present in your shell environment, and the script is not running in the apache fastcgi environment (which provides them), it complains.

    Do you have access to apache error logs? What do they say?

    Does your host have mod_wsgi support? If so, you could use Django's wsgi handler:

    import sys
    import os
    
    base = os.path.dirname(os.path.abspath(__file__)) + '/..'
    sys.path.append(base)
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'yourproject.settings'
    
    import django.core.handlers.wsgi
    
    application = django.core.handlers.wsgi.WSGIHandler()
    

    Further instructions can be found on the modwsgi wiki, and the Django docs.

    0 讨论(0)
提交回复
热议问题