On Aug 28, 11:24 pm, Greg Fuller <[EMAIL PROTECTED]> wrote: > I would like a way to to adjust settings based on information in the > http header. I've seen a similar question asked before, but I don't > need all the django request object, just the http header information. > More specifically, user_agent, http_host, and path_info. > > Here are two examples of the sort of things I would like to do: > > # use iphone template if appropriate > if http_header['USER_AGENT'].find('iphone'): > TEMPLATE_DIRS = ( > os.path.join(cur_dir_path, 'template_sets/' + 'iphone'), > > # set SITE_ID for MyOtherDomain.com > if http_header["HTTP_HOST"].find('myotherdomain.com'): > SITE_ID = 2 > > Does anyone know if this can be done? > > Thanks, Greg
settings.py isn't executed for every request, just when the Django process starts - and it doesn't have access to any http information. Instead, this sounds like a job for middleware. Create a custom middleware class defining the process_request method, and in that module import your settings (from django.conf import settings). The method is passed the request object, from which you can get the header information you need, then you can set individual settings.* items on a per-request basis. http://docs.djangoproject.com/en/dev/topics/http/middleware/#topics-http-middleware -- DR. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---