Filtering by requested URL #284

Closed
gw0 opened this Issue May 29, 2012 · 2 comments

Projects

None yet

3 participants

@gw0
gw0 commented May 29, 2012

I know that with the callback function one can implement his own complex mechanism of deciding when to display the Django Debug Toolbar and when not, but common filtering use cases (like checking users IP) should be made as simple as possible.

Therefore I suggest an configuration option to filter out (not show) the toolbar on pages whose URLs match a specific pattern (or regular expression). E.g. if you are using the Django admin panel, but not developing enything in it, you do not need the debug toolbar there, so it would be nice to filter out the toolbar on all requests under '^admin/'. Same need appears if you have a page with many small iframes and you just want to debug the outside Django app and templates, not the ones in the small iframes - here it would be nice to hide the toolbar on all requests to the iframed app.

Suggestion is therefore to have one or more regular expressions for filtering where the toolbar should be shown based on the requested URL. E.g. either as a complex regex or as a list of simpler regexes:

DEBUG_TOOLBAR_CONFIG = ( ... 'HIDE_FILTER_URL': '^admin/|^myapp/someview', ... )
or
DEBUG_TOOLBAR_FILTER_URL = ('^admin/', '^myapp/someview')
@steppo40

I stepped into the same issue and agree with gw0 on suggesting an implementation of common filtering patterns to quickly remove the toolbar from matching urls. Just an hint.

Either way, really good job the all-mighty debug-toolbar. You guys rock!

@aaugustin
Contributor

Now that #324 is fixed, this has become really simple to implement. Here's how you would exclude the admin:

from debug_toolbar.middleware import show_toolbar

def custom_show_toolbar(request):
    return show_toolbar(request) and not request.path.startswith('/admin/')

Here's how you would exclude a series of URL prefixes:

from debug_toolbar.middleware import show_toolbar

excluded_urls = ['/foo', '/bar']

def custom_show_toolbar(request):
    excluded = any(request.path.startswith(url) for url in excluded_urls)
    return show_toolbar(request) and not excluded

I don't think it would be easier to use a DSL for filtering URLs. Plain Python is a suitable tool for this class of problems.

Thanks for the suggestion anyway!

@aaugustin aaugustin closed this Oct 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment