我想动态地向urlpattern添加一个id,并将该id打印到我的服务器上。例如,在http://127.0.0.1:8000/experience/3上,我想将3打印到我的服务器上
from django.contrib import admin
from django.urls import path,include
from core.views import TestView
from core.views import ExperienceView
from core.views import ProjectView
from rest_framework.authtoken.views import obtain_auth_token
urlpatterns = [
path('experience/<str:id>', ExperienceView.as_view(),name='experience'),
]
class ExperienceView(APIView):
...
def delete(self,request,*args,**kwargs,id):
connection = sqlite3.connect('/Users/lambda_school_loaner_182/Documents/job-search-be/jobsearchbe/db.sqlite3')
cursor = connection.cursor()
req = request.data
print(id)
return Response(data)
url参数被传递给
args
和kwargs
,在这种情况下,您可以从kwargs
获取对象id
相关问题 更多 >
编程相关推荐