Python 405创建用户时post请求中不允许出现方法错误
我正在制作一个用户注册表单,其中我提出了一个post请求,以获取打印表单中的用户输入数据,但405方法不允许出现导致问题的错误。我是个新手,所以我不知道出了什么问题 控制器类:Python 405创建用户时post请求中不允许出现方法错误,python,pycharm,python-3.6,web.py,Python,Pycharm,Python 3.6,Web.py,我正在制作一个用户注册表单,其中我提出了一个post请求,以获取打印表单中的用户输入数据,但405方法不允许出现导致问题的错误。我是个新手,所以我不知道出了什么问题 控制器类: import web from Models import RegisterModel urls = ( "/", "Home", "/register", "Register", "/post", "PostRegistration", ) render = web.template.rend
import web
from Models import RegisterModel
urls = (
"/", "Home",
"/register", "Register",
"/post", "PostRegistration",
)
render = web.template.render("Views/Templates", base="MainLayout")
app = web.application(urls, globals())
# Classes/routes
class Home:
def GET(self):
return render.Home()
class Register:
def GET(self):
return render.Register()
class PostRegistration:
def POST(self):
data = web.input()
reg_model = RegisterModel.RegisterModelCls()
reg_model.insert_user(data)
return data.username
if __name__ == "__main__":
app.run()
登记表格:
<div class="container">
<h2>Register Account</h2>
<br /><br />
<form>
<div class="form-group label-static is-empty">
<label for="username" class="control-label">Username</label>
<input id="username" name="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" name="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" name="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" name="password" class="form-control"
type="password" placeholder="Make a password" />
</div>
<a type="submit" href="/post" class="btn btn-info waves-effect"
>Submit <div class="ripple-container"></div></a>
</form>
</div>
错误:
http://0.0.0.0:8080/
127.0.0.1:64395 - - [06/Sep/2019 00:19:16] "HTTP/1.1 GET /post" - 405
Method Not Allowed
你把“得到”和“发布”混在一起了 该错误表示您正在url'/post'上执行“获取”操作 py获取URL并在URL列表中查找,并标识由类“PostRegistration”处理的URL“/post” 因此,web.py在类PostRegistration上调用GET方法,该方法不存在,或者,正如web.py所说的“方法不允许”
若要克服此问题,请使用POST操作(如@Barmar所建议的),或者将PostRegistration.POST(self)重命名为PostRegistration.get(self)。使用
默认值为method=“get”
@Bamar仍面临相同的错误。
http://0.0.0.0:8080/
127.0.0.1:64395 - - [06/Sep/2019 00:19:16] "HTTP/1.1 GET /post" - 405
Method Not Allowed