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.
Answers:
You have a typo. It should be method
not methods
if request.method == 'POST':
Try using
if request.method == 'POST':
instead of
if request.methods == 'POST':
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.
You have a typo. It should be method
not methods
if request.method == 'POST':
Try using
if request.method == 'POST':
instead of
if request.methods == 'POST':