繁体   English   中英

django 保存数据库工作,但返回 500 错误?

[英]django saving database works, but returns 500 error?

我很困惑。 我承认自己是新手,但这应该可行。 请参阅下面的代码。 如所写,.save() 行已被注释掉。

当我运行它时,一切正常,如预期的那样,未保存数据并返回“g”。

如果我取消注释 the.save() 行

保存表条目,但返回 500 错误。

非常感谢任何帮助。

def register_new_poll(request):
new_poll_name = request.POST.get('n','d')
new_poll_password = request.POST.get('w','')
new_poll_port = request.POST.get('p','d')
new_poll_ip = request.POST.get('i','d')
new_poll_duration = request.POST.get('d','d')
if new_poll_name != 'd' and new_poll_port != 'd' and new_poll_ip != 'd' and new_poll_duration != 'd':
    try:
        poll.objects.get(name=new_poll_name)
        return HttpResponse("Already In Database");
    except poll.DoesNotExist:
        new_poll = poll(name=new_poll_name,ip=new_poll_ip,port=new_poll_port,password=new_poll_password,duration=new_poll_duration,last_contact_time=datetime.now(),users_at_last_contact=0)
        write_poll_list()
        #new_poll.save()
        return HttpResponse("g");
    except:
        return HttpResponse("b");
        pass
else:
    return HttpResponse("b");

ippoll中的一个字段。 请参阅粘贴的第 12 行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM