. Advertisement .
..3..
. Advertisement .
..4..
I’m building a new program, but when I run it, an error pops up. The error displayed is as follows:
Method Not Allowed The method is not allowed for the requested URL
I have tried several workarounds, but they still do not get the desired results. If you have come across this situation and have a solution for the “the method is not allowed for the requested url” problem, pls let me know. Here is what I do:
@app.route('/entry', methods=['GET', 'POST'])
def entry_page():
if request.method == 'POST':
date = request.form['date']
title = request.form['blog_title']
post = request.form['blog_main']
post_entry = models.BlogPost(date = date, title = title, post = post)
db.session.add(post_entry)
db.session.commit()
return redirect(url_for('database'))
else:
return render_template('entry.html')
@app.route('/database')
def database():
query = []
for i in session.query(models.BlogPost):
query.append((i.title, i.post, i.date))
return render_template('database.html', query = query)
THIS IS THE BLOG ENTRY PAGE
blog:
<html>
<form action='/database' method = "post">
date<input name = "date" type = "text" class="text">
title<input name = "blog_title" type = "text" class="text">
main<input name = "blog_main" type = "text" class="text">
<input type = "submit">
</form>
</html>
THIS IS THE QUERY:
{{query}}
Thanks!
The cause:
After considering about your error, I find out that no url methods are accepted by the database route. This is the reason of your error.
Solution:
Let’s place the url methods in the app route as you do in the fuction of entry_page:
Similar problems occurred when I tried to deploy Flask in the IIS. IIS doesn’t accept routes that contain an underline (“_”), it seems. Problem solved when I removed underline.