Skip to content

Conversation

@ajostergaard
Copy link

Minor efficiency gain.

@jezdez
Copy link
Contributor

jezdez commented Apr 7, 2012

This isn't really true though, you can run and should be able to run the debug toolbar in cases DEBUG is False, e.g. in staging environments. You can however achieve what you try to do with a custom SHOW_TOOLBAR_CALLBACK:

def show_only_in_debug(request):
    "Always show toolbar, for example purposes only."
    from django.conf import settings
    return settings.DEBUG

DEBUG_TOOLBAR_CONFIG = {
    'SHOW_TOOLBAR_CALLBACK': show_only_in_debug,
    # ..
}

@jezdez jezdez closed this Apr 7, 2012
@ajostergaard
Copy link
Author

Fair enough but what I was wanting to achieve wasn't to not run the toolbar when not in DEBUG mode - what I wanted to achieve was to not have the middleware called on every request when we know upfront (on server start) that the middleware is disabled for whatever reason.

Perhaps my choice of toolbar 'flag' was incorrect but raising MiddlewareNotUsed is certainly appropriate.

@jezdez
Copy link
Contributor

jezdez commented Apr 7, 2012

Understood, but given the fact that it's allowed to use a custom callback that is passed the request we can't bail that early in the middleware, sorry.

@ajostergaard
Copy link
Author

Perhaps it would make sense to implement a debug_toolbar on/off switch? I assume you'll agree that it's not good practice to execute a pile of code if you know upfront it'll be wasted effort.

The alternative is using django settings to manipulate the middleware config based on deployment environment but that seems heavy handed particularly as Django has a hook specifically for the purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants