- class DynamicURLResolver(regex='', app_name=None, namespace=None)¶
A URL resolver that allows for dynamically altering URL patterns.
A standard URLResolver expects that a list of URL patterns will be set once and never again change. In most applications, this is a good assumption. However, some that are more specialized may need to be able to swap in URL patterns dynamically. For example, those that can plug in third-party extensions.
DynamicURLResolver makes it easy to add and remove URL patterns. Any time the list of URL patterns changes, they’ll be immediately available for all URL resolution and reversing.
The usage is very simple:
dynamic_patterns = DynamicURLResolver() urlpatterns = [dynamic_patterns] dynamic_patterns.add_patterns([ url(...), url(...), ])
DynamicURLResolver will handle managing all the lookup caches to ensure that there won’t be any stale entries affecting any dynamic URL patterns.
- property url_patterns¶
Returns the current list of URL patterns.
This is a simplified version of URLResolver.url_patterns that simply returns the preset list of patterns. Unlike the original function, we don’t care if the list is empty.
Adds a list of URL patterns.
The patterns will be made immediately available for use for any lookups or reversing.
Removes a list of URL patterns.
These patterns will no longer be able to be looked up or reversed.
- property resolver_chain¶
Returns every URLResolver between here and the root.
The list of resolvers is cached in order to prevent having to locate the resolvers more than once.