【发布时间】:2023-03-19 03:38:01
【问题描述】:
我是 django 开发的新手。我正在开发一个 API,我在其中从客户端(移动应用程序)发送数据,并且这些数据将使用 django 存储在数据库中。如果我查询数据,则应从数据库中获取数据。数据库最好是 postgres/mysql DB。我已经编写了部分代码,但卡住了如何继续。如果有人能指导我如何继续,我将不胜感激。
from django.shortcuts import render
from rest_framework.views import APIView
from django.http import Http404
from django.http import JsonResponse
from django.core import serializers
from django.conf import settings
import json
# Create your views here.
@api_view(["POST"])
def getIdealWeight(heightData):
try:
height=json.loads(heightData.body)
weight=str(height*10)
return JsonResponse("the ideal weight is:"+weight+" kg.",safe=False)
except ValueError as e:
return Response(e.args[0],status.HTTP_400_BAD_REQUEST)
【问题讨论】:
标签: python postgresql api web-services django-rest-framework