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代码:我没有在这里发布整个代码,因为没有偏离我面临的问题。我能够打开/ admin页面,当我提供输入时,会收到错误"方法不允许所请求的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>
答案 0 :(得分:1)
将您的HTML更改为:
<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>
您基本上将表单发送到仅接受 GET 请求的 admin 功能。
您需要将表单发布到接受 POST 请求的 admin_post 功能。