首页 > 解决方案 > request.form.get 和 request.args.get 在烧瓶表单数据中不返回任何内容

问题描述

我试图通过单击“更多照片”的链接来获取 dirname 值。这是表单 HTML。

<form action="/single" method="GET">
   <input type="text" name="dirname" value="{{ dir_name }}" style="display:none">
   <a href="single.html" class="btn btn-outline-white py-2 px-4">More Photos</a>
</form>

这是烧瓶中获取此数据的函数。

@app.route('/single.html', methods=['GET', 'POST'])
@app.route('/single', methods=['GET', 'POST'])
def single():
    print(request.method)
    if request.method == "GET":
        dir_name = request.args.get("dirname")
        print("Dir name is ", dir_name)
        main_path = join("static/Downloaded_images", dir_name)
        images_paths, names = get_paths(main_path)
    return render_template('single.html', images_paths_names=zip(images_paths,names))

这是我单击更多照片时的 URL。http://127.0.0.1:5000/single.html

如何在 URL 中传递 dirname 以使其发挥作用?目前它显示我没有。

标签: pythonhtmlflask

解决方案


推荐阅读