前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python-django-apache

python-django-apache

作者头像
py3study
发布2020-01-08 16:10:57
5750
发布2020-01-08 16:10:57
举报
文章被收录于专栏:python3python3

今天弄了一天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,报错如下

代码语言:javascript
复制
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
代码语言:javascript
复制
不明白什么错误,点下F5,管理端居然能访问了,但是没有css,找了半天错误日志,看不大明白,要下班了,写到这里,如果有那位大侠知道原因还望告知,刚刚在apache上做django的部署就这么大打击
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
访问管理
访问管理(Cloud Access Management,CAM)可以帮助您安全、便捷地管理对腾讯云服务和资源的访问。您可以使用CAM创建子用户、用户组和角色,并通过策略控制其访问范围。CAM支持用户和角色SSO能力,您可以根据具体管理场景针对性设置企业内用户和腾讯云的互通能力。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档