【发布时间】:2019-03-24 22:41:25
【问题描述】:
views.py
def login(request):
password = request.POST.get('password')
mobile = request.POST.get('mobile')
user = authenticate(username=mobile, password=password)
if user is not None:
if user.is_active:
login(request, user)
return HttpResponseRedirect("/owner/?own=" + str(user.id))
login.html
$('.login-form').on('submit', function(event) {
event.preventDefault();
var form = $(this);
$.ajax({
url: '/ajax/login/',
type: "POST",
data: form.serialize()
success: function(data) {
});
});
我遇到了错误:
不允许的方法(POST):/ 不允许的方法:/ [20/Oct/2018 04:41:30]“POST / HTTP/1.1”405 0
【问题讨论】:
-
你能从你的
urls.py为你的login函数发布配置吗? -
当我手动发送帖子数据时,此代码有效。但使用 form.serialize() 它不起作用。
标签: python django python-3.x django-forms django-views