1
What is wrong in this code? I use the correct
app_name
andname
.
The path you use does not link to a view: it is a path that contains a lot of subpaths, all generated by the DefaultRouter
.
You are using a router, this means that it will create different paths that will each have a specific name. These are documented in the documentation for the DefaultRouter
[drf-doc].
You thus can visit this with:
from django.shortcuts import redirect
@api_view(['POST'])
@permission_classes([IsAuthenticated])
def bump(request, pk):
product = get_object_or_404(Product, pk=pk)
product.bumps.add(request.user)
return redirect('products:product-detail', pk)
Source:stackexchange.com