How to reload Django's URL config

Note, this article was published over 3
years ago and hence the content may be stale. Consume with a pinch
of salt.

Problem

For some reason, you need to reload your Django URL config.

Normally, the root URL config will be imported and stored in memory when your
server process starts up. Occasionally though, you may want to reload it. This
can be the case if your URL configuration changes depending on certain
parameters.

Discussion

This was a problem I needed to solve while testing the checkout process for
django-oscar. Oscar uses a setting flag to optionally add decorators to
certain URLs, and hence I needed to patch the setting and reload the URLs as
part of the set-up for a test.

This was achieved in the following way, where the setting
OSCAR_ALLOW_ANON_CHECKOUT is set to True and the URL config is reloaded.