0

I am using the Rest Framework in Django. I use the browsable API feature to auto-generate forms (for http POST,PUT etc) based on the Serializer for the given API.

My problem is that I am now creating an API with a nested serializer to receive a list of dictionaries in a known format. The declaration of the the nested serializer within the main serializer is:

customer_hosts = CustomerNetworkHostSerializer(many=True, required=True)

My API inherits generic's CreateAPIView form rest_framework. I also set the serializer_class to my main serializer.

The API works fine with the serializer if I manually send the required json object using a http post but I have no way to send the values for that variable using a browser with the auto-generated form. The variable with the nested serializer does not show up at all.

So what I am looking for is away to get the browsable_api working with a nested dynamic serializer if is possible?

1 Answer 1

1

I can't find the exact RFC reference but the limitation here is HTTP. HTTP forms cannot natively encode nested data structures (both application/x-www-form-urlencoded and multipart/form-data rely on flat key-value formats)

one approach here might be to create a page that uses the browsableapi renderer to render those parts of your form that are possible and then implement your own logic to
- render the nested serializer
- format the form and contents into other language for submission to your end point (e.g. convert the html form and contents to json: Convert form data to JavaScript object with jQuery)

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.