#20109: django-admin.py does not correctly set DJANGO_SETTINGS_MODULE (patch attached) -------------------------------------+------------------------------------- Reporter: jamercee | Owner: nobody Type: New feature | Status: closed Component: Core (Management | Version: 1.5 commands) | Resolution: Severity: Normal | worksforme Keywords: djang-admin.py, | Triage Stage: manage.py, | Unreviewed "DJANGO_SETTINGS_MODULE" | Needs documentation: 0 Has patch: 1 | Patch needs improvement: 0 Needs tests: 0 | UI/UX: 0 Easy pickings: 0 | -------------------------------------+------------------------------------- Changes (by carljm):
* status: new => closed * needs_better_patch: => 0 * resolution: => worksforme * needs_tests: => 0 * needs_docs: => 0 Comment: Hi, thanks for the report. The report doesn't make sense to me, because as far as I know Python always adds the directory of the running script to the beginning of `sys.path`, no matter where you run it from, so the added code you propose should be entirely redundant. Demo: {{{ [11:32] carljm@endive:~/tmp {test33} $ cat foo/manage.py #!/usr/bin/env python import sys print(sys.path) [11:32] carljm@endive:~/tmp {test33} $ python foo/manage.py ['/home/carljm/tmp/foo', '/home/carljm/.venvs/test33/lib/python3.3/site- packages/distribute-0.6.28-py3.3.egg', '/home/carljm/.venvs/test33/lib/python3.3/site- packages/pip-1.2.1-py3.3.egg', '/home/carljm/.venvs/test33/lib/python33.zip', '/home/carljm/.venvs/test33/lib/python3.3', '/home/carljm/.venvs/test33/lib/python3.3/plat-linux', '/home/carljm/.venvs/test33/lib/python3.3/lib-dynload', '/opt/Python-3.3.0/lib/python3.3', '/opt/Python-3.3.0/lib/python3.3/plat- linux', '/home/carljm/.venvs/test33/lib/python3.3/site-packages'] [11:32] carljm@endive:~/tmp {test33} $ ./foo/manage.py '['/home/carljm/tmp/foo', '/home/carljm/.venvs/test33/lib/python3.3/site- packages/distribute-0.6.28-py3.3.egg', '/home/carljm/.venvs/test33/lib/python3.3/site- packages/pip-1.2.1-py3.3.egg', '/home/carljm/.venvs/test33/lib/python33.zip', '/home/carljm/.venvs/test33/lib/python3.3', '/home/carljm/.venvs/test33/lib/python3.3/plat-linux', '/home/carljm/.venvs/test33/lib/python3.3/lib-dynload', '/opt/Python-3.3.0/lib/python3.3', '/opt/Python-3.3.0/lib/python3.3/plat- linux', '/home/carljm/.venvs/test33/lib/python3.3/site-packages'] [11:32] carljm@endive:~/tmp {test33} $ cd foo [11:32] carljm@endive:~/t/foo {test33} $ python manage.py ['/home/carljm/tmp/foo', '/home/carljm/.venvs/test33/lib/python3.3/site- packages/distribute-0.6.28-py3.3.egg', '/home/carljm/.venvs/test33/lib/python3.3/site- packages/pip-1.2.1-py3.3.egg', '/home/carljm/.venvs/test33/lib/python33.zip', '/home/carljm/.venvs/test33/lib/python3.3', '/home/carljm/.venvs/test33/lib/python3.3/plat-linux', '/home/carljm/.venvs/test33/lib/python3.3/lib-dynload', '/opt/Python-3.3.0/lib/python3.3', '/opt/Python-3.3.0/lib/python3.3/plat- linux', '/home/carljm/.venvs/test33/lib/python3.3/site-packages'] [11:32] carljm@endive:~/t/foo {test33} $ ./manage.py ['/home/carljm/tmp/foo', '/home/carljm/.venvs/test33/lib/python3.3/site- packages/distribute-0.6.28-py3.3.egg', '/home/carljm/.venvs/test33/lib/python3.3/site- packages/pip-1.2.1-py3.3.egg', '/home/carljm/.venvs/test33/lib/python33.zip', '/home/carljm/.venvs/test33/lib/python3.3', '/home/carljm/.venvs/test33/lib/python3.3/plat-linux', '/home/carljm/.venvs/test33/lib/python3.3/lib-dynload', '/opt/Python-3.3.0/lib/python3.3', '/opt/Python-3.3.0/lib/python3.3/plat- linux', '/home/carljm/.venvs/test33/lib/python3.3/site-packages'] }}} No matter where I run `manage.py` from, `/home/carljm/tmp/foo` (its location) is always the first entry on `sys.path`. I verified this under both Python 2 and Python 3. So it seems there must be something else unusual going on in your situation. (Also, it seems your proposed code could be simplified by using the builtin `__file__` rather than `inspect.getfile(inspect.currentframe())`.) -- Ticket URL: <https://code.djangoproject.com/ticket/20109#comment:1> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.