Django 403 forbidden error ajax (with csrf token) GET

半世苍凉 提交于 2019-12-12 04:06:01

问题


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.

Console log

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>

Thanks in advance.


回答1:


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

Now it works!



来源:https://stackoverflow.com/questions/35103266/django-403-forbidden-error-ajax-with-csrf-token-get

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!