user6946961 user6946961 - 6 days ago 6x
React JSX Question

How do i configure django urls to make it so if it displays 404, it reroutes to Reactjs

The title is terrible - sorry about that.

So say I have a website say I've configured my so that whenever the person enters it redirects them to the index.html (where it displays the reactjs application). I've set reactjs with react-router and made it so when you click a button on the index page it goes to

Thing is... I don't want that.

I want it to go to I want react to handle this however and not django. ALL of this url thing should be in the same application of index.html. How do I configure django so that if I enter it goes to the index of ReactJs's application and then it checks to see if the route has webpage. Otherwise say if I went to (which the react route doesn't have) it should display a 404.

Basically what I want to happen:

User goes to
>if exists in django - it returns a html doc
>if not then it redirects to where ReactJs will handle the url and see if it matches any of the routers
...> if it does, then it displays that route
...> if not then it displays a django 404 or a custom 404 page.

How do I configure django and reactjs to do this?


Are you using Django to render react? I am making the assumption that you have some view like views.LoadReactView.

What you need is a catch all route.

from django.contrib import admin
from myapp import views

urlpatterns = [
    url(r'^', views.LoadReactView.as_view()),

This should appear as your very last pattern. You essentially are saying "after checking all the other routes, if there are no matches, go here".

In addition, you could also actually just define your main view as your 404 handler

urlpatterns = [

handler404 = views.LoadReactView.as_view