Skip to content

Instantly share code, notes, and snippets.

@licensed
Forked from flavianmissi/django_update_view.py
Created July 13, 2018 18:06
Show Gist options
  • Save licensed/ee77630329156ace7b0f9e6ad7c3a6a0 to your computer and use it in GitHub Desktop.
Save licensed/ee77630329156ace7b0f9e6ad7c3a6a0 to your computer and use it in GitHub Desktop.
Django UpdateView sample
#views.py
from django.views.generic import UpdateView
class UpdateBook(UpdateView):
model = Book
form_class = BookForm
template_name = 'create_form.html'
success_url = '/books/'
#urls.py
from django.conf.urls import *
from library.views import UpdateBook
urlpatterns = patterns('',
url('^update_book/(?P<pk>[\w-]+)$', UpdateBook.as_view(), name='update_book'),
)
# you MUST pass a pk or slug param to this view
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment