gpt4 book ai didi

python - django @login_required 装饰器错误

转载 作者:行者123 更新时间:2023-11-28 18:55:57 25 4
gpt4 key购买 nike

我正在运行 django 1.1rc。使用 Django 的内置开发服务器,我的所有代码都能正常工作;但是,当我使用 Apache 的 mod_python 将其投入生产时,我在所有 View 中都收到以下错误:

 Caught an exception while rendering: Reverse for '<django.contrib.auth.decorators._CheckLogin

我应该寻找什么导致此错误?

更新:奇怪的是我可以访问 View 帐户/登录名以及管理站点。我尝试删除所有 View 上的 @login_required 装饰器,它会生成相同类型的异常。

更新 2:所以我的自定义包中的任何 View 似乎都存在问题:booster。 django.contrib 工作正常。我在 http://server_name/booster 提供应用程序服务.但是,内置的 auth 登录 View 重定向到 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 }} &nbsp;


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.

感谢您的帮助,皮特

最佳答案

在谷歌上搜索了一下,听起来您可能需要删除服务器上的所有 .pyc 文件,并让它在第一次访问它们时重新编译它们。

关于python - django @login_required 装饰器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1195432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com