Maheer AB
Maheer AB

Reputation: 1

Why is my page either not loading anything or giving me Template does not exist error? Django-React integration

[The templates section in settings.py]

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'backend', 'dist')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

[Static files path] {

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'backend', 'dist', 'static', 'assets'),
]
}

    STATIC_URL = '/static/'

    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, 'backend', 'dist', 'static', 'assets'),
    ]

File structure

[index.html]

`<!doctype html>
<html lang="en">
  <head>
      <meta charset="UTF-8" />
      <link rel="icon" type="image/png+xml" href="Logo.png" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <link rel="preconnect" href="https://fonts.googleapis.com">
      <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
      <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap" rel="stylesheet">

    <script type="module" crossorigin src="/assets/index-fhkDj9Lf.js"></script>
    <link rel="stylesheet" crossorigin href="/assets/index-TTwl8E9H.css">
  </head>
  <body>
    <div id="root"></div>

  </body>
</html>
`

[urls.py]

from django.contrib import admin
from django.urls import path, include, re_path
from django.views.generic import TemplateView


urlpatterns = [
    path('admin/', admin.site.urls),
    path('auth/', include('djoser.urls')),
    path('auth/', include('djoser.urls.jwt')),    
    ]

urlpatterns += [re_path(r'^.*', TemplateView.as_view(template_name='index.html'))]

error

`I believe the error is occuring either because my static files aren't loading correctly or my routes are bad and index.html is just not getting picked up at all, as mentioned I do get a blank page this happens when I just put index.html in quotation marks in urls.py.

I tried changing the file paths and fixing it, making sure css mime type is css and am expecting the page to load which either gives me an error or a blank screen.`

Upvotes: 0

Views: 49

Answers (0)

Related Questions