为什么我的Django应用程序无法与Apache / mod_python一起使用?

时间:2021-11-10 20:39:08

I have Apache setup to serve requests for http://www.mysite.com from this directory:

我有Apache设置来从这个目录服务http://www.mysite.com的请求:

/var/www/html/www.mysite.com

The Django site is in /var/www/html/www.mysite.com/mysite.

Django网站位于/var/www/html/www.mysite.com/mysite。

I get this error when I make a request for /mysite/app/foo:

当我向/ mysite / app / foo发出请求时,我收到此错误:

(big stack trace) AttributeError: 'module' object has no attribute 'common'

(大堆栈跟踪)AttributeError:'module'对象没有属性'common'

'myapp.common' is the first item listed after all the django apps (eg. 'django.contrib.admin') in INSTALLED_APPS in the settings.py file. If I change the order of modules listed, Django chokes on the first path of one of my applications that it encounters.

'myapp.common'是settings.py文件中INSTALLED_APPS中所有django应用程序(例如'django.contrib.admin')之后列出的第一个项目。如果我改变列出的模块的顺序,Django会在我遇到的一个应用程序的第一条路径上窒息。

The Python import path seems to be correct, since it's finding mysite.settings:

Python导入路径似乎是正确的,因为它找到了mysite.settings:

<Location "/mysite/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonOption django.root /mysite
    PythonDebug On
    PythonPath "['/var/www/html/www.mysite.com'] + sys.path"
</Location>

What could be the problem? It's strange that it's complaining about 'common' when the actual list contains 'mysite.common':

可能是什么问题呢?奇怪的是,当实际列表包含'mysite.common'时,它正在抱怨'常见':

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'mysite.common',
    ....

Is this a Django bug or do I have something misconfigured? Perhaps some external dependency needs to be added to the import path? It works OK with the Django development server.

这是一个Django错误还是我有错误的配置?也许某些外部依赖需要添加到导入路径中?它适用于Django开发服务器。

3 个解决方案

#1


Does your mysite directory contain a __init__.py file? It should, to mark it as a package.

你的mysite目录是否包含__init__.py文件?它应该,将其标记为一个包。

#2


Is mysite.common a package stored under /var/www/html/www.mysite.com/mysite/common? If so try using common instead of mysite.common in INSTALLED_APPS.

mysite.common是否存储在/var/www/html/www.mysite.com/mysite/common下?如果是这样,请尝试在INSTALLED_APPS中使用common而不是mysite.common。

#3


I'm guessing you're obscuring your actual module name intentionally, which is fine... but I got this error when I had named my Django site (mysite, in your case) with the same name as a Python module that exists elsewhere in sys.path.

我猜你是故意模糊你的实际模块名称,这很好......但是当我用其他地方存在的Python模块命名我的Django网站(在你的情况下是mysite)时我得到了这个错误在sys.path中。

For example, if you created a Django site called math, with an app called common inside of it, you'd get this error because the Python system math module doesn't contain an attribute or submodule named common.

例如,如果您创建了一个名为math的Django站点,其中有一个名为common的应用程序,则会出现此错误,因为Python系统数学模块不包含名为common的属性或子模块。

You'll have to rename your Django site to not collide with the other module name.

您必须将Django站点重命名为不与其他模块名称冲突。

#1


Does your mysite directory contain a __init__.py file? It should, to mark it as a package.

你的mysite目录是否包含__init__.py文件?它应该,将其标记为一个包。

#2


Is mysite.common a package stored under /var/www/html/www.mysite.com/mysite/common? If so try using common instead of mysite.common in INSTALLED_APPS.

mysite.common是否存储在/var/www/html/www.mysite.com/mysite/common下?如果是这样,请尝试在INSTALLED_APPS中使用common而不是mysite.common。

#3


I'm guessing you're obscuring your actual module name intentionally, which is fine... but I got this error when I had named my Django site (mysite, in your case) with the same name as a Python module that exists elsewhere in sys.path.

我猜你是故意模糊你的实际模块名称,这很好......但是当我用其他地方存在的Python模块命名我的Django网站(在你的情况下是mysite)时我得到了这个错误在sys.path中。

For example, if you created a Django site called math, with an app called common inside of it, you'd get this error because the Python system math module doesn't contain an attribute or submodule named common.

例如,如果您创建了一个名为math的Django站点,其中有一个名为common的应用程序,则会出现此错误,因为Python系统数学模块不包含名为common的属性或子模块。

You'll have to rename your Django site to not collide with the other module name.

您必须将Django站点重命名为不与其他模块名称冲突。