سؤال

Possible Duplicate:
Django: How to access URL regex parameters inside a middleware class?

I am using django in google appengine. Each url in my app has a company code in the format:

http://localhost:8080/[company]/blah/blah

What I want to do is pre process the url and fetch the [company], set appengine datastore namespace to the company code. This can be done by using named url pattern which will pass the company code to each view function as kwargs parameter. This seems too much to just set a namespace at the begining. Moreover I will not need this company param in any of my views.

Is it possible to set the namespace from the url param but avoid passing the company param to each view of my project?

هل كانت مفيدة؟

المحلول

You don't need to actually include the kwarg in your views function definition so you could just ignore it.

url(r'^(?P<company>[-\w]+)/$','app.views.foo_view', name="foo_view"),

and

def foo_view(request):
    pass

Alternatively use the process_request middleware and pop the company out of the kwargs so that it won't be passed to any of the views.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top