Flask – 'Request' object has no attribute 'methods'

Question:

I’m doing a project under flask, and I have a form which interacts with my database, but when I load the page where the form is I’m having this error:

AttributeError: ‘Request’ object has no attribute ‘methods’

I’ve take a look to other thread I haven’t found my solution so I’m requesting your help

Here is my app.py code:

@app.route('/add/', methods=['POST', 'GET'])
def add () :
    if not session.get('logged_in'):

    return render_template('login.html')
else:
    
    if request.methods == 'POST':
        nom = str(request.fom.get('nom'))
        lien = str(request.form.get('lien'))
        db = get_db()
        db.execute('INSERT INTO sites (nom, lien) VALUES(%(nom)s, %(lien)`s)',{'nom' : nom, 'lien' : lien})`
        db.commit()
return render_template('add.html')

and my HTML:

{% extends 'layout.html' %}

{% block titre %}
Ajouter un site
{% endblock %}

{% block body %}
<h1>Ajouter votre site</h1>


<form method="POST">
        <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
          <input class="mdl-textfield__input" type="text" id="nom" name="nom" required>
          <label class="mdl-textfield__label" for="nom">Nom du site</label>
        </div>

        <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
                <input class="mdl-textfield__input" type="text" id="lien" name="lien" required>
                <label class="mdl-textfield__label" for="lien">lien du site</label>
        </div>

        <input value="add" id="submit" type="submit">
      </form>
{% endblock %}

Thanks for your help.

Asked By: Newbiedev

||

Answers:

You have a typo. It should be method not methods

if request.method == 'POST':
Answered By: kundan

Try using

if request.method == 'POST':

instead of

if request.methods == 'POST':

Source: http://flask.pocoo.org/docs/0.12/quickstart/

Answered By: monomo
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.