xxxxxxxxxx
class AuthorCreateView(CreateView):
form_class = AuthorForm
template_name = 'author_new.html'
success_url = 'success'
xxxxxxxxxx
from django.http import HttpResponse #last line below allows MyView.get
# to return an HttpResponse object
from django.views import View #View is to become the parent class of MyView
class MyView(View):
''' View is the parent class that provides method as_view() to MyView '''
def get(self, request, *args, **kwargs):
return HttpResponse('Hello, World!')
xxxxxxxxxx
In Django, the CreateView class is a class-based view that provides
an easy way to handle the creation of new objects. It abstracts the
common functionality required for creating an object, such as rendering
a form, validating the submitted data, and saving the object to the
database.
It includes form validation logic, ensuring that the submitted data is
valid before saving the object.
xxxxxxxxxx
###### 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()),]