繁体   English   中英

如何使用webpy在python中修复500内部服务器错误?

[英]How fix 500 Internal Server Error in python using webpy?

当我加入代码的某些行我scripty.js文件并以我main.py我有一些问题,我的POST功能:

scripty.js:

 var form = $('#register-form').serialize();
    $.ajax({
        url: '/postreg',
        type: 'POST',
        data: form,
        success: function (res) {
            res.preventDefault()
            console.log("done");

        }
    });

和main.py:

class PostRegistration:
    def POST(self):
        data = web.input()
        return data.username

我的结果是:

127.0.0.1:55126 - - [01/Apr/2019 18:37:25] "HTTP/1.1 GET /static/js/ripples.min.js.map" - 200 

Traceback (most recent call last):
  File "/home/amir/.local/lib/python3.6/site-packages/web/utils.py", line 70, in __getattr__
    return self[key]
KeyError: 'username'


During handling of the above exception, another exception occurred:


Traceback (most recent call last):
  File "/home/amir/.local/lib/python3.6/site-packages/web/application.py", line 257, in process
    return self.handle()

  File "/home/amir/.local/lib/python3.6/site-packages/web/application.py", line 248, in handle

    return self._delegate(fn, self.fvars, args)
  File "/home/amir/.local/lib/python3.6/site-packages/web/application.py", line 488, in _delegate
    return handle_class(cls)

  File "/home/amir/.local/lib/python3.6/site-packages/web/application.py", line 466, in handle_class
    return tocall(*args)

  File "/home/amir/PycharmProjects/SocialWeb/Controller.py", line 27, in POST
    return data.username
  File "/home/amir/.local/lib/python3.6/site-packages/web/utils.py", line 72, in __getattr__
    raise AttributeError(k)
AttributeError: 'username'

127.0.0.1:55124 - - [01/Apr/2019 18:37:30] "HTTP/1.1 POST /postreg" - 500 Internal Server Error

query serialize使用输入name属性,而不是id属性。 您的html代码段似乎不包含name="username"

来自jquery文档:

注意:只有“成功控件”被序列化为字符串。 没有提交按钮值被序列化,因为表单未使用按钮提交。 要使表单元素的值包含在序列化字符串中,该元素必须具有name属性。 复选框和单选按钮(“radio”或“checkbox”类型的输入)中的值仅在选中时才包括在内。 文件选择元素中的数据未序列化。

这是我的注册表格HTML文件

<div class="container">
    <h2>Register Account</h2>

    <br /><br />

    <form id="register-form">

        <div class="form-group  label-static is-empty">
            <label for="username" class="control-label">Username</label>
            <input  id="username" class="form-control" type="text" placeholder="Choose a Username">
        </div>

        <div class="form-group  label-static is-empty">
            <label for="display_name" class="control-label">Full Name</label>
            <input id="display_name" class="form-control" type="text" placeholder="Enter your full name">

        </div>
        <div class="form-group  label-static is-empty">
            <label for="email" class="control-label">Email Address</label>
            <input id="email" class="form-control" type="email" placeholder="Enter your email">

        </div>
        <div class="form-group  label-static is-empty">
            <label for="password" class="control-label">Password</label>
            <input id="password" class="form-control" type="password" placeholder="Choose a password">

        </div>

        <button type="submit" class="btn btn-raised btn-info ">Submit <div class="ripple-container"></div> </button>
    </form>
</div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM