from flask import *
from flask_restful import *
import sqlite3
import database
@app.route('/admin')
def admin():
""" hanldes the admin page for user entry """
db = database.database()
db.create()
db.table('admin')
#data = db.print_database('admin')
#return render_template ("mylogin.html", input = 'admin', dbs = data.fetchall())
return render_template ("mylogin.html", input = 'admin')
@app.route('/admin', methods = ["POST"])
def admin_post():
""" hanldes the admin page for user entry """
print "handling post"
return request.form['text']
if __name__ == "__main__":
app.run(debug=True)
HTML CODE : I have not posted the entire code here as not deviate from the issue I am facing. I am able to open the /admin page and when I give an input , getting an error "Method is not allowed for the requested URL"
<h2>welcome admin</h2>
<form action="." method ="POST">
hello admin
<input type = "text" name = "text">
<input type = "submit" name ="my-form" value = "Send">
</form>
Change your html to this:
<h2>welcome admin</h2>
<form action="{{ url_for('admin_post') }}" method ="POST">
<input type = "text" name = "text">
<input type = "submit" name ="my-form" value = "Send">
</form>
What you're basically doing is sending the form to your admin function which only accepts GET requests.
You need to post your form to the admin_post function which accepts POST requests.
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.