Jump to >


class DynamicURLResolver(regex='', app_name=None, namespace=None)[source]

Bases: django.urls.resolvers.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]


DynamicURLResolver will handle managing all the lookup caches to ensure that there won’t be any stale entries affecting any dynamic URL patterns.

__init__(regex='', app_name=None, namespace=None)[source]

Initialize the resolver.

  • regex (unicode, optional) – The relative pattern for the root of any child URLs.

  • app_name (unicode, optional) – The application namespace for any child URLs.

  • namespace (unicode, optional) – The instance namespace for any child URLs.

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.


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[source]

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.