djblets.urls.resolvers¶
- class DynamicURLResolver(regex='', app_name=None, namespace=None)[source]¶
Bases:
URLResolver
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[source]¶
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.
- add_patterns(patterns)[source]¶
Adds a list of URL patterns.
The patterns will be made immediately available for use for any lookups or reversing.