class django.views.generic.edit.UpdateView
A view that displays a form for editing an existing object, redisplaying the form with validation errors (if there are any) and saving changes to the object. This uses a form automatically generated from the object’s model class (unless a form class is manually specified).
Ancestors (MRO)
This view inherits methods and attributes from the following views:
django.views.generic.detail.SingleObjectTemplateResponseMixindjango.views.generic.base.TemplateResponseMixindjango.views.generic.edit.BaseUpdateViewdjango.views.generic.edit.ModelFormMixindjango.views.generic.edit.FormMixindjango.views.generic.detail.SingleObjectMixindjango.views.generic.edit.ProcessFormViewdjango.views.generic.base.View
Attributes
-
template_name_suffix -
The
UpdateViewpage displayed to aGETrequest uses atemplate_name_suffixof'_form'. For example, changing this attribute to'_update_form'for a view updating objects for the exampleAuthormodel would cause the defaulttemplate_nameto be'myapp/author_update_form.html'.
-
object -
When using
UpdateViewyou have access toself.object, which is the object being updated.
Example myapp/views.py:
from django.views.generic.edit import UpdateView
from myapp.models import Author
class AuthorUpdate(UpdateView):
model = Author
fields = ['name']
template_name_suffix = '_update_form'
Example myapp/author_update_form.html:
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Update" />
</form>
Please login to continue.