How to detect if script ran from Django or command prompt?
<p>I have a Python script that pauses for user input (using <code>raw_input</code>, recently I created a Django web UI for this script. Now when I execute the script via Django is pauses as it's waiting for input in the backend. </p>

<p>How can I determine if the script was ran from Django or terminal/cmd/etc? I don't want to maintain 2 streams of code, one for web and another one for terminal.</p>

<p>Explicit is better than implicit. Wrap your interactivity in a function that's called only if the <code>__name__ == "__main__"</code> part was executed. From the django parts, just use it as a library. Most ways of doing these kinds of checks are semi-magical and hence flaky.</p>

python django