Django基础---6,视图

配置网站白名单

ALLOWED_HOSTS = ['*']
LANGUAGE_CODE = 'zh-hans'

 

 然后我们首先在api下增加一个.py文件

文件里面导入

from django.views.generic import View
from django.http import JsonResponse,HttpResponse

class Xiaotaozi(View):
def get(self,request,name,age):
return HttpResponse('my name is {},age is {}'.format(name,age))


class Xiaotao(View):
def get(self,request):
# print(dir(request))
name=request.GET.get('name','') #把接口传入的值进行赋值
age = request.GET.get('age',10)
return HttpResponse('my name is {},age is {}'.format(name,age))

 

 编写我们的路由

 

 页面访问

 

posted @ 2022-04-24 18:01  沫笙*  阅读(19)  评论(0编辑  收藏  举报