jazzband / django-hosts

Dynamic and static host resolving for Django. Maps hostnames to URLconfs.
http://django-hosts.rtfd.org
Other
982 stars 106 forks source link

Can I insert django-debug-toolbar urls to every urls.py ? #83

Closed jeyraof closed 6 years ago

jeyraof commented 6 years ago

In hosts.py:

host_patterns = patterns(
    '',
    host(r'admin', 'server.admin_urls', name='admin'),
    host(r'', 'main.urls', name='main'),
    host(r'app1', 'app_one.urls', name='app1'),
    host(r'app2', 'app_two.urls', name='app2'),
)

And now, I'm using debug_toolbar on every app like:

app_one/urls.py:

urlpatterns = [blahblah~]

if settings.DEBUG:
    import debug_toolbar
    urlpatterns += [
        path('__debug__/', include(debug_toolbar.urls))
    ]

app_two/urls.py:

urlpatterns = [blahblah~]

if settings.DEBUG:
    import debug_toolbar
    urlpatterns += [
        path('__debug__/', include(debug_toolbar.urls))
    ]

So, how to insert debug_toolbar urls to every urls mentioned by hosts.py ?

jeyraof commented 6 years ago

Can I get some insight to resolve it, @jezdez ?

timgraham commented 6 years ago

Usage questions aren't answered on the issue tracker.

brablc commented 11 months ago

It seems I had to include the toolbar into every application to avoid the 'djdt' is not a registered namespace problem. My solution is a generic file that I drop to each site next to urls.py:

# urls_debug.py

from django.urls import path, include
import debug_toolbar

from .urls import urlpatterns as original_urlpatterns

urlpatterns = original_urlpatterns + [
    path('__debug__/', include(debug_toolbar.urls)),
]

And in hosts I include it this way:

# hosts.py

from django_hosts import patterns, host
from django.conf import settings

def enable_debug(path: str) -> str:
    if settings.DEBUG:
        path += "_debug"
    return path

host_patterns = patterns(
    "",
    host(r"www", enable_debug("www.urls"), name="www"),
    host(r"dash", enable_debug("dash.urls"), name="dash"),
    host(r"admin", enable_debug("adm.urls"), name="admin"),
)