1.Yuketang.objects.filter函数(其他键值)

2.Yuketang.objects.get函数(主键)

键__contains(包含函数 类似于 Select From 操作中的 Like %%)

from django.shortcuts import render
from django.forms.models import model_to_dict
from django.views.decorators.http import require_http_methods
from django.core import serializers
from django.http import JsonResponse
import json

from .models import Yuketang
Create your views here.
@require_http_methods([“GET”])
def query(request):
timu = []
daan = []
question = request.GET.get(‘question’)
ykt = Yuketang.objects.filter(timu__contains=question).values()
ykt = list(ykt)[0]
# 转为字典类型
response = {
“timu”: ykt[“timu”],
“xuanxiang”: ykt[“xuanxiang”],
“daan”: ykt[“daan”],
“jiexi”: ykt[“jiexi”]
}
return JsonResponse(ykt,json_dumps_params={‘ensure_ascii’:False})

Categories:

Tags:

No responses yet

发表评论

邮箱地址不会被公开。 必填项已用*标注