404 page not found using Django + response-router

I'm trying to use reactjsand react-router( 1.x) with my Django app, but it's hard for me to put all this together. Here is the github project just incase I do not provide enough information in this matter.

https://github.com/liondancer/django-cherngloloong

I created path="about"in myroutes.js

var routes = (
    <Router>
        <Route path="/" component={ Views.Layout }>
            <IndexRoute component={ Views.Index } />
            <Route path="about" component={ Views.About } />
        </Route>
        <Route path="*" component={ Views.RouteNotFound } />
    </Router>
);

export default routes;

My layout.js

class Layout extends React.Component {
    constructor(props) {
        super(props);
    }
    render() {
        return (
            <div id="review-web">
                <header className="header">
                    <LogoElement />
                    <CenterPiece />
                </header>
                <div>
                    { React.cloneElement(this.props.children, { path: this.props.path }) }
                </div>
                <Footer />
            </div>
        );
    }
}

export default Layout;

When I enter localhost.8000/about, I get a 404Django error

enter image description here

My goal is to keep the interface and backend separate, so I think I should use Django as an endpoint for data, not view views.

+4
source share
2

.

settings.py:

REACT_ROUTES = [
    'login',
    'signup',
    'password-reset',
    'password-change',
    'about',
    ...
]

urls.py:

routes = getattr(settings, 'REACT_ROUTES', [])
urlpatterns = [
    ...
    url(r'^(%s)?$' % '|'.join(routes), TemplateView.as_view(template_name='index.html')),
]

- django, url(r'^.*$'), HTTP status_code 200. , HTTP status_code 404 URL-.

+4

JS . .

@blueprint.route('/stuff/<path:path>', methods=["get"])
@blueprint.route('/', methods=["get"])
def index(path=None):
    return render_template('app.html')
+1

Source: https://habr.com/ru/post/1612306/


All Articles