Skip to content

Instantly share code, notes, and snippets.

@mason276752
Forked from FZambia/reload_urlconf.py
Created May 7, 2017 19:18
Show Gist options
  • Save mason276752/2eb74be7cdb2ad49a5ae58d64a691e1d to your computer and use it in GitHub Desktop.
Save mason276752/2eb74be7cdb2ad49a5ae58d64a691e1d to your computer and use it in GitHub Desktop.
reload django urlconf
#python manage.py runserver --noreload
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.http import HttpResponse
import sys
def reload_urls(request, urlconf=None):
if urlconf is None:
urlconf = settings.ROOT_URLCONF
if urlconf in sys.modules:
reload(sys.modules[urlconf])
return HttpResponse('urlconf reloaded')
def reloaded(request):
return HttpResponse('hello')
urlpatterns = patterns('',
url(r'^$', reload_urls),
url(r'^reloaded/$', reloaded),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment