[英]Method is not allowed for the requested URL
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:我没有在此处发布完整的代码,因为它没有偏离我所面临的问题。 我可以打开/ 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>
将您的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函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.