How to serve a Svelte app frontend build in Django backend static?

40 views Asked by At

The svelte app is normal svelte (not kit) with some routing. Build by npm run build into: /dist: /assets/index.js, /assets/index.css, index.html.

I tried to follow this tutorial for React and expect it to have the same results. When accessed the serving path, it returns

TemplateDoesNotExist at /index/
frontend/index.html
Request Method: GET
Request URL:    http://127.0.0.1:8000/index/
Django Version: 5.0.1
Exception Type: TemplateDoesNotExist
Exception Value:    
frontend/index.html

In the project app folder:

# views.py
from django.shortcuts import render
def index(request):
    return render(request, 'frontend/index.html')

# urls.py
urlpatterns = [
    path("admin/", admin.site.urls),
    path("", include("api.urls")),
    path('index/', views.index, name='index'),
]

# settings.py
STATIC_URL = "/static/" 
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static/frontend/assets')]
0

There are 0 answers