Reputation: 192
I have the following urlpatterns configured for my Django app. This rule will route to http://localhost:8000/profile/.
urlpatterns = [
path("profile/", test_frontend_views.profile),
]
The views code:
def profile(request):
return render(request, 'frontend/Profile_temp_master.html')
Within my React components that are dynamically creating HTML for the template, I am making requests to my Django backend API with the following scheme:
fetch("api/profile", requestOptions).then(..).then(..)
However, rather than this request routing to http://localhost:8000/api/profile/, it is routing to http://localhost:8000/profile/api/profile/ which is not a valid endpoint and returns and error. How can I solve this so that the URL routes to the correct endpoint?
Upvotes: 0
Views: 219
Reputation: 16309
You need to do
fetch("/api/profile", requestOptions).then(..).then(..)
with a /
at the start to make it absolute. Otherwise it will be relative to the current url.
Upvotes: 1