Python web-Django CSRF跨站请求伪造防护( 六 )
from django.views.decorators.csrf import csrf_exemptcsrf_protect
@csrf_exempt
def login(request):
if request.method == 'GET':
return render(request'login.html')
else:
return HttpResponse('ok')
2、如果是类视图 , 需要使用方法装饰器进行封装
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exemptcsrf_protect
from django.views.generic import TemplateView
@method_decorator(csrf_exempt)
class LoginView(TemplateView):
template_name = 'login.html'
推荐阅读
- Python|阿里达摩院13小时讲完的python!整整466集,拿走不谢
- Python打开和关闭文件
- 用python爬了840款真无线蓝牙耳机数据,竟发现了几个有趣结论!
- 手把手教你使用Python操控手机微信app(最新教程)
- Python编程常用技巧,你全知道么?
- 升职加薪利器:Python+Pytest框架在Jenkins上生成Allure测试报告
- 编程零基础应当如何开始学习 Python?
- 女神照片当背景,使用Python做个免费的VIP视频播放软件
- 单身情人节,看看这位Python小哥如何完成人生的逆袭!
- 情人节来了,教你个用 Python 表白的技巧