Python Django登录时出现http 500错误

Python Django登录时出现http 500错误,python,django,apache,authentication,http-error,Python,Django,Apache,Authentication,Http Error,因此,我正在为我的Django应用程序创建一个登录系统。它在我的开发端工作得非常好,但是在prod中,如果我提交了正确的用户名和密码,它就不工作了(它给出了500个错误)。我不确定我在views.py中指出的两行中的哪一行是问题所在,但我认为这一定是这两行中的一行,因为如果我输入了一个错误的用户,那么即使在prod中,我也可以很好地重定向 我的dev和prod端的代码完全相同——唯一的区别在于设置 DEBUG = True ALLOWED_HOSTS = [] ^以上是我的开发人员

因此,我正在为我的Django应用程序创建一个登录系统。它在我的开发端工作得非常好,但是在prod中,如果我提交了正确的用户名和密码,它就不工作了(它给出了500个错误)。我不确定我在views.py中指出的两行中的哪一行是问题所在,但我认为这一定是这两行中的一行,因为如果我输入了一个错误的用户,那么即使在prod中,我也可以很好地重定向

我的dev和prod端的代码完全相同——唯一的区别在于设置

   DEBUG = True
   ALLOWED_HOSTS = []
^以上是我的开发人员设置,但in-prod-DEBUG为False,并且已使用适当的名称填写了允许的\u主机

在views.py中:

def user_login(request):
if request.method == "POST":
    username = request.POST['username']
    password = request.POST['password']
    user = authenticate(username=username, password=password)
    if user is not None and user.is_active:
        login(request=request, user=user) <- This line
        return render(request, 'site/homepage.html') <- Or this line
    else:
        return render(request, 'site/login.html', {'incorrect': True})
else:
    return render(request, 'site/login.html', {})
def用户登录(请求):
如果request.method==“POST”:
username=request.POST['username']
password=request.POST['password']
用户=验证(用户名=用户名,密码=密码)
如果user不是None且user.u处于活动状态:

登录(request=request,user=user)在表单中,
action
属性没有任何值,因此您不向视图发送任何内容。它应该是




如果您的登录url名称是“我的服务器”中测试的登录名,请告诉我们新错误

view.py:

def login_user(request):
    if request.method == "POST":
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if user is not None and user.is_active:
            login(request, user)
            return HttpResponseRedirect('/')
        else:
            return render(request, 'login/auth.html', {'incorrect': True})
    else:
        return render(request, 'login/auth.html', {})

哪条是错误消息?Web服务器日志显示的内容,例如:sudo tail/var/log/apache2/error。log@AviahLaor[2016年2月8日星期一11:21:54.582105][mpm_事件:通知][pid 1068:tid 307405880]AH00491:SIGTERM,关闭[2016年2月8日星期一11:21:55.659160][mpm_事件:通知][pid 1439:tid 3074177664]AH00489:Apache/2.4.7(Ubuntu)mod_wsgi/3.4 Python/2.7.6 configured--恢复正常操作[Mon Feb 08 11:21:55.659284 2016][core:notice][pid 1439:tid 3074177664]AH00094:命令行:'/usr/sbin/apache2'只要我重新启动Apache服务器,你能设置DEBUG=True来捕获异常吗?@AviahLaor If DEBUG=True(就像在我的开发代码中一样),也不例外。代码按预期工作,重定向顺利进行。这就是这个错误的奇怪之处。注意,仍然会出现一个普通的500错误,并且任何日志中都没有出现任何错误。可能与collectstatics或:有关,并尝试启用调试模式,如ur dev系统,以显示错误。@user2151557您确定了这个500错误的问题了吗。如果是,是什么?我似乎也有类似的问题。
<form id="login_form" method="post" action=".">
<form id="login_form" action="{% url 'login' %}" method="post">
def login_user(request):
    if request.method == "POST":
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if user is not None and user.is_active:
            login(request, user)
            return HttpResponseRedirect('/')
        else:
            return render(request, 'login/auth.html', {'incorrect': True})
    else:
        return render(request, 'login/auth.html', {})