由于我正在创建的网站规模较小,我决定跳过 JSON,只创建一个 ajax 页面,该页面返回实际的 html 或单个单词来说明要做什么。代码好像有错误,因为在new_user_pass = new_user(request.POST)
服务器突然返回500 (INTERNAL SERVER ERROR)
网站检查用户之前是否登录过,然后做出决定:如果有,则在创建会话后重定向到主页(尚未编码)。如果他们没有:返回一个告诉 JQuery 向他们询问其他信息的单词。如果某处出现错误,它应该到达返回错误的文件末尾(尚未完全编码)。
这是 forms.py 文件:
class log_in(forms.Form):
username = forms.EmailField()
password = forms.PasswordInput()
class new_user(forms.Form):
username = forms.EmailField()
password = forms.PasswordInput()
password2 = forms.PasswordInput()
pen_name = forms.CharField(max_length=30)
views.py 文件:
def user_log_in(request):
#add stuff for ajax request
user_pass = log_in(request.POST)
er = []
if user_pass.is_valid():
cleaned_info = user_pass.cleaned_data
user_object = User.objects.filter(email = cleaned_info['username'])
if user_object.exists():
#create session
return HttpResponseRedirect('/home')
else:
new_user_pass = new_user(request.POST)#where bug is
cleaned_info = new_user_pass.cleaned_data
if new_user_pass.is_valid():
if cleaned_info['password'] == cleaned_info['password2']:
new_user = User(activated = 0, email = cleaned_info['username'], pen_name = cleaned_info['pen_name'], password = cleaned_info['password'])
new_user.save()
msg = ""
if send_mail('Activate', msg, '*******', [cleaned_info['username']], fail_silently=False):
return HttpResponse('e_act')
else:
er.append("Error Sending Email")
else:
er.append('Passwords are not the same')
elif cleaned_info['TN']:
for e in new_user_pass.errors:
er.append(e)
else:
return HttpResponse('n_usr')
return HttpResponse('SOS')
而且,虽然我不认为错误在这里,但 Jquery 函数:n_usr = false;
function log_in () {
//add code to check if it's the wrong usr, pass, correct, or if they've never logged in before.
//code to reveal section
编辑:Django给出了错误new_user' referenced before assignment