簡體   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