django class views how to get model objects code example
Example 1: django create view class
from .forms import CreateArticleForm
from django.views.generic import CreateView
class ArticleCreateView(CreateView):
form_class = CreateArticleForm
template_name = 'articles/create_article.html'
from .views import ArticleCreateView
urlpatterns =[ path('articles/create/', ArticleCreateView.as_view()),]
Example 2: views django
from django.http import HttpResponse
import datetime
def current_datetime(request):
now = datetime.datetime.now()
html = "<html><body>It is now %s.</body></html>" % now
return HttpResponse(html)