Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make autoreload work under Django >= 1.8 #129

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions devserver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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()