本文介绍了如何为此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?
发布评论