0
我是Django REST的新手,請幫助,如何僅呈現表單中的某些字段,所以現在我獲取所有字段和相關表格,但是我只需要顯示一些田Django REST如何呈現表單中的選定字段
查看:
class ProFormList(APIView):
renderer_classes = [TemplateHTMLRenderer]
template_name = "accounts/page_user_profile.html"
def get(self, request, id):
account = get_object_or_404(Account, id=id)
serializer = AccountSerializer(account)
return Response({'serializer': serializer, 'account':account})
def post(self, request, id):
account = get_object_or_404(Account, id=id)
serializer = AccountSerializer(account, data=request.data)
if not serializer.is_valid():
return Response({'serializer': serializer, 'account':account})
serializer.save()
return redirect('accounts:profile', id=account.id)
我的HTML:
<div class="tab-pane " id="tab_1_2">
<form role="form" action="{% url 'accounts:proform' id=account.id %}" method="POST">
{% csrf_token %}
{% render_form serializer %}
<div class="form-group">
<div class="margiv-top-10">
<button type="submit" class="btn green"> Save Changes </button>
<button type="" class="btn default"> Cancel </button>
</div>
</div>
使用META:田在串行 – Jerzyk