0

I'm new in django development. I m developing an API in which i am sending data from client side (mobile app) and this data is to be stored in a database using django. And if I query the data the data should be fetched from the DB. Database is preferably postgres/mysql DB. I have written some part of the code but stuck how to proceed. I'll appreciate if someone can guide me how to proceed.

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)
0

1 Answer 1

1

Judging from the code, I'll advice you start from the very beginning of DRF Tutorials and cover a great part of it before going further with your project. After the quickstart, you should visit the individual parts dedicated to the major concepts like serializers, views, etc. Jumping straight to the project without having a fair knowledge of the framework will make it difficult to achieve what you want.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.