Вопрос

I have a Flask Application running on Google App Engine. I am trying to submit a form built using WTForm and I keep getting the following error.

403 Forbidden: You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.

Location.html (Part of the code)

    <form method=post action="/home/location">
    ....
     <button type="submit" class="btn btn-primary" value="Submit">
                        Directions
                    </button>
    </form>

main.py

@app.route('/home/location', methods=['POST', 'GET'])
def location():
    form = cfcdirections.Direction(request.form)
    print(request.method)
    if request.method == 'POST' and form.validate():
        print("After if")
        directions = cfcdirections()
        street_no = directions.No
        street = directions.Street
        suburb = directions.Suburb
        postcode = directions.Postcode
        state = directions.State
    return render_template('Location.html',form=form)
Это было полезно?

Решение

Don't forget to include the CSRF token in your form:

<form method=post action="/home/location">
    {{ form.csrf_token }}
    ....
    <button type="submit" class="btn btn-primary" value="Submit">
                    Directions
                </button>
</form>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top