Home > Net >  React and Django website not loading on Heroku
React and Django website not loading on Heroku

Time:10-24

Homepage doesn't load properly

I have successfully build and deployed my code in Heroku.

It works fine locally but react doesn't render the index.html

The backend API works properly here but the homepage here doesn't load - using ReactJS.

My all GitHub codes are here inside the develop branch.

Followed this post steps to host the same.

CodePudding user response:

The homepage does not have a proper URL or path defined.

For example, you can go here:

https://mangya.herokuapp.com/administrator/

Or here

https://mangya.herokuapp.com/api

...As they are valid URLs.

Your blank 'homepage' path is not listed so there is no view being hit thus you get the error.

To fix this you need to change your urls.py in MyBlog to look like this:

urlpatterns = [
    path('', [path.to.your.view]),
    path('administrator/', admin.site.urls),
    path('api/', include(router.urls))
]

In Django for anything to be rendered when you hit a URL, you need to have a view defined that renders the template, this is what my example for your urls.py shows.

So for example, if you are trying to run a Vue, React, or any other frontend framework that would rely on an API and Ajax calls to populate a page, you must allow that base page to be rendered by Django as it is the server running your application.

  • Related