问题描述
我最近开始学习 Flask。我正在尝试构建一个简单的注册表单,但出现 Method not allowed 错误。我花了一些时间在这里和谷歌上阅读解决方案,但没有任何成功。我希望有人能帮我解决这个问题。
<form method="POST" id="registerform">
<div class="form-group">
<small><label for="email">Email address</label></small>
<input type="email" class="form-control" id="email" aria-describedby="emailHelp" placeholder="Enter email">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password">
</div>
<div class="form-group">
<label for="password2">Repeat Password</label>
<input type="password" class="form-control" id="password2" placeholder="Repeat Password">
</div>
<button type="submit" class="btn btn-primary">Register</button>
</form>
</div>
<div class="col"></div>
</div>
</div>
$(document).ready(function() {
$("#registerform").on('submit',function(e) {
e.preventDefault();
$.ajax({
method: "POST",url: "/register",dataType: "html",data: $("#registerform").serialize(),success: function(data) {
if (data == 'Registration succesful,please check your mail to activate account') {
$('#msg').html('<div class="alert alert-success" role="alert" id="msg2">' + data + '</div>');
} else {
$('#msg').html('<div class="alert alert-success" role="alert" id="msg2">' + data + '</div>');
}
}
});
});
});
@app.route('/register',methods =['GET','POST'])
def register():
msg = ''
if request.method == 'POST' and 'password' in request.form and 'email' in request.form and 'password2' in request.form:
password = request.form['password']
password2 = request.form['password2']
email = request.form['email']
#sql QUEIRES AND OTHER STUFFS HERE#
msg = 'Registration succesful,please check your mail to activate account.'
else:
msg = 'Please fill out the form !'
return msg
先谢谢你!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)