这个问题困扰了很久,查了很多的资料,都是1.X版本的Django这里走了好多的弯路。产品经理来写代码还是各种尴尬,基础不扎实。好好打基础,加油。
1.view文件
from django.shortcuts import render
from http.client import responses
from django.http import HttpResponse, HttpResponseRedirect
# Create your views here.
def info(request):
if request.method=='GET':
token=request.GET.get('token')
return HttpResponse("token:" + token )
2.url文件编写,导入re_path 正则表达式
from django.contrib import admin
from django.urls import path,re_path
from users import views
urlpatterns = [
path('admin/', admin.site.urls),
re_path('info/$', views.info),
]
image.png
3.Postman测试
访问的URL地址:
http://127.0.0.1:8000/info/?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo2LCJ1c2VybmFtZSI6InRlc3QzIiwiZXhwIjoxNTQ3MjQxMjg2LCJlbWFpbCI6IiJ9.fGKsGJR4BkAff-jr4XLaLIW2CHuOwxhzr1ebpTW2Dwk
image.png
网友评论