Когда я добавил строку кода в мой файл 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