[Answer]-Django developement on pytools – auto-restart server after changes? (VS 2013)

1👍

Python Tools for Visual Studio (PTVS) doesn’t currently allow you to set an environment variable for an active python project (https://pytools.codeplex.com/workitem/737). A workaround is to set the environment variable and launch the development server from outside Visual Studio. You can do this either globally or within a virtual environment.

Using the global environment

Set the environment variable “WATCH_FILE_CHANGES_MASK” to have a value of “*.py” as described at http://msdn.microsoft.com/en-us/library/windows/desktop/ms682653(v=vs.85).aspx then from the project directory run

python .\manage.py runserver

Within a virtual environment

Edit the file env\scripts\activate.bat under the project directory and add the line

set "WATCH_FILE_CHANGES_MASK=*.py"

Then from the project directory activate the virtualenv

.\env\scripts\activate

and run the server

python .\manage.py runserver

Oddly neither setting the global environment variable nor editing the activate script have an effect on how the development server behaves when launched from within Visual Studio. Personally I prefer to launch the development server externally for this reason and also because of some limitations Visual Studio enforces while the server is running (no renaming, moving files, etc.) that are not relevant to django development.

Leave a comment