URLS:
from django.contrib import admin from django.urls import path from cmbd import views urlpatterns = [ path('admin/', admin.site.urls), path('home/', views.Home.as_view()), ]
VIEWS:
from django.shortcuts import render,redirect from django.shortcuts import HttpResponse # Create your views here. from django.views import View class Home(View): def dispatch(self, request, *args, **kwargs): print('before') result = super(Home,self).dispatch(request,*args,**kwargs) print('after') return result def get(self,request): print('in get') return render(request,'home.html') def post(self,request): print('in post') return render(request,'home.html')
TEMPLATES下home.html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div> <form action="/home/" method="post"> <input type="text" name="user" /> <input type="submit" value="submit" /> </form> </div> </body> </html>