小编Bij*_*joy的帖子

Django CSRF 验证失败。即使使用@csrf_exempt 请求也中止

这是我的 view.py 我试图从支付网关获得响应,但我获得403 Forbidden CSRF 验证失败。请求中止。付款后,我为视图豁免了 CSRF 令牌,但仍然显示相同的错误

from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def resp(request, encResp):
    print " RESPONSE WITH CSRF EXEMPT " 
    '''
    Please put in the 32 bit alphanumeric key in quotes provided by CCAvenues.
    '''
    workingKey = WorkingKey
    decResp = decrypt(encResp,workingKey)
    data = '<table border=1 cellspacing=2 cellpadding=2><tr><td>'   
    data = data + decResp.replace('=','</td><td>')
    data = data.replace('&','</td></tr><tr><td>')
    data = data + '</td></tr></table>'

    html = '''\
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Response Handler</title>
        </head>
        <body>
            <center>
                <font …
Run Code Online (Sandbox Code Playgroud)

python django ccavenue django-1.9

5
推荐指数
1
解决办法
1000
查看次数

Flask-restful 基本认证

我是 Flask 的新手,我的学业需要一些帮助。

我正在尝试使用flask-restful构建一个简单的待办事项列表系统。

我当前的代码如下所示:

class ToDoList(Resource):
    '''TODO LIST'''
    operation = ['delete']
    decorators = [auth.login_required, advertise('operation')]
    def post(self):
        """remove all item in the TODO list"""
        operation = request.args.get('op')
        if operation == 'delete':
            collection2.delete_many({})
            return {'Success': 'OK'}, 200
        return {'Error':'Illegal Operation'}, 400
    def get(self):
        """return a list of the TODO name"""
        list_1 = collection2.find()
        list_2 = []
        for each in list_1:
            list_2.append(JSONEncoder().encode(each))
        return {'list':list_2}, 200
Run Code Online (Sandbox Code Playgroud)

它有效,但我只post想要需要身份验证的方法和不需要身份验证的get方法,这样任何人都可以在不登录的情况下获取列表。我正在使用flask-restful 我不知道如何分别为每个函数提供装饰器。

python flask flask-restful

3
推荐指数
1
解决办法
3533
查看次数

标签 统计

python ×2

ccavenue ×1

django ×1

django-1.9 ×1

flask ×1

flask-restful ×1