简体   繁体   中英

Django send request to API, where URL is Dynamic

How the URL looks like

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

Here the POST_NUMBER is dynamic, how to send a request to the Page like this http://127.0.0.1:8080/api/post/14 Where 14 is the post number Here is my URL Pattern

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

Here is the PostView

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

My error is PostView() got an unexpected keyword 'int'

try this

in urls

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

in views

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

refer this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM