views:

49

answers:

1

Hi,

I'm using django with apache mod_python. I authenticate users via the basic auth handler (django.contrib.auth.handlers.modpython) [1]. My views get only an instance of AnonymousUser passed in request.user. What am I doing wrong?

[1]: it's an API that is https only, so it shouldn't be a security problem.

A: 

I figured it out by myself now: In case you need to do something user specific in a view that is exposed via basic authentication don't let apache handle authentication for you.

If you want HTTP Basic Authentication for all your views write (or get) a Middleware. If, like me, you want to expose only a few views via basic auth create a decorator.

http://djangosnippets.org/snippets/243/ is a good start.

Till Backhaus