[Django]-Dynamically reload the URLConfs for a running site

5👍

Your question starts from a premise that most Django programmers wouldn’t accept: that you can or should create URLs dynamically from the database. If you’re doing that, you’re doing it wrong.

Your URL patterns are part of the code, not the data. Obviously, the URLs themselves are formed by combining the patterns with the data – eg foo/<slug>/bar/, but this doesn’t need reloading when new slugs are added because it is resolved by the view, not the URL processor.

0👍

import sys    
from django.conf import settings
from django.core.urlresolvers import clear_url_caches

clear_url_caches()
reload(sys.modules[settings.ROOT_URLCONF])
👤Evgeny

Leave a comment