Create a restful Djangorest-framework of the project up and running

# Background: The recent write a demo, Django write something faster, acquire DJango try.

First create a project

django-admin startproject HelloWorld

Inside the project to create a new app

django-admin startapp app1

app1 inside view change change it

from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
# Create your views here.
# https://www.cnblogs.com/huchong/p/8450355.html
class TestView(APIView):
    
    def get(self,request):
        t_num = request.GET.get("t_num")
        print("捕获到参数", t_num)
        return Response('GET请求,响应内容')

Then add to urls

from django.contrib import admin
from django.urls import path
from kingdeeScreen.views import TestView
urlpatterns = [
    path('admin/', admin.site.urls),
    path('hello/', TestView.as_view()),
]

go inside with setting

INSTALLED_APPS = [
    'rest_framework',
]

Then you can use to test the postman.

 

Guess you like

Origin www.cnblogs.com/daysn/p/11358033.html