Tag Archives: django

Passing REMOTE_USER through mod_WSGI

I need to change the way we authenticate a django application.

Currently we authenticate by an apache module which sets the REMOTE_USER header and passes it to the python app in the environment of mod_wsgi.

The new approach will be to use an app gateway. The gateway works like a reverse proxy and intercept requests to the application. The app gateway authenticates the user and if succesful forwards the request to our application with the REMOTE_USER header set.

The problem with this approach is that mod_wsgi will drop that header.

Continue reading Passing REMOTE_USER through mod_WSGI

Django Q function

When querying objects in django the simplest way is to use the filter() query.

If we have a set of systems for example and we want to filter out those that have a SPARC architecture we could do:

And if we wanted to narrow that down to only sparc machines that use NIS for name resolution we could do:

But that is narrowing down the selection. It’s an AND. What were asking for is systems that are a SPARC _AND_ use NIS. And although we can use exclude() to reject some results it’s still and AND operation. What about an OR query?

What if we wanted to select systems that had either a T5 or a T7 processor? Then we need Q queries.

Q queries take the same form of argument as filter() & exclude() etc. but can be combined using OR operators. Here’s the Q query for our model that looks at the cpu_implementation for T5 or T7:

To build our query we just use this Q expression in a filter: