>happen outside of the view (and come to the view as a parameter). The
>other thing is that _all_ my views will need this and to me that just
>feels a bit dirty. I guess it is probably the best way, though.
The easiest way out for that is to provide a decorator for your view
functions that just takes the first parameter of the function call,
pulls out the host header value and puts that into a kwarg for the view
function with your choice of name. Something like:
def extract_host(fun):
def _inner(request, *args, **kw):
kw['host'] = request.META['HTTP_HOST']
return fun(*args, **kw)
return _innner
and use this like:
@extract_host
def yourview(request, host=''):
...
or with Python 2.3:
def yourview(request, host=''):
...
yourview = extract_host(yourview)
That way you only need to code that stuff once and apply it to all view
functions that need it. Oh, I didn't check the code above, so you
better try it before you apply it ;-)
bye, Georg