﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34787	The 'runserver' command doesn't work when run from an installed script on Windows	Joël Larose	Sarah Boyce	"My `manage.py` is as follows:
{{{
#!/usr/bin/env python
import os
import sys


def django_manage():
    """"""Function implementation of python manage.py""""""
    os.environ.setdefault(""DJANGO_SETTINGS_MODULE"", ""<project_package>.settings.dev"")
    from django.core.management import execute_from_command_line
    execute_from_command_line(sys.argv)


if __name__ == ""__main__"":
    django_manage()
}}}

In my `pyproject.toml` I have:
{{{
[project.scripts]
    ""djm"" = ""<project_package>.manage:django_manage""
}}}

In Windows this generates a `djm.exe` file.

This allows me to save a few keystrokes when issuing commands from CLI.  And it works for most of the django commands.  The only exception I've encountered so far is with the `runserver` command.
It gives:
{{{
<project_path>\venv\Scripts\python.exe: Error while finding module specification for '__main__' (ValueError: __main__.__spec__ is None)
}}}

After much debugging and tracing, I found where the issue lies.  The problem is in the `get_child_arguments` function in `django/utils/autoreload.py`.  When you flip the first two `if`-`elif` blocks, everything works.  That is, the check for `not py_script.exists()` needs to come before the check for `getattr(__main__, ""__spec__"", None) is not None`.

I'm not sure if this creates different problems, but it certainly fixes the one I was having."	Bug	closed	Core (Management commands)	dev	Normal	fixed		David Smith	Ready for checkin	1	0	0	0	1	0
