Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include urls without importing package #1506

Closed
timobrembeck opened this issue Sep 27, 2021 · 2 comments · Fixed by #1537
Closed

Include urls without importing package #1506

timobrembeck opened this issue Sep 27, 2021 · 2 comments · Fixed by #1537

Comments

@timobrembeck
Copy link
Member

timobrembeck commented Sep 27, 2021

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

@matthiask
Copy link
Member

matthiask commented Sep 27, 2021

To be honest: I have no idea why we couldn't make include("debug_toolbar.urls") work (except for time and energy, always excellent reasons)

Maybe it has to do with old ways of declaring URLconf namespaces or maybe something to do with the magical auto-installation of the toolbar which has been removed a few years ago.

@tim-schilling
Copy link
Contributor

Yarp, I agree here. This should be possible now if it wasn't in the past.

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 a pull request may close this issue.

3 participants