Python 如何要求此Django视图使用HTTPS?
我如何将所需的HTTPS添加到此中?我通常有一个装饰师 但在这种情况下,我不能应用它Python 如何要求此Django视图使用HTTPS?,python,django,http,rest,https,Python,Django,Http,Rest,Https,我如何将所需的HTTPS添加到此中?我通常有一个装饰师 但在这种情况下,我不能应用它 (r'^login/?$','django.contrib.auth.views.login',{'template_name':'login.html', 'authentication_form':CustomAuthenticationForm}), 我相信您可以这样包装函数: def secure_required(view_func): """Decorator makes sure URL
(r'^login/?$','django.contrib.auth.views.login',{'template_name':'login.html', 'authentication_form':CustomAuthenticationForm}),
我相信您可以这样包装函数:
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('http://', 'https://')
return HttpResponseRedirect(secure_url)
return view_func(request, *args, **kwargs)
return _wrapped_view_func
从django.contrib.auth.views导入登录
需要从导入安全工具
urlpatterns=模式(“”,
(r“^login/?$”,需要安全(登录),{'template\u name':'login.html','authentication\u form':CustomAuthenticationForm}),
)
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}),
)