ReactJS Django admin page not found

778 Views Asked by At

I have a project with react and Django and after I ran the command

npm run build 

and changed the Django static field settings to:

   'DIRS': [os.path.join(BASE_DIR, 'frontend/build')],

I can't access the Django administration "http://localhost:8000/admin/" after I built up the project.

1

There are 1 best solutions below

0
On

Update your urls to admin/, It's worked for me.

urlpatterns = [
path('admin/web', admin.site.urls),
path('api-auth/', include('rest_framework.urls')),
path('accounts/', include('account.urls')),
path('main-app/', include('main.urls')),
path('admin/password_reset/', auth_views.PasswordResetView.as_view(),
     name='admin_password_reset'),
path('admin/password_reset/done/',
     auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),
path('reset/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(),
     name='password_reset_confirm'),
path('reset/done/', auth_views.PasswordResetCompleteView.as_view(),
     name='password_reset_complete'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

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