我有一个小的Django网站,我试图运行在apache2.2http服务器上。 使用“python”应用程序运行良好管理.py运行服务器”。在
Django版本:1.0.2 final
Python:2.5
操作系统:Windows 2000
我没有完成documentation中描述的步骤,经过一番摆弄,我在httpd.conf一
<Location "/therap/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
PythonOption django.root /therap
PythonDebug On
PythonPath "['D:/therap/therap'] + sys.path"
</Location>
MaxRequestsPerChild 1
D:\therap\therap being the place where我的管理.py是。在
当我试图在浏览器中打开时,我看到Django使用的样式有错误(与白底黑courier相反)
^{pr2}$有一个网址.py在D:\therap\therap中。 但是在我大部分代码所在的D:\therap\therap\main中没有。在
然后我尝试使用父文件夹
<Location "/therap/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE therap.settings
PythonOption django.root /therap
PythonDebug On
PythonPath "['D:/therap'] + sys.path"
</Location>
MaxRequestsPerChild 1
这给了我一个不同的错误:
MOD_PYTHON ERROR
ProcessId: 2424
Interpreter: '***'
ServerName: '****'
DocumentRoot: 'C:/Programme/Apache Software Foundation/Apache2.2/htdocs'
URI: '/therap/'
Location: '/therap/'
Directory: None
Filename: 'C:/Programme/Apache Software Foundation/Apache2.2/htdocs/therap'
PathInfo: '/'
Phase: 'PythonHandler'
Handler: 'django.core.handlers.modpython'
Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)
File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1229, in _process_target
result = _execute_target(config, req, object, arg)
File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1128, in _execute_target
result = object(arg)
File "C:\Python25\lib\site-packages\django\core\handlers\modpython.py", line 228, in handler
return ModPythonHandler()(req)
File "C:\Python25\lib\site-packages\django\core\handlers\modpython.py", line 201, in __call__
response = self.get_response(request)
File "C:\python25\Lib\site-packages\django\core\handlers\base.py", line 67, in get_response
response = middleware_method(request)
File "C:\python25\Lib\site-packages\django\middleware\locale.py", line 17, in process_request
translation.activate(language)
File "C:\python25\Lib\site-packages\django\utils\translation\__init__.py", line 73, in activate
return real_activate(language)
File "C:\python25\Lib\site-packages\django\utils\translation\trans_real.py", line 209, in activate
_active[currentThread()] = translation(language)
File "C:\python25\Lib\site-packages\django\utils\translation\trans_real.py", line 198, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "C:\python25\Lib\site-packages\django\utils\translation\trans_real.py", line 183, in _fetch
app = __import__(appname, {}, {}, [])
ImportError: No module named main
我确实使用了国际化模块,但我不明白它为什么会在这一点上引起问题。在
“main”是唯一的Django应用程序(包含视图、模型、表单等)的名称。完整路径是D:\therap\therap\main。在
我把__init__.py
-文件放在从主文件夹到d:\therap的任何地方。在
现在我不知道我还能做什么。有什么想法吗?在
问题是,您导入的应用程序(“main”)就好像它直接位于Python路径上一样,而您的URLconf(“网址)就好像它位于Python路径上的“therap”模块中。只有当“D:/therap”和“D:/therap/therap”都在Python路径上时,这才有效(runserver会自动为您做这件事,以“使事情变得简单”;尽管它最终只是将混乱推迟到部署时间)。可以通过在Apache配置中使用以下行来模拟runserver的行为:
标准化引用可能更有意义,这样Python路径只需要包含其中一个。通常的方法(至少是我经常看到的引用方式)是在Python路径上加上“D:\therap”,并将您的应用程序限定为主治疗室而不仅仅是“主”。就我个人而言,我采取相反的方法,效果很好:在Python路径上放置“D:\therap\therap”,并将ROOT\URLCONF设置为“url”,而不是网址". “如果你不想让你的应用程序成为一个可重复使用的应用程序,那么这个应用程序的名字就好像你不想让它成为一个可重复使用的应用程序的主要优点”。在
相关问题 更多 >
编程相关推荐