simonw / django-sql-dashboard

Django app for building dashboards using raw SQL queries
https://django-sql-dashboard.datasette.io/
Apache License 2.0
437 stars 37 forks source link

Installation by include() #14

Closed simonw closed 3 years ago

simonw commented 3 years ago

Urgent instructions are to do this:

from django.urls import path
from django_sql_dashboard.views import dashboard, dashboard_index

urlpatterns = [
    path("dashboard/", dashboard_index, name="django_sql_dashboard-index"),
    path("dashboard/<slug>/", dashboard),
    # ...
]

Using include() here would be better, especially since the paths need to have fixed names that can be referenced in the templates.

simonw commented 3 years ago

I'm going to copy the pattern used by django-debug-toolbar:

import debug_toolbar
from django.conf import settings
from django.urls import include, path

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

Where debug_toolbar.urls is defined here: https://github.com/jazzband/django-debug-toolbar/blob/8b280e196e21b73de10f22cc9bae0d566777dc35/debug_toolbar/__init__.py

urls = "debug_toolbar.toolbar", "djdt"

And debug_toolbar/toolbar.py contains this: https://github.com/jazzband/django-debug-toolbar/blob/8b280e196e21b73de10f22cc9bae0d566777dc35/debug_toolbar/toolbar.py

# ...
    @classmethod
    def get_urls(cls):
        if cls._urlpatterns is None:
            from . import views

            # Load URLs in a temporary variable for thread safety.
            # Global URLs
            urlpatterns = [
                path("render_panel/", views.render_panel, name="render_panel")
            ]
            # Per-panel URLs
            for panel_class in cls.get_panel_classes():
                urlpatterns += panel_class.get_urls()
            cls._urlpatterns = urlpatterns
        return cls._urlpatterns
# ...
urlpatterns = DebugToolbar.get_urls()