django updateview class
###### views.py #####
from .forms import CreateArticleForm
from django.views.generic import CreateView
class ArticleCreateView(CreateView):
form_class = CreateArticleForm
template_name = 'articles/create_article.html'
###### urls.py ######
from .views import ArticleCreateView
urlpatterns =[ path('articles/create/', ArticleCreateView.as_view()),]
4.13
8
###### views.py #####
from .models import Article
from .forms import UpdateArticleForm
from django.views.generic import UpdateView
class ArticleUpdateView(UpdateView):
model = Article
form_class = UpdateArticleForm
template_name = 'articles/create_article.html'
###### urls.py ######
from .views import ArticleUpdateView
urlpatterns =[
path('articles/<int:pk>/update/', ArticleUpdateView.as_view()),]
# pk is default value (for primary key of id of an instance of object
Thank you!
8
0
Are there any code examples left?
New code examples in category Python