请求的URL不允许使用方法

2024-10-04 11:31:20 发布

您现在位置:Python中文网/ 问答频道 /正文

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页面,当我给出输入时,得到一个错误“Method is not allowed for the required URL”

^{pr2}$

Tags: thefromimportappflaskfordbreturn
1条回答
网友
1楼 · 发布于 2024-10-04 11:31:20

将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>

基本上,发送表单的功能只接受您的请求。在

您需要将您的表单发布到管理帖子功能,该功能接受post请求。在

相关问题 更多 >