使用uploadify修复django csrf错误 [英] Fixing django csrf error when using uploadify

查看:108
本文介绍了使用uploadify修复django csrf错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的django管理员中使用uploadify,但是我收到403错误。当我使用 @csrf_exempt 时,错误消失了,但这是非常危险的。

I'm using uploadify in my django admin but I'm getting a 403 error. When I use @csrf_exempt the error is gone but this is very risky.

有没有更好的方法来解决这个问题,而不会影响管理页面使用@csrf_exempt装饰器?

Is there a better way to fix this problem without compromising the admin page by using @csrf_exempt decorator?

感谢提前

推荐答案

@Paul McMillan我面对同样的问题, csrf 保护一个观点,做一个小的&丑陋的解决方法提供基本的csrf验证,这里是代码

@Paul McMillan I faced the same problem with csrf protection of a view and made a small & ugly workaround to provide basic csrf validation, here is the code

from django.views.decorators.csrf import csrf_exempt
from django.middleware.csrf import CsrfViewMiddleware

def check_uploadify_csrf(request):
    return CsrfViewMiddleware().process_view(request, check_uploadify_csrf, None, None) == None

@csrf_exempt
def some_view(request):
    if check_uploadify_csrf(request):
        # do some actions

@ginad我使用uploadify选项 formData 将csrf令牌发送到后端

@ginad I used uploadify option formData to send csrf token to backend

formData:{csrfmiddlewaretoken:'{{csrf_token}}'},

谢谢,

Sultan

这篇关于使用uploadify修复django csrf错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆