简体   繁体   English

在Apache上设置django的问题

[英]Problem setting up django on Apache

This is probably really simple. 这可能很简单。 But I guess I'm too new to WSGI and Django to get it on my own. 但我想我对WSGI和Django来说太新了,不能靠我自己来做。 I have a brand new shiny Django project on a Ubuntu virtual machine hosted in /var/www/mysite. 我在/ var / www / mysite中托管的Ubuntu虚拟机上有一个全新的闪亮Django项目。 The project was created with 该项目是用。创建的

django-admin startproject mysite

I'm following a WSGI tutorial to get it set up, so I created an ./apache folder, inside of which I placed this file, django.wsgi: 我正在按照WSGI教程来设置它,所以我创建了一个./apache文件夹,在其中我放置了这个文件,django.wsgi:

import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = '/var/www/mysite/mysite.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

I then added this config line to the Apache configuration: 然后我将此配置行添加到Apache配置中:

WSGIScriptAlias / /var/www/mysite/apache/django.wsgi

When I try to hit the site, nothing is returned. 当我尝试访问该网站时,不会返回任何内容。 The connection just hangs. 连接只是挂起。 This is in my access.log: 这是在我的access.log中:

192.168.2.116 - - [15/Aug/2010:14:09:02 -500] "GET / HTTP/1.1" 500 639 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8

So it's hitting the site. 所以它正在击中网站。 But someone isn't doing anything. 但有人没有做任何事情。 There are no errors in the errors.log. errors.log中没有错误。

Anyone have any ideas? 有人有主意吗?

The blatant mistake in original question is that: 原始问题中明显的错误是:

os.environ['DJANGO_SETTINGS_MODULE'] = '/var/www/mysite/mysite.settings'

would need to be: 需要是:

sys.path.append('/var/www')
sys.path.append('/var/www/mysite')

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

That is, Django settings module must be a Python package path, NOT an absolute file system path. 也就是说,Django设置模块必须是Python包路径,而不是绝对文件系统路径。 The accepted answer doesn't even point that out and rather just gives another set of code to use with no explanation. 接受的答案甚至没有指出,只是给出了另一组代码,无需解释。

Further, you need to set Python module search path, ie., sys.path, so that Python can find your settings file listed in that environment variable. 此外,您需要设置Python模块搜索路径,即sys.path,以便Python可以找到该环境变量中列出的设置文件。

Finally, if your browser was hanging you have done something else wrong as well, as what you did should have resulted in an error being returned and not the browser hanging. 最后,如果您的浏览器挂起,您也做了其他错误,因为您所做的应该导致返回错误而不是浏览器挂起。 There would also have had to be an error in the Apache error log, so you are either looking in wrong place or don't know what to look for. Apache错误日志中也必须存在错误,因此您要么在错误的位置查找,要么不知道要查找的内容。

Aren't you missing path to your Django application? 你错过了Django应用程序的路径吗? My app.wsgi has this: 我的app.wsgi有这个:

import os, sys
sys.path.append('/usr/local/src/django-1.2') # django is outside default path
sys.path.append('/usr/local/src/django-photologue-2.2') # app i'm using
sys.path.append('/var/www/mysite')

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
# this is regular python import, so my settings are physically
# here: /var/www/mysite/settings.py

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM