0

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.

Rayyan
  • 182
  • 4
  • 16
Abdo
  • 36
  • 6
  • `npm` is for `React`, not for `Django`. What error do you get? – Magofoco Dec 18 '20 at 22:36
  • yes I no I am using django reset framework with react but when I run django with react in the same port after running " npm run build " I can't access to django admin page because react router will be excuted when I go to the link : http://localhost:8000/admin/" – Abdo Dec 18 '20 at 22:40
  • 1
    React and Django have to run on two different ports – Magofoco Dec 18 '20 at 22:41
  • @Abdo Can you post the error that you get. It is difficult to know how to proceed without that info – tim-mccurrach Dec 19 '20 at 01:03
  • He probably doesn't get an error, he's just redirected to a page server by React instead of getting the Django admin page. If you solved this, could you post the answer? – DjangoDev1 Jan 13 '21 at 22:35

1 Answers1

0

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'))]
Frightera
  • 4,773
  • 2
  • 13
  • 28
Vivens
  • 1