Flask POST表单错误“不允许使用方法”

问题描述 投票:0回答:1

我试图将一个参数从文本输入形式传递到我的app.py中,但出现以下错误消息:

不允许的方法所请求的URL不允许使用此方法。

这里是我的app.py配置:

@main_blueprint.route('/reports/daily_reports') 
def downloadsss():
    if request.method == 'GET':
    daily_path = "./app/templates/Repo/DailyReports"
    daily_listOfFiles = os.listdir(daily_path)
    return render_template('main/DailyReports.html', len = len(daily_listOfFiles), daily_listOfFiles 
    = daily_listOfFiles)
    elif request.method == 'POST' and 'download' in request.form:
    download = request.form.get('download')
    path = 'C:/Users/Ahmed Mustafa/FlaskProject/app/templates/Repo/DailyReports/' + download
    return send_file(path, as_attachment=True)

以下是我的HTML代码:

{% extends "main/main_base.html" %}  {# main/main_base.html extends layout.html #}
{% block content %}
<head>
<style>
 body {background-color: powderblue;}
 h1   {color: blue;}
 p    {color: red;}
 h2   {color: black; font-size: 20px;  font-family: "Lucida Sans Unicode", "Lucida Grande", sans- 
 serif;}
 th   {vertical-align: top; align-items: center;}
 table{align-items: center; }
 </style>
 <div class="jumbotron text-center">
    <p><font size="6">This page is to show the Daily Reports list!</font></p>

<form method="post">
<input type="text" name="download" />
<input type="submit" value="Download" />
</form>

    <!-- For loop logic of jinja template -->
        <li class="list-group-item"><font size="6">
        {% print('Total Number of Reports:'), len %}</font></li>
        <div align="left" >         
        {%for i in range(0, len)%}
        {% print('Report Number:'),[i+1] %}
        <li class="list-group-item">
        <a href="file:///C:/Users/Ahmed 
 Mustafa/FlaskProject/app/templates/static/DailyReports/{{daily_listOfFiles[i]}}"> 
 {{daily_listOfFiles[i]}}</a>
        <p>&nbsp;</p>
        <h2></h2>
        </li> 
        {% endfor %}
    </div>
 </div>
{% endblock %}
python html forms flask post
1个回答
1
投票
@main_blueprint.route('/reports/daily_reports', methods=('GET', 'POST'))
© www.soinside.com 2019 - 2024. All rights reserved.