在按钮onclick location.href中使用Flask url_重定向将导致“不允许使用方法”` 我在一些基本形式的中间框中,我碰到一个意想不到的 405的方法,不允许

在按钮onclick location.href中使用Flask url_重定向将导致“不允许使用方法”` 我在一些基本形式的中间框中,我碰到一个意想不到的 405的方法,不允许,flask,jinja2,Flask,Jinja2,基本上我在jinja模板中有一些html,看起来像 <!--Select File Y--> <tr> <td>File Y</td> <td>{{form.pathY }}</td> <td><input type=file name=browse ></td> <td><button onclick="window.location.h

基本上我在jinja模板中有一些html,看起来像

<!--Select File Y-->
<tr>
    <td>File Y</td>
    <td>{{form.pathY }}</td>
    <td><input type=file name=browse ></td>
    <td><button onclick="window.location.href='{{ url_for( 'dataTablePage' , table='Y' ) }}';">Display Table Y</button></td>
</tr>
<tr>
    <td/>
    <td/>
    <td/>
    <td><a href="{{ url_for( 'dataTablePage' , table='Merged' ) }}">View Merged Data</a></td>
</tr>

这是HTML的一个问题,实际上:

缺少的默认值是提交按钮状态

由于您没有指定按钮的类型,它只是尝试提交表单,这导致405问题

将您的按钮类型更改为“按钮”,它应能按预期工作:

显示表Y

这是HTML的一个问题,实际上:

缺少的默认值是提交按钮状态

由于您没有指定按钮的类型,它只是尝试提交表单,这导致405问题

将您的按钮类型更改为“按钮”,它应能按预期工作:

显示表Y

Solid,甚至没有意识到按钮had的类型是
submit
,现在发生的事情很有意义。Solid,甚至没有意识到按钮had的类型是
submit
,现在发生的事情很有意义。
@app.route('/DataTable/<table>/')
def dataTablePage(table) :
    """
    Takes the user to the Table View corresponding to the given table parameter
    """
    table == "X" :
        dfTable = DataFrame( data = {"X1":[1,2,3] , "X2":[2,3,4]} ) 
    elif table == "Y" :
        dfTable = DataFrame( data = {"Y1":[1,2,3,4,5] , "Y2":[2,3,4,5,6]} ) 
    elif table == "Merged" :
        dfTable = DataFrame( data = {"M1":[1,2] , "M2":[2,3]} ) 
    else :
        redirect( url_for('error') )

    return render_template( 'dataTable.html' , filePath="x.csv" , headers=dfTable.columns.values.tolist() , table=dfTable.iterrows() )