Does raising 404 makes use django's auth system?

29 views
Skip to first unread message

Filipe

unread,
Sep 25, 2006, 5:14:09 AM9/25/06
to Django users
Raising an HTTP 404 while having DEBUG = False in settings.py makes a
webpage show up with nothing but a traceback with the following error:

[...]
File
"/usr/lib/python2.4/site-packages/django/core/context_processors.py",
line 17, in auth
return {

AttributeError: 'ModPythonRequest' object has no attribute 'user'

Is Django's authentication system needed in order to raise 404s? I had
a look to context_processors.py and got convinced that the 'user'
attribute mentioned has something to do with the auth system.

The website I'm developing doesn't use a database actually, so I'm not
using the ORM and the features that depend on it (the auth system is
one of them, right?).


thanks in advance,
Filipe

Malcolm Tredinnick

unread,
Sep 25, 2006, 5:55:53 AM9/25/06
to django...@googlegroups.com
On Mon, 2006-09-25 at 09:14 +0000, Filipe wrote:
> Raising an HTTP 404 while having DEBUG = False in settings.py makes a
> webpage show up with nothing but a traceback with the following error:
>
> [...]
> File
> "/usr/lib/python2.4/site-packages/django/core/context_processors.py",
> line 17, in auth
> return {
>
> AttributeError: 'ModPythonRequest' object has no attribute 'user'

Can you paste the full traceback for this, please? A few people have
reported this on and off; time to track down what's going on.

Thanks,
Malcolm


Filipe

unread,
Sep 25, 2006, 6:28:04 AM9/25/06
to Django users
I'm running django on linux, and using the latest trunk.
When I got this particular traceback I was using mod_python, but the
same happens using the built-in webserver (only, "ModPythonRequest" is
replaced with "WSGIRequest" in that case).


The full traceback follows:

________________________________________________________________
Mod_python error: "PythonHandler django.core.handlers.modpython"

Traceback (most recent call last):

File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line
299, in HandlerDispatch
result = object(req)

File
"/usr/lib/python2.4/site-packages/django/core/handlers/modpython.py",
line 183, in handler
return ModPythonHandler()(req)

File
"/usr/lib/python2.4/site-packages/django/core/handlers/modpython.py",
line 153, in __call__
response = self.get_response(req.uri, request)

File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py",
line 95, in get_response
return callback(request, **param_dict)

File "/usr/lib/python2.4/site-packages/django/views/defaults.py",
line 79, in page_not_found
return http.HttpResponseNotFound(t.render(RequestContext(request,
{'request_path': request.path})))

File "/usr/lib/python2.4/site-packages/django/template/context.py",
line 97, in __init__
self.update(processor(request))

File
"/usr/lib/python2.4/site-packages/django/core/context_processors.py",
line 17, in auth
return {

AttributeError: 'ModPythonRequest' object has no attribute 'user'

________________________________________________________________

thanks!
Filipe

Malcolm Tredinnick

unread,
Sep 25, 2006, 6:47:12 AM9/25/06
to django...@googlegroups.com

OK, this is the problem line: RequestContext tries to access "user". The
reason we are using RequestContext is because of ticket #688 (which is
quite a reasonable change). However, we have to conditionally avoid this
user requirement.

>
> File "/usr/lib/python2.4/site-packages/django/template/context.py",
> line 97, in __init__
> self.update(processor(request))
>
> File
> "/usr/lib/python2.4/site-packages/django/core/context_processors.py",
> line 17, in auth
> return {
>
> AttributeError: 'ModPythonRequest' object has no attribute 'user'


I'm a bit tired right now, so I'm stopping for the evening, but I'll
have a look at this tomorrow.

Regards,
Malcolm


Michael Radziej

unread,
Sep 25, 2006, 7:16:13 AM9/25/06
to django...@googlegroups.com
Malcolm Tredinnick schrieb:

> OK, this is the problem line: RequestContext tries to access "user". The
> reason we are using RequestContext is because of ticket #688 (which is
> quite a reasonable change). However, we have to conditionally avoid this
> user requirement.

Well, as a work around, if you don't use a database, you should
remove
"django.core.context_processors.auth",
from TEMPLATE_CONTEXT_PROCESSORS in settings.py

This setting makes some of the default views trigger a context
processor that requires the session middleware. Since this
middleware needs a database, you've probably switched it off.

Michael

Filipe

unread,
Sep 26, 2006, 6:31:09 AM9/26/06
to Django users
thanks

Filipe

unread,
Sep 26, 2006, 6:35:57 AM9/26/06
to Django users
Michael Radziej wrote:
> Well, as a work around, if you don't use a database, you should
> remove
> "django.core.context_processors.auth",
> from TEMPLATE_CONTEXT_PROCESSORS in settings.py

hmm, I don't have that in settings.py. However, I do have:

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'myproject.main',
)

I tried removing the reference to 'django.contrib.auth' and the error
remained, though.

Michael Radziej

unread,
Sep 26, 2006, 7:15:54 AM9/26/06
to django...@googlegroups.com
Filipe schrieb:

> Michael Radziej wrote:
>> Well, as a work around, if you don't use a database, you should
>> remove
>> "django.core.context_processors.auth",
>> from TEMPLATE_CONTEXT_PROCESSORS in settings.py
>
> hmm, I don't have that in settings.py. However, I do have:

Ah, it's there by default even if you don't have any settings for
it. See the code for django.conf.global_settings.

You need to copy the specific settings from
django.conf.global_settings to your settings module, it is:

TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
# 'django.core.context_processors.request',
)

Then comment out context_processors.auth (or however you want to
deal with it), and get:

TEMPLATE_CONTEXT_PROCESSORS = (
# 'django.core.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
# 'django.core.context_processors.request',
)


I'm not sure if you run into other problems then, but let's deal
with those afterwards.

Michael

Filipe

unread,
Sep 27, 2006, 4:21:54 AM9/27/06
to Django users
Michael Radziej wrote:
> You need to copy the specific settings from
> django.conf.global_settings to your settings module, it is:
>
> TEMPLATE_CONTEXT_PROCESSORS = (
> 'django.core.context_processors.auth',
> 'django.core.context_processors.debug',
> 'django.core.context_processors.i18n',
> # 'django.core.context_processors.request',
> )
>
> Then comment out context_processors.auth (or however you want to
> deal with it), and get:
>
> TEMPLATE_CONTEXT_PROCESSORS = (
> # 'django.core.context_processors.auth',
> 'django.core.context_processors.debug',
> 'django.core.context_processors.i18n',
> # 'django.core.context_processors.request',
> )
>
>
> I'm not sure if you run into other problems then, but let's deal
> with those afterwards.

works perfectly. Haven't detected any side effect yet.
thanks.

Michael Radziej

unread,
Sep 27, 2006, 5:44:35 AM9/27/06
to django...@googlegroups.com
Filipe schrieb:

> works perfectly. Haven't detected any side effect yet.
> thanks.

Good to know! Perhaps you should file a ticket that
context_processors.auth should behave better when there's no
session. If you do, please include a link to this thread.

Michael

Reply all
Reply to author
Forward
0 new messages