【Django进阶】

Django路由映射FBV 和 CBV

django中请求处理方式有2种:FBV(function base views) 和 CBV(class base views),换言之就是一种用函数处理请求,一种用类处理请求。

FBV

# url.py
from django.conf.urls import url, include
from mytest import views
 
urlpatterns = [
    url(r‘^index/‘, views.index),
]

# views.py
from django.shortcuts import render
 
 
def index(req):
    if req.method == ‘POST‘:
        print(‘method is :‘ + req.method)
    elif req.method == ‘GET‘:
        print(‘method is :‘ + req.method)
    return render(req, ‘index.html‘)
View Code

相关文章:

  • 2022-01-09
  • 2021-10-12
  • 2021-07-01
猜你喜欢
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2021-06-12
  • 2022-12-23
  • 2021-07-03
相关资源
相似解决方案