0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.