简体   繁体   中英

Django 403 forbidden error ajax (with csrf token) 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.

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM