From 1e4275ea7a53391f5e3d7b54ee8a2004cda11e85 Mon Sep 17 00:00:00 2001 From: kappa118 Date: Wed, 26 Feb 2025 20:02:13 -0500 Subject: [PATCH] core django changes for new react ui --- dispatcharr/settings.py | 15 ++++++++++++--- dispatcharr/urls.py | 42 +++++++++++++++++------------------------ 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/dispatcharr/settings.py b/dispatcharr/settings.py index 08700674..ef3e2223 100644 --- a/dispatcharr/settings.py +++ b/dispatcharr/settings.py @@ -49,7 +49,10 @@ ROOT_URLCONF = 'dispatcharr.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [BASE_DIR / 'templates'], + 'DIRS': [ + os.path.join(BASE_DIR, 'frontend/build'), + BASE_DIR / "templates" + ], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -98,8 +101,14 @@ USE_I18N = True USE_TZ = True STATIC_URL = '/static/' -STATIC_ROOT = BASE_DIR / 'staticfiles' -STATICFILES_DIRS = [BASE_DIR / 'static'] +STATIC_ROOT = BASE_DIR / 'staticfiles' # Directory where static files will be collected + +# Adjust STATICFILES_DIRS to include the paths to the directories that contain your static files. +STATICFILES_DIRS = [ + os.path.join(BASE_DIR, 'frontend/build/static'), # React build static files + BASE_DIR / 'static', # Django custom static files (if any) +] + DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' AUTH_USER_MODEL = 'accounts.User' diff --git a/dispatcharr/urls.py b/dispatcharr/urls.py index 2b0c6997..346a8c5e 100644 --- a/dispatcharr/urls.py +++ b/dispatcharr/urls.py @@ -2,7 +2,7 @@ from django.contrib import admin from django.urls import path, include from django.conf import settings from django.conf.urls.static import static -from django.views.generic import RedirectView +from django.views.generic import TemplateView from rest_framework import permissions from drf_yasg.views import get_schema_view from drf_yasg import openapi @@ -21,39 +21,31 @@ schema_view = get_schema_view( permission_classes=(permissions.AllowAny,), ) - - urlpatterns = [ - path('', RedirectView.as_view(pattern_name='dashboard:dashboard'), name='home'), + # API Routes path('api/', include(('apps.api.urls', 'api'), namespace='api')), + + # Admin + path('grappelli/', include('grappelli.urls')), # Grappelli admin path('admin/', admin.site.urls), - path('accounts/', include(('apps.accounts.urls', 'accounts'), namespace='accounts')), - #path('streams/', include(('apps.streams.urls', 'streams'), namespace='streams')), - #path('hdhr/', include(('apps.hdhr.urls', 'hdhr'), namespace='hdhr')), - path('m3u/', include(('apps.m3u.urls', 'm3u'), namespace='m3u')), - path('epg/', include(('apps.epg.urls', 'epg'), namespace='epg')), - path('channels/', include(('apps.channels.urls', 'channels'), namespace='channels')), - path('settings/', include(('core.urls', 'settings'), namespace='settings')), - #path('backup/', include(('apps.backup.urls', 'backup'), namespace='backup')), - path('dashboard/', include(('apps.dashboard.urls', 'dashboard'), namespace='dashboard')), - path('output/', include('apps.output.urls', namespace='output')), - - - # Swagger UI: + # Swagger UI path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), - - # ReDoc UI: + + # ReDoc UI path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'), - - # Optionally, you can also serve the raw JSON: + + # Optionally, serve the raw Swagger JSON path('swagger.json', schema_view.without_ui(cache_timeout=0), name='schema-json'), + # Catch-all route to serve React's index.html for non-API, non-admin paths + path('', TemplateView.as_view(template_name='index.html')), # React entry point + ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) +# Serve static files for development (React's JS, CSS, etc.) if settings.DEBUG: urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) - urlpatterns += static( - settings.MEDIA_URL, - document_root=settings.MEDIA_ROOT - ) \ No newline at end of file + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + +urlpatterns += [path('', TemplateView.as_view(template_name='index.html'))]