3

I'm just getting started to Django Rest Framework and i created my first endpoints. Now, i'm trying to add filtering to my URLS but there are two things i don't understand yet:

  1. I created the following route: router.register(r'endpoint', views.myView, basename='myView'). When i try to filter on my browser like the following http://127.0.0.1:8000/api/endpoint?&user=TEST, i will get redirected to http://127.0.0.1:8000/api/endpoint/?&user=TEST. Why is there a slash before the ??

  2. What is the difference between using router.register and a standard view on my urlpatterns like i would do in Django?

1

1 Answer 1

3
  1. Because the default value of APPEND_SLASH is True and hence the redirection.

  2. The DRF routers will generate appropriate URL patterns depending on which type of router (SimpleRouter or DefaultRouter ) you are using. Highy recommend using along with the DRF ViewSets

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

2 Comments

Thank you a lot for your answer, it's very clear. What happens if i set APPEND_SLASH to False? Is it a bad practice?
I would like to set the APPEND_SLASH=True (the default setup) and I would not define any end-points without a trailing slash

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.