@@ -297,3 +297,45 @@ urlpatterns = [
297297~~ {' post_reset_redirect' : ' /accounts/password/done/' },),
298298]
299299```
300+
301+
302+ ## Example 7 from django-angular
303+ [ django-angular] ( https://github.com/jrief/django-angular )
304+ ([ project examples website] ( https://django-angular.awesto.com/classic_form/ ) )
305+ is a library with helper code to make it easier to use
306+ [ Angular] ( /angular.html ) as the front-end to [ Django] ( /django.html ) projects.
307+ The code for django-angular is
308+ [ open source under the MIT license] ( https://github.com/jrief/django-angular/blob/master/LICENSE.txt ) .
309+
310+ [ ** django-angular / djng / urls.py** ] ( https://github.com/jrief/django-angular/blob/master/djng/urls.py )
311+
312+ ``` python
313+ import warnings
314+ from django.urls import reverse
315+ ~~ from django.conf.urls import url
316+ from django.http.response import HttpResponsePermanentRedirect
317+
318+
319+ warnings.warn(" Reversing URL's using urlpatterns is deprecated. "
320+ " Please use the middleware instead" ,
321+ DeprecationWarning )
322+
323+
324+ def angular_reverse (request , * args , ** kwargs ):
325+ url_name = request.GET .get(' djng_url_name' )
326+ url_args = request.GET .getlist(' djng_url_args' , None )
327+ url_kwargs = {}
328+
329+ prefix = ' djng_url_kwarg_'
330+ for param in request.GET :
331+ if param.startswith(prefix):
332+ url_kwargs[param[len (prefix):]] = request.GET [param]
333+
334+ url = reverse(url_name, args = url_args, kwargs = url_kwargs)
335+ return HttpResponsePermanentRedirect(url)
336+
337+
338+ urlpatterns = [
339+ ~~ url(r ' ^ reverse/$ ' , angular_reverse),
340+ ]
341+ ```
0 commit comments