由于Django应用程序中的登录模板导致的内部服务器错误

时间:2014-01-15 11:49:23

标签: python django login wsgi internal-server-error

我暴露了我的问题。我正在开发一个django应用程序,这个应用程序包含一个登录页面。该应用程序设置为WSGI应用程序。好吧,有了这个,应用程序工作到今天。昨天,一切都很顺利,但后来我做了一个apt-get更新和升级。之后,应用程序崩溃了,但仅在加载登录页面时。应用程序的其余部分工作正常,但是当我注销时,它无法加载登录模板。我不知道会出现什么问题,因为最奇怪的是,在应用程序崩溃之前,我做了应用程序的备份,这个备份工作正常,甚至是登录页面。但我希望恢复原始应用,因为我在备份之前做了一些更改。

这是我的错误日志:

[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98] mod_wsgi (pid=23556): Exception occurred processing WSGI script '/home/wtelecom/teams/app.wsgi'.
[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98] Traceback (most recent call last):
[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98]   File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 241, in __call__
[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98]     response = self.get_response(request)
[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98]   File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 179, in get_response
[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98]   File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 228, in handle_uncaught_exception
[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98]     return callback(request, **param_dict)
[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98]   File "/usr/local/lib/python2.6/dist-packages/django/utils/decorators.py", line 91, in _wrapped_view
[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98]     response = view_func(request, *args, **kwargs)
[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98]   File "/usr/local/lib/python2.6/dist-packages/django/views/defaults.py", line 32, in server_error
[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98]     t = loader.get_template(template_name) # You need to create a 500.html template.
[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98]   File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py", line 145, in get_template
[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98]     template, origin = find_template(template_name)
[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98]   File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py", line 138, in find_template
[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98]     raise TemplateDoesNotExist(name)
[Wed Jan 15 12:10:58 2014] [error] [client 192.168.1.98] TemplateDoesNotExist: 500.html
[Wed Jan 15 12:10:58 2014] [debug] mod_deflate.c(615): [client 192.168.1.98] Zlib: Compressed 616 to 381 : URL /accounts/login/, referer: http://192.168.2.10/accounts/login/

我已经破解了urls.py和login.html,它们与备份应用程序类似:

# -*- encoding: utf-8 -*-
from django.conf import settings
from django.conf.urls.defaults import *

from django.contrib import admin
from django.contrib.auth.views import login
from django.views.generic.simple import direct_to_template
from webadmin.views import user_logout
from teams_test.views import index
admin.autodiscover()

urlpatterns = []
if settings.DEBUG:
    urlpatterns += patterns('', 
        (r'^media/(?P<path>.*)$', 'django.views.static.serve',
                {'document_root': settings.MEDIA_ROOT}),
    )
urlpatterns += patterns('',
    (r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'webadmin/login.html'}),
    url(r'^accounts/logout/$', user_logout, name="user_logout"),
    (r'^admin/', include(admin.site.urls)),
    (r'^sentry/', include('sentry.urls')),
    (r'^webadmin/', include('webadmin.urls')),
    (r'^project/', include('teams_test.urls')),
    (r'^video/', include('video.urls')),
    url(r'', index, name='index'),

)

的login.html:

{% extends "layouts/app.html" %}
{% load i18n %}

{% block title %}{% trans "User registration" %}{% endblock %}
{% block robots %}noindex,nofollow{% endblock %}

{% block extrajs %}
<script type="text/javascript">
    $(function() {
        $("input#id_username").focus();
        $("input[type='text'], input[type='password']").addClass("text");
});
</script>
{% endblock %}

{% block page %}

{% if form.errors %}
<p>{% trans "Your username and password didn't match. Please try again." %}</p>
{% endif %}
<div id="page" class="container">
    <div class="header prepend-1 span-20 append-2 last whiteboard">

<form method="post" action="{% url django.contrib.auth.views.login %}">
{% csrf_token %}
<table>
<tr>
    <td>{{ form.username.label_tag }}</td>
    <td>{{ form.username }}</td>
</tr>
<tr>
    <td>{{ form.password.label_tag }}</td>
    <td>{{ form.password }}</td>
</tr>
</table>

<input type="submit" value="{% trans "login" %}" />
<input type="hidden" name="next" value="{% url list_ongoing_phases %}" />
</form>
</div></div>

{% endblock %}

我很感激你能给我的任何帮助。我非常坚持这一点。抱歉我的英语,我不是母语。

提前致谢。

1 个答案:

答案 0 :(得分:0)

[Wed Jan 15 12:10:58 2014] [错误] [client 192.168.1.98] TemplateDoesNotExist:500.html

使用debug = False运行时需要一个名为500.html的模板,因此django可能会显示错误。