python-django-apache
2023-01-31 03:01:04
python
今天弄了一天Django,想把它架到apache上
这是apache的conf配置文件中我加入的内容
Listen 127.0.0.1:8888
<VirtualHost 127.0.0.1:8888>
<Location "/">
SetHandler python-program
PythonPath "['E:/code'] + sys.path"
PythonHandler djanGo.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE newtest.settings
PythonAutoReload On
PythonOption django.root /newtest
PythonDebug On
</Location>
Alias /site_media E:/code/newtest/media
Alias /media D:/Python25/Lib/site-packages/django/contrib/admin/media
<Location "/media/">
SetHandler None
</Location>
<Location "/site_media">
SetHandler None
</Location>
<Location "/media">
SetHandler None
</Location>
</VirtualHost>
根据网上搜到的相关文章操作的,其中设置media路径均使用绝对路径,修改好再设置settings,对settings的修改其实也只是对几个路径的修改,把相对路径改为绝对路径,如下面三个
STATIC_PATH = 'E:/code/newtest/media'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on windows.
# Don't forget to use absolute paths, not relative paths.
'E:/code/newtest/templates'
)
MEDIA_ROOT = 'E:/code/newtest/media'
运行服务器,网页访问没有CSS,对了半天认为路径设置没有错误,打开apache错误日志,发现拒绝访问,原来文件夹需要设置访问权限,否则服务器拒绝,修改吧,没办法
<Directory "E:/code/newtest/media/">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory "D:/Python25/Lib/site-packages/django/contrib/admin/media/">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
于是加了上面两段到apache的conf配置里面,一个是admin的meida路径一个是我工程所在位置的meida路径,保存后再打开网页,这次我的工程可以访问了,并且css都是加载的,界面和预期一样,但是访问管理端--admin,报错如下
MOD_PYTHON ERROR
ProcessId: 1500
Interpreter: 'localhost'
ServerName: 'localhost'
DocumentRoot: 'D:/Program Files/Apache Software Foundation/Apache2.2/htdocs'
URI: '/admin/'
Location: '/'
Directory: None
Filename: 'D:/Program Files/Apache Software Foundation/Apache2.2/htdocs/admin'
PathInfo: '/'
Phase: 'PythonHandler'
Handler: 'django.core.handlers.modpython'
Traceback (most recent call last):
File "D:\Python25\Lib\site-packages\mod_python\importer.py", line 1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)
File "D:\Python25\Lib\site-packages\mod_python\importer.py", line 1229, in _process_target
result = _execute_target(config, req, object, arg)
File "D:\Python25\Lib\site-packages\mod_python\importer.py", line 1128, in _execute_target
result = object(arg)
File "D:\Python25\lib\site-packages\django\core\handlers\modpython.py", line 222, in handler
return ModPythonHandler()(req)
File "D:\Python25\lib\site-packages\django\core\handlers\modpython.py", line 195, in __call__
response = self.get_response(request)
File "D:\Python25\lib\site-packages\django\core\handlers\base.py", line 128, in get_response
return self.handle_uncaught_exception(request, resolver, exc_info)
File "D:\Python25\lib\site-packages\django\core\handlers\base.py", line 160, in handle_uncaught_exception
return callback(request, **param_dict)
File "D:\Python25\lib\site-packages\django\views\defaults.py", line 88, in server_error
t = loader.get_template(template_name) # You need to create a 500.html template.
File "D:\Python25\lib\site-packages\django\template\loader.py", line 80, in get_template
source, origin = find_template_source(template_name)
File "D:\Python25\lib\site-packages\django\template\loader.py", line 73, in find_template_source
raise TemplateDoesNotExist, name
TemplateDoesNotExist: 500.html
不明白什么错误,点下F5,管理端居然能访问了,但是没有css,找了半天错误日志,看不大明白,要下班了,写到这里,如果有那位大侠知道原因还望告知,刚刚在apache上做django的部署就这么大打击
相关文章