From 6403e933d531e3e12cd78be0e8cebc48f14f92e7 Mon Sep 17 00:00:00 2001 From: Ion Scerbatiuc Date: Wed, 4 May 2016 16:02:07 -0700 Subject: [PATCH 1/2] Make autoreload work under Django >= 1.8 --- devserver/__init__.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/devserver/__init__.py b/devserver/__init__.py index 4b264aa..6d92101 100644 --- a/devserver/__init__.py +++ b/devserver/__init__.py @@ -47,3 +47,29 @@ def get_version(): if __build__: base = '%s (%s)' % (base, __build__) return base + + +def patch_get_commands(): + # Make autoreload use the devserver's runserver command instead of the + # default one. This prevent crashing the devserver on a syntax error + import functools + import django.core.management.get_commands + + original = django.core.management.get_commands + if getattr(original, '_wrapped', False): + return + + @functools.wraps(original) + def wrapper(*args, **kwargs): + commands = original(*args, **kwargs) + commands['runserver'] = 'devserver' + return commands + wrapper._wrapped = True + + django.core.management.get_commands = wrapper + + +import django +major, minor = django.VERSION[:2] +if major >= 1 and minor >= 8: + patch_get_commands() From 45b3eaa5dbd0b5450814c4ff0588be4a2d606741 Mon Sep 17 00:00:00 2001 From: Ion Scerbatiuc Date: Wed, 4 May 2016 16:12:08 -0700 Subject: [PATCH 2/2] Fixed import --- devserver/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devserver/__init__.py b/devserver/__init__.py index 6d92101..d39513e 100644 --- a/devserver/__init__.py +++ b/devserver/__init__.py @@ -53,7 +53,7 @@ def patch_get_commands(): # Make autoreload use the devserver's runserver command instead of the # default one. This prevent crashing the devserver on a syntax error import functools - import django.core.management.get_commands + import django.core.management original = django.core.management.get_commands if getattr(original, '_wrapped', False):