django의 CBV 및 FBV

886 단어
urls.py ------> views.py
FBV 생략
CBV
urls.py
from django.conf.urls import url
from django.contrib import admin
from app01 import views

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^home/', views.Home.as_view(), name="home"),
]

views.py
from django.shortcuts import render, redirect
from django.views import View
# Create your views here.


class Home(View):

    #    get  post   ,   
    def dispatch(self, request, *args, **kwargs):
        res = super(Home, self).dispatch(request, *args, **kwargs)
        return res

    #     get
    def get(self, request):
        print 'get'
        return render(request, 'index.html')

    #submit(post)   post
    def post(self, request):
        print 'post'
        return redirect('/home/')

좋은 웹페이지 즐겨찾기