Django: How do I access URL regex options inside a middleware class?

I am working on a Django project on the Google App Engine. I have a url:

http://localhost:8080/[company]/projects/project

Note that [company]this is the URL parameter defined in my urls.py, for example:

(r'(^[a-zA-Z0-9-_.]*)/projects/project/(\d*)', 'projects.views.project_form'),

I want to get the value [company]from middleware where I set the GAE repository namespace to value [company].

Is it possible to get the parameter [company]from the request object passed in the process_requestmiddleware class method ?

+5
source share
1 answer

process_view, , , . :

def process_view(self, request, view_func, view_args, view_kwargs)
    ...

view_args - , , view_kwargs - , .

, :

def process_view(self, request, view_func, view_args, view_kwargs):
    company = view_kwargs.get('company', None)

django , URL- args kwargs :

http://www.djangobook.com/en/1.0/chapter08/#cn38

[ url-] , , : , .

+5

All Articles