Skip to content

Include urls without importing package #1506

Closed
@timobrembeck

Description

@timobrembeck

I don't want to have the django-debug-toolbar package installed in my production environment, so I'm looking for alternatives to a slightly "dirty" import which is not at the top of the file (see PEP-402):

if "debug_toolbar" in settings.INSTALLED_APPS:
    import debug_toolbar
    urlpatterns.append(url(r"^__debug__/", include(debug_toolbar.urls)))

But the obvious string-module-path

    urlpatterns.append(url(r"^__debug__/", include("debug_toolbar.urls")))

fails due to the error ModuleNotFoundError: No module named 'debug_toolbar.urls'.

However, I noticed that

urlpatterns.append(url(r"^__debug__/", include("debug_toolbar.toolbar")))

seems to work, so I wonder why this isn't documented. Are there any downsides to this approach, or might this stop to work in future versions of the django debug toolbar?

Thanks for any comments on this!

Django version: 3.2.7
Django Debug Toolbar version: 3.2.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions