gpt4 book ai didi

python - Django 项目上的 SSL(django-sslserver) 问题

转载 作者:太空宇宙 更新时间:2023-11-03 15:14:23 25 4
gpt4 key购买 nike

我在 virtualenv 中使用 Django 1.6.2,Ubuntu 12.04 LTS。因为我想将我的项目转移到 https,所以我安装了 django-sslserver .
该项目需要自签名,并且适用于主页。但是,我的 django 项目中的应用程序遇到了问题。并非所有页面都重定向到 https,因此会导致 404 错误(仅当明确前缀为 https 时才有效)。此外,整个模板(外观即静态文件?)丢失了。这里到底发生了什么?如何确保所有页面都重定向到 https 并以与 http 相同的方式工作?

最佳答案

已编辑:我的拉取请求已合并。静态资源现在可以正常服务了。

问题是 runsslserver 命令没有实现为静态资源提供服务。一种修复方法是覆盖 PATH_TO_PYTHON_SITE_PACKAGE/sslserver/management/commands/runsslserver.py 中的 get_handler,如下所示:

# ...
from django.contrib.staticfiles.handlers import StaticFilesHandler
from django import get_version

# ...

class Command(runserver.Command):
# ...

help = "Run a Django development server over HTTPS"

def get_handler(self, *args, **options):
"""
Returns the static files serving handler wrapping the default handler,
if static files should be served. Otherwise just returns the default
handler.

"""
handler = super(Command, self).get_handler(*args, **options)
use_static_handler = options.get('use_static_handler', True)
insecure_serving = options.get('insecure_serving', False)
if use_static_handler:
return StaticFilesHandler(handler)
return handler

# ...

您可能希望通过以下方式获取站点包路径

python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"

我还提交了一份 pull request如果你想自己分支、合并并重新安装它作为一个包。

干杯

关于python - Django 项目上的 SSL(django-sslserver) 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22829216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com