I develop an application using Django and React. I want to serving Django and React together. I create an build in react. I use it in Django. This is urls.py ;
urlpatterns = [ url(r'^$', views.index), ]
and views.py;
def index(request): return render(request, "build/index.html")
When I run development server there is no any error but when ı want to go url directly ;
http://www.x.com:8000/accounts
I got page not found (404) error.
Advertisement
Answer
Well, do you have an urlpattern for /accounts
? If your example is complete then you get 404 because Django doesn’t know what to return for /accounts
. The only URL your Django server supports, as per your example code, is index available at http://www.x.com:8000
(maybe even http://www.x.com:8000/
(notice the trailing /
) depending on your APPEND_SLASH
settings).
You need to to add an urlapptern and view (and probably a template) for /accounts
. Something like (not tested)
urlpatterns = [ url(r'^$', views.index), url(r'^accounts$', views.index), ] def accounts(request): return render(request, "build/accounts.html")