Does the INTERNAL_IPS variable control the Django DEBUG variable?

Asked

Viewed 38 times

-1

My Django application should run two environments: one for development and one for production.

When running in the development environment, access to application by 127.0.0.1 and when production access, I use my domain www normally.

In the application code, I need to know what environment I am in and for that I use the variable DEBUG of the archive settings.py. I know I can check the hostnames of the environments:

DEBUG = (socket.gethostname() == 'ambiente_dev')

However, I saw that in the documentation there is a configuration called INTERNAL_IPS. If I put the development environment IP in this tuple, like this:

INTERNAL_IPS = (
    '127.0.0.1',
)

The variable DEBUG will automatically get the value True when I run the application in the development environment?

1 answer

1


Apparently NAY, exactly in the own link that you posted it says:

Allow the debug() context Processor to add some variables to the template context.

And if you notice this debug() described is also a link, which leads to the documentation page that explains that it is exactly it:

If this Processor is enabled, Every Requestcontext will contain These two variables - but only if your DEBUG Setting is set to True and the request’s IP address (request.META['REMOTE_ADDR']) is in the INTERNAL_IPS Setting:

  • debug - True. You can use this in templates to test whether you’re in DEBUG mode.

  • sql_queries - A list of {'sql': ..., 'time': ...} Dictionaries, Representing Every SQL query that has happened so far During the request and how long it Took. The list is in order by database alias and then by query. It’s lazily generated on access.

Translate, if this processor is activated, all RequestContext will contain these two variables (debug and sql_queries), but this will be only if its configuration DEBUG is defined as True and the requested IP address (request.META['REMOTE_ADDR']) is in INTERNAL_IPS.

So both are complementary, but they don’t influence each other’s behavior and context debug() although gift will need both settings.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.