Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I test whether Django is running in debug mode?

Tags:

django

My settings file has:

DEBUG = True

The obvious method:

if DEBUG:
    print 'debug'

Does not seem to work:

global name 'DEBUG' is not defined
like image 923
Hoa Avatar asked May 20 '13 11:05

Hoa


People also ask

How do I know if Django server is running?

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...

What is debug in Django settings?

One of the main features of debug mode is the display of detailed error pages. If your app raises an exception when DEBUG is True, Django will display a detailed traceback, including a lot of metadata about your environment, such as all the currently defined Django settings (from settings.py).

How do I test a Django project?

The preferred way to write tests in Django is using the unittest module built-in to the Python standard library. This is covered in detail in the Writing and running tests document. You can also use any other Python test framework; Django provides an API and tools for that kind of integration.


1 Answers

As mentioned in the comment, you need to do:

from django.conf import settings

print(settings.DEBUG)
like image 153
zsquare Avatar answered Sep 21 '22 00:09

zsquare