我正在运行django 1.1rc。我的所有代码都可以使用django的内置开发服务器正常工作;但是,当我使用Apache的mod_python将其移植到生产中时,我的所有视图都出现以下错误:
Caught an exception while rendering: Reverse for '<django.contrib.auth.decorators._CheckLogin
我可以找到导致此错误的内容吗?
更新 奇怪的是,我可以访问视图帐户/登录,也可以访问管理网站。我尝试在所有视图中删除@login_required装饰器,它会生成相同类型的异常。
UPDATE2: 因此,我的自定义程序包中的任何视图似乎都存在问题:助推器。 django.contrib工作正常。我正在http://server_name/booster投放该应用。但是,内置身份验证登录视图会重定向到http://server_name/accounts/login。这是否可以解决可能出现的问题?
回溯:
Environment:
Request Method: GET
Request URL: http://lghbb/booster/hospitalists/
Django Version: 1.1 rc 1
Python Version: 2.5.4
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'booster.core',
'booster.hospitalists']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')
Template error:
In template c:\booster\templates\hospitalists\my_patients.html, error at line 23
Caught an exception while rendering: Reverse for '<django.contrib.auth.decorators._CheckLogin object at 0x05016DD0>' with arguments '(7L,)' and keyword arguments '{}' not found.
13 : <th scope="col">Name</th>
14 : <th scope="col">DOB</th>
15 : <th scope="col">IC</th>
16 : <th scope="col">Type</th>
17 : <th scope="col">LOS</th>
18 : <th scope="col">PCP</th>
19 : <th scope="col">Service</th>
20 : </tr>
21 : </thead>
22 : <tbody>
23 : {% for patient in patients %}
24 : <tr class="{{ patient.gender }} select">
25 : <td>{{ patient.bed }}</td>
26 : <td>{{ patient.mr }}</td>
27 : <td>{{ patient.acct }}</td>
28 : <td><a href="{% url hospitalists.views.patient patient.id %}">{{ patient }}</a></td>
29 : <td>{{ patient.dob }}</td>
30 : <td class="{% if patient.infections.count %}infection{% endif %}">
31 : {% for infection in patient.infections.all %}
32 : {{ infection.short_name }}
33 : {% endfor %}
Traceback:
File "C:\Python25\Lib\site-packages\django\core\handlers\base.py" in get_response
92. response = callback(request, *callback_args, **callback_kwargs)
File "C:\Python25\Lib\site-packages\django\contrib\auth\decorators.py" in __call__
78. return self.view_func(request, *args, **kwargs)
File "c:/booster\hospitalists\views.py" in index
50. return render_to_response('hospitalists/my_patients.html', RequestContext(request, {'patients': patients, 'user' : request.user}))
File "C:\Python25\Lib\site-packages\django\shortcuts\__init__.py" in render_to_response
20. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "C:\Python25\Lib\site-packages\django\template\loader.py" in render_to_string
108. return t.render(context_instance)
File "C:\Python25\Lib\site-packages\django\template\__init__.py" in render
178. return self.nodelist.render(context)
File "C:\Python25\Lib\site-packages\django\template\__init__.py" in render
779. bits.append(self.render_node(node, context))
File "C:\Python25\Lib\site-packages\django\template\debug.py" in render_node
71. result = node.render(context)
File "C:\Python25\Lib\site-packages\django\template\loader_tags.py" in render
97. return compiled_parent.render(context)
File "C:\Python25\Lib\site-packages\django\template\__init__.py" in render
178. return self.nodelist.render(context)
File "C:\Python25\Lib\site-packages\django\template\__init__.py" in render
779. bits.append(self.render_node(node, context))
File "C:\Python25\Lib\site-packages\django\template\debug.py" in render_node
71. result = node.render(context)
File "C:\Python25\Lib\site-packages\django\template\loader_tags.py" in render
24. result = self.nodelist.render(context)
File "C:\Python25\Lib\site-packages\django\template\__init__.py" in render
779. bits.append(self.render_node(node, context))
File "C:\Python25\Lib\site-packages\django\template\debug.py" in render_node
81. raise wrapped
Exception Type: TemplateSyntaxError at /hospitalists/
Exception Value: Caught an exception while rendering: Reverse for '<django.contrib.auth.decorators._CheckLogin object at 0x05016DD0>' with arguments '(7L,)' and keyword arguments '{}' not found.
Original Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\django\template\debug.py", line 71, in render_node
result = node.render(context)
File "C:\Python25\Lib\site-packages\django\template\defaulttags.py", line 155, in render
nodelist.append(node.render(context))
File "C:\Python25\Lib\site-packages\django\template\defaulttags.py", line 382, in render
raise e
NoReverseMatch: Reverse for '<django.contrib.auth.decorators._CheckLogin object at 0x05016DD0>' with arguments '(7L,)' and keyword arguments '{}' not found.
感谢您的帮助, 皮特
答案 0 :(得分:1)
我的apache配置有问题:
我改变了这个:
SetEnv DJANGO_SETTINGS_MODULE设置
到此:
SetEnv DJANGO_SETTINGS_MODULE booster.settings
要解决defualt auth登录问题,我添加了设置settings.LOGIN_URL。
答案 1 :(得分:0)
稍微搜索了一下,听起来你可能需要删除服务器上的任何.pyc文件,让它们在第一次访问时重新编译它们。
答案 2 :(得分:0)
这是Django中非常常见的“幻像错误”。换句话说,您的代码中存在一个错误,但调试页面正在吐出一个误导性的异常。通常当我看到这个错误时,这是因为我在我的一个模板中的url标签中搞砸了一些东西 - 最常见的是拼写错误的url或者我尚未编写的视图的url。很多时候,Django调试页面甚至会突出显示错误来自的URL。