Python服务器issu

2024-04-24 12:02:41 发布

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

你能帮我解决这个误会吗。我有一些使用flask的项目,它可以在本地服务器127.0.0.1上完美地工作,但是当我将它移动到Web服务器(blue host)时,我的一些脚本给了我以下错误:

这里我有jQuery,Ajax响应来显示一个表而不重新加载页面:

<button class="myButton" id = "Lbutton">Load</button>

<script>

$("#Lbutton").click(function(){

  $.ajax({
          url: "/table,
          type: "get",
          data: {jsdata: $( "#select option:selected" ).text()},
          success: function(response) {
            $("#place_for_suggestions").html(response);

          },
          error: function(xhr) {
            // handle error
          }
        });

});

</script>

url:“/table,是Flask函数的链接:

@FlaskApp2.route('/table')
def table():

    modid = request.args.get('jsdata')
    return render_template('table.html')

但最后服务器给了我一个错误:

File does not exist: /home1/user/public_html/table

为什么直接链接的行动,服务器理解像一个文件的链接?你知道吗

所以,你的每一个动作

<form action="/sendemail" method="post">

服务器像链接一样理解并给出错误消息!你知道吗

我做错了什么?你知道吗


Tags: 服务器urlget链接responsehtml错误table
2条回答

解决了,我需要把完整的路径在行动和路由()装饰@应用程序路径“/…/模板/表格.html““

很可能需要将POST方法添加到route定义中。你知道吗

@FlaskApp2.route('/table')

变成:

@FlaskApp2.route('/table', methods=['GET', 'POST'])

请在此处查看文档: http://flask.pocoo.org/docs/0.12/quickstart/#http-methods

它有一个接受GET和POST HTTP方法的端点示例。你知道吗

另请查看相关问题:Flask example with POST

相关问题 更多 >