如何为此Django视图要求HTTPS?

编程入门 行业动态 更新时间:2024-10-28 04:20:03
本文介绍了如何为此Django视图要求HTTPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 (r'^login/?$','django.contrib.auth.views.login',{'template_name':'login.html', 'authentication_form':CustomAuthenticationForm}),

如何添加此需要的HTTPS?我通常有一个装饰师..

How do I add HTTPS required to this? I usually have a decorator for it..

但是在这种情况下我不能申请它。

But in this case I can't apply it.

def secure_required(view_func): """Decorator makes sure URL is accessed over https.""" def _wrapped_view_func(request, *args, **kwargs): if not request.is_secure(): if getattr(settings, 'HTTPS_SUPPORT', True): request_url = request.build_absolute_uri(request.get_full_path()) secure_url = request_url.replace('', '') return HttpResponseRedirect(secure_url) return view_func(request, *args, **kwargs) return _wrapped_view_func

推荐答案

我相信你可以用这种方式包装函数:

I believe you can wrap the function in this manner:

from django.contrib.auth.views import login from <<wherever>> import secure_required urlpatterns = patterns('', (r'^login/?$',secure_required(login),{'template_name':'login.html', 'authentication_form':CustomAuthenticationForm}), )

更多推荐

如何为此Django视图要求HTTPS?

本文发布于:2023-10-28 17:42:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537326.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   Django   HTTPS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!