Apache mod_wsgi error: Forbidden You don't have permission to access / on this server

后端 未结 5 1763
长发绾君心
长发绾君心 2020-12-01 14:35

I\'m using Ubuntu 10.04.
I create a django project under /home/wong2/Code/python/django2/ named atest
and create a wsgi file setting.

5条回答
  •  鱼传尺愫
    2020-12-01 15:25

    You may get a surprise where your WSGI has its home directory! On my admittedly naive wsgi_mod installation, it is / - I was so surprised I had to write this script to make sure:

    import os
    
    def application(environ, start_response):
        status = '200 OK'; e=os.listdir(os.getcwd())
        output = '''WSGI %s
    '''%(e) response_headers = [('Content-type', 'text/html'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output]

    That means imported applications will need a full path to be found, e.g.:

    sys.path.append('/home/foo/www/Forms')
    from DataCommon import page
    

    This is the recommended (by Google) approach to this:

    import sys; path='/home/foo/www/Forms';
    if path not in sys.path: sys.path.append(path)
    

提交回复
热议问题