Django 向 API 发送请求,其中 URL 是动态的

Django send request to API, where URL is Dynamic

URL 的样子

 http://<IP_ADDR>:<PORT>/api/post/<POST_NUMBER>

这里的POST_NUMBER是动态的,如何像这样向页面发送请求 http://127.0.0.1:8080/api/post/14 其中 14 是 post 数字 这是我的 URL 模式

path('api/post/<int>', views.PostView, name="Post")

这是 PostView

def PostView(request,POST_NUMBER = 0):
       print(POST_NUMBER)

我的错误是 PostView() 得到了一个意外的关键字 'int'

试试这个

在网址中

path('api/post/<post_number>', views.PostView, name="Post") 
or 
path('api/post/<int:post_number>', views.PostView, name="Post")

观看次数

def PostView(request,post_number = 0):
       print(post_number)

参考this