Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
Images in django not showing up in react

This is an application in which I'm using django backend and react frontend. The images display in react when I keep react and django separate and communicate simply with the APIs. However, I want to deploy both the frontend and backend together. I'm trying to use django re_path to redirect any url that does't match with the urls specifiled in django urls.py. Whenever I do this the images from react and django stop displaying. Both django and react lose track of the path of the images.

project structure
>backend
    ...
    settings.py
    urls.py
>blog
    ...
    urls.py
    serializers.py
    views.py
>frontend
    ...
    build
    src
    package.json
manage.py
>static

urls.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include('djoser.urls')),
    path('api/', include('djoser.urls.jwt')),
    path('api/', include('accounts.urls')),
    path('summernote/',include('django_summernote.urls')),
    path('api/blog/', include('blog.urls')),
    re_path('*', TemplateView.as_view(template_name='index.html')),
   
]

settings.py

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'frontend/build')
        ],
        'APP_DIRS': True,
    },
]

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static',),
    os.path.join(BASE_DIR, 'frontend/build/static'),
    ]
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

How do I fix this? I'm using Django v4

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I finally fixed it using path instead of re_path. I had to change re_path('*', TemplateView.as_view(template_name='index.html')) to re_path('', TemplateView.as_view(template_name='index.html')). I don't know if changes regarding the use of repath in Django 4.0

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda