From b5f986abddad0d3559052c63761ec3d0a68ab4f8 Mon Sep 17 00:00:00 2001 From: "Sean C. Farley" Date: Tue, 10 Apr 2012 12:23:06 -0400 Subject: [PATCH] Avoid unbound form for GET instance Do not attempt to get an unbound form for an instance using a GET method. This results in the same issue as getting a generic form where an explicit form must be provided for an instance obtained using the GET method. --- djangorestframework/renderers.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/djangorestframework/renderers.py b/djangorestframework/renderers.py index e40865b62..a72ebaf11 100644 --- a/djangorestframework/renderers.py +++ b/djangorestframework/renderers.py @@ -244,18 +244,20 @@ class DocumentingTemplateRenderer(BaseRenderer): except Exception: form_instance = None - # If we still don't have a form instance then try to get an unbound form - if not form_instance: - try: - form_instance = view.get_bound_form(method=method) - except Exception: - pass + # Forms for the GET method must be explicit, so do not get an unbound + # form nor create a generic form for this instance. + if method != 'get': + # If we still don't have a form instance then try to get an unbound form + if not form_instance: + try: + form_instance = view.get_bound_form(method=method) + except Exception: + pass - # If we still don't have a form instance then try to get an unbound form - # which can tunnel arbitrary content types. Forms for the GET method - # must be explicit, so do not create a generic form. - if not form_instance and method != 'get': - form_instance = self._get_generic_content_form(view) + # If we still don't have a form instance then try to get an unbound form + # which can tunnel arbitrary content types. + if not form_instance: + form_instance = self._get_generic_content_form(view) return form_instance