summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/autoreload.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py
index 845c46c8d4..1ef10a15f9 100644
--- a/django/utils/autoreload.py
+++ b/django/utils/autoreload.py
@@ -207,12 +207,26 @@ def get_child_arguments():
on reloading.
"""
import django.__main__
+ django_main_path = Path(django.__main__.__file__)
+ py_script = Path(sys.argv[0])
args = [sys.executable] + ['-W%s' % o for o in sys.warnoptions]
- if sys.argv[0] == django.__main__.__file__:
+ if py_script == django_main_path:
# The server was started with `python -m django runserver`.
args += ['-m', 'django']
args += sys.argv[1:]
+ elif not py_script.exists():
+ # sys.argv[0] may not exist for several reasons on Windows.
+ # It may exist with a .exe extension or have a -script.py suffix.
+ exe_entrypoint = py_script.with_suffix('.exe')
+ if exe_entrypoint.exists():
+ # Should be executed directly, ignoring sys.executable.
+ return [exe_entrypoint, *sys.argv[1:]]
+ script_entrypoint = py_script.with_name('%s-script.py' % py_script.name)
+ if script_entrypoint.exists():
+ # Should be executed as usual.
+ return [*args, script_entrypoint, *sys.argv[1:]]
+ raise RuntimeError('Script %s does not exist.' % py_script)
else:
args += sys.argv
return args