![]() ![]() The complete list of base_template options and their associated style options is listed below. Profile = get_object_or_404(Profile, pk=pk) Views.py: from django.shortcuts import get_object_or_404įrom my_ import Profile The following view demonstrates an example of using a serializer in a template for viewing and updating a model instance: Serializers may be rendered as forms by using the render_form template tag, and including the serializer instance as context to the template. Views.py: from my_ import Profileįrom rest_framework.renderers import TemplateHTMLRendererįrom rest_framework.response import Response Here's an example of a view that returns a list of "Profile" instances, rendered in an HTML template: Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and. The StaticHTMLRender class expects the response to contain a string of the pre-rendered HTML content.īecause static HTML pages typically have different behavior from API responses you'll probably need to write any HTML views explicitly, rather than relying on the built-in generic views. Complete reference documentation for the Stripe API. The TemplateHTMLRenderer class expects the response to contain a dictionary of context data, and renders an HTML page based on a template that must be specified either in the view or on the response. In order to return HTML responses you'll need to use either TemplateHTMLRenderer, or StaticHTMLRenderer. Additionally, serializers can be used as HTML forms and rendered in templates. REST framework is suitable for returning both API style responses, and regular HTML pages. ![]()
0 Comments
Leave a Reply. |