How can I be certain that my application is running on development server or not? I suppose I could check value of settings.DEBUG
and assume if DEBUG
is True
then it's running on development server, but I'd prefer to know for sure than relying on convention.
Django provides a simple WSGI server as a dev server.
To verify the Django project, make sure your virtual environment is activated, then start Django's development server using the command python manage.py runserver . The server runs on the default port 8000, and you see output like the following output in the terminal window: Performing system checks...
Django, being a web framework, needs a web server in order to operate. And since most web servers don't natively speak Python, we need an interface to make that communication happen. Django currently supports two interfaces: WSGI and ASGI.
I put the following in my settings.py to distinguish between the standard dev server and production:
import sys RUNNING_DEVSERVER = (len(sys.argv) > 1 and sys.argv[1] == 'runserver')
This also relies on convention, however.
(Amended per Daniel Magnusson's comment)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With