I am working on a project where we use feature toggles to hide features until they are ready to be released.
The pattern we have followed is to simply not route certain endpoints if the feature toggle is off. I.e in urls.py
, we only include URLs in the urlconf
if the toggle is on. But this means feature toggles only have an effect if the server is restarted. We'd like to be able to dynamically turn feature toggles on and off on a running server. It seems that the urlconf
is only parsed at startup time so changes to it are not reflected without a reboot.
I've tried making a middleware to block certain URLs based on the value of a feature toggle and that works but doesn't play nicely with the Swagger
docs, which I also would like to reflect the state of the feature toggles.
In general, it feels like I am fighting the system, which is usually a sign that I'm not approaching it from the right angle.
So, how do people advise me to implement dynamic feature toggles of behaviour in Django?
EDIT: I meant to say that I have looked at a few posts, such as this one: Django dynamic urlpatterns but there wasn't really any resolution.
Some even older posts talk about forcing a refresh of urlconf
by reloading the module and I've tried that but, although I can see the code getting executed again, it doesn't seem to affect the URLs. It's like they are being cached but I can't find out any way to clear that cache (all posts on I've found on that subject are obsolete)