Django 403禁止错误ajax(带csrf令牌)GET [英] Django 403 forbidden error ajax (with csrf token) GET

查看:167
本文介绍了Django 403禁止错误ajax(带csrf令牌)GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用django-ajax选择从我的数据库中选择一个城市。
输入字段时,我会收到403错误(GET方法)。这是捕捉,昨天工作,我没有碰到任何相关的。

I'm using django-ajax-selects to select a city from my database. When typing in the field, I get a 403 error (GET method). Here's the catch, it worked yesterday, and I didn't touch anything relevant.

Forbidden (Permission denied): /lookups/ajax_lookup/city
[30/Jan/2016 15:54:01]"GET /lookups/ajax_lookup/city?term=Lyon HTTP/1.1" 403 22



我的表单



My form

<form enctype="multipart/form-data" id="JobOfferForm" action="" method="POST">
    {% csrf_token %}

    <div class="row">
        <div class="input-field col s12">
            <p class="grey-text">Ville</p>
            {{ jobOfferForm.city }}
        </div>
    </div>

    <button class="btn waves-effect waves-light" name="jobOfferFormOK" type="submit">Sauvegarder</button>
</form>

提前感谢

推荐答案

我已经弄清楚了!

我忘了在我的 CityLookup中添加一个 check_auth 方法,所以它只适用于员工用户...我应该更好地阅读文档。

I have figured it out!
I forgot to include a check_auth method in my CityLookup, so it worked only for staff users... I should have read the documentation better.

def check_auth(self, request):
    if not request.user.is_authenticated() or not request.user.has_beta_access:
        raise PermissionDenied

现在可以使用了!

这篇关于Django 403禁止错误ajax(带csrf令牌)GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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