tags:

views:

637

answers:

3

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

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

What might I look for that's causing this error?

Update: What's strange is that I can access the views account/login and also the admin site just fine. I tried removing the @login_required decorator on all of my views and it generates the same type of exception.

Update2: So it seems like there is a problem with any view in my custom package: booster. The django.contrib works fine. I'm serving the app at http://server_name/booster. However, the built-in auth login view redirects to http://server_name/accounts/login. Does this give a clue to what 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

A: 

Having googled on this a bit, it sounds like you may need to delete any .pyc files on the server and let it recompile them the first time they're accessed.

R. Bemrose
That's not it unfortunately.
slypete
The other thing that comes to mind is to make sure Production is running Python 2.4 or newer. However, I just assumed that wasn't the problem (and deleted the answer I'd written that said that).
R. Bemrose
+1  A: 

I had a problem with my apache configuration:

I changed this:

SetEnv DJANGO_SETTINGS_MODULE settings

to this:

SetEnv DJANGO_SETTINGS_MODULE booster.settings

To solve the defualt auth login problem, I added the setting settings.LOGIN_URL.

slypete
A: 

This is a pretty common 'phantom error' in Django. In other words, there's a bug in your code, but the debug page is spitting back a misleading exception. Usually when I see this error, it's because I've screwed something up in a url tag in one of my templates - most commonly a misspelled url or a url for a view that I haven't written yet. A lot of the times, the Django debug page will even highlight the url that the error is coming from.

jcp