25π
The URL parameters are available in self.kwargs
.
From the documentation:
Filtering against the URL
Another style of filtering might involve restricting the queryset based on some part of the URL.
For example if your URL config contained an entry like this:
url('^purchases/(?P<username>.+)/$', PurchaseList.as_view()),
You could then write a view that returned a purchase queryset filtered by the username portion of the URL:
class PurchaseList(generics.ListAPIView): serializer_class = PurchaseSerializer def get_queryset(self): """ This view should return a list of all the purchases for the user as determined by the username portion of the URL. """ username = self.kwargs['username'] return Purchase.objects.filter(purchaser__username=username)
2π
You have to use lookup_field
in your views to get product_id
and the view should not belongs to any model. Here I already answer a question like yours using django rest framework to return info by name
Hope this will help to solve your problem.
- Django returning "CSRF verification failed. Request aborted. " behind Nginx proxy locally
- Append to site <title> in Django template using block.super
- "Upload" a file from django shell
- Uploading Large files to AWS S3 Bucket with Django on Heroku without 30s request timeout
0π
This is my approach:
Update URL:
url(r'^product-configuration$', views.ProductDetailConfiguration, name='product-configuration'),
In view.py:
class ProductDetailConfiguration(viewsets.ModelViewSet):
lookup_field = 'product_id'
serializer_class = ProductConfigurationSerializer
def retrieve(request, product_id=None, *args, **kwargs):
queryset = self.get_queryset()
# Filter with produc_id
# print(product_id)
# Return Response
- Catch exception on save in Django admin?
- Merge two fields in one in a Django Rest Framework Serializer
- Idiomatic python β property or method?
- TypedChoiceField or ChoiceField in Django
- How to prevent user to access login page in django when already logged in?
-1π
You can get the data from the request url by :-
data_dict = self.request.data
This will return a dictionary of all the parameters of the request url.
You can use the parameter name as the key