Django @login_required decorator error

I am running django 1.1rc. All my code works correctly using the django built-in development server; however, when I translate it into production using Apache mod_python, I get the following error in all of my views:

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

What can I find by causing this error?

Update: It is strange that I can access the account / login views, as well as the admin site just fine. I tried to remove the @login_required decorator in all my views and created the same type of exception.

Update2: So it seems like there is a problem with any view in my custom package: booster. Django.contrib works fine. I serve the application at http: // server_name / booster . However, the built-in auth login view is redirected to http: // server_name / accounts / login . Does this mean that it may be wrong?

Traceback:

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.

Thanks for your help, Pete.

+3
source share
3 answers

I had a problem with my apache configuration:

I changed this:

SetEnv DJANGO_SETTINGS_MODULE Settings

:

SetEnv DJANGO_SETTINGS_MODULE booster.settings

To solve the defualt auth authentication problem, I added parameter settings. LININ_URL

+1
source

, , .pyc .

0

phantom Django. , , . , , , - url - URL- URL- , . , Django URL-, .

0

Source: https://habr.com/ru/post/1713779/


All Articles