weixin_33699914 2018-11-29 20:35 采纳率: 0%
浏览 558

为什么提交表单时收到了404错误?

我在提交表单时收到了404错误提示。我试图通过该表格上传并提交.png,按理来说服务器(Python,Flask)应该能够使用它才对......有人知道我的问题出在哪里吗?

AJAX:

<script>
    document.getElementById("exampleFormControlFile1").onchange = function() {
    console.log("Came here");
    $.ajax({
        url:'/uploadPNG/',
        type:'post',
        data:$('#exampleFormControlFile1').serialize(),
        success:function(){
            console.log("Came here");

            }
});
};
</script>

HTML:

<form method="POST" id="form">
    <div class="form-group">
    <label for="exampleFormControlFile1">Upload your .png template</label>
    <input type="file" class="form-control-file" id="exampleFormControlFile1">
    </div>
</form>

SERVER:

@app.route('/uploadPNG/', methods=['POST'])
def upload():
    if request.method == 'POST':
        print("Got png")
    return "gotcha"

提前感谢你的解答!

  • 写回答

1条回答 默认 最新

  • weixin_33688840 2018-12-01 10:32
    关注

    I just figured out the issue. Gonna answer my own post here so that others may have it easier. A magic wizard once told me to always check the documentation. http://flask.pocoo.org/docs/1.0/patterns/fileuploads/ Then I had to adjust the AJAX call like here: 'append' called on an object that does not implement interface FormData And then i had to add the name "file" to the input tag.

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)