I have a django rest api that implements viewsets as highlighted below.
class SubjectViewSet(viewsets.ModelViewSet):
pagination_class = ContentRangeHeaderPagination
queryset = Subject.objects.all()
serializer_class = SubjectSerializer
Similarly, my frontend is based on react-admin here
import React from 'react';
import { Admin, Resource } from 'react-admin';
import simpleRestProvider from 'ra-data-simple-rest';
import { NonIndividualList, NonIndividualCreate, NonIndividualEdit} from './subjects';
const App = () => (<Admin dataProvider=simpleRestProvider('http://localhost:8000/api/v1/coreapp')}>
<Resource name="subject" title="Non-Individuals" list={NonIndividualList}
create={NonIndividualCreate} edit={NonIndividualEdit}/>
</Admin>);
export default App;
In my rest server, under settings.py I have the following settings
APPEND_SLASH = False
Finally, my app/urls.py looks like this
router = DefaultRouter()
router.register(r'api/v1/coreapp/subject', views.SubjectViewSet)
urlpatterns = [(r'^', include(router.urls)),]
Question:
From postman, I can comfortably crud the endpoint
- GET: http://localhost:8000/api/v1/coreapp/subject/,
- POST:http://localhost:8000/api/v1/coreapp/subject/,
- Put: http://localhost:8000/api/v1/coreapp/subject/2/,
- Delete: http://localhost:8000/api/v1/coreapp/subject/1/,
However, my react-admin client doesnot append a trailing slash
Instead, Http-actions Create/Put send the requests to url. Notice the missing trailing backslash?
I have tried to,
1- Set the Append_Slash = True 2- Added a / to the resource name, which simply appends two backslash
<Resource name="subject/"/>
for PUT, notice the additional backslash.
Bottom line is, my server accepts requests whenever they have a trailing backslash.
My react-admin app doesnot append the backslash on requests. Please SO, advise a brother :-)