Django REST Framework URLPathVersioning不起作用

时间:2019-04-25 17:52:31

标签: python django django-rest-framework api-versioning

我按照指南here向我们的API添加了版本控制。 =INDEX('Sheet 2'!B$2:B$6,MATCH(MID('Sheet 1'!A2,FIND(" ",'Sheet 1'!A2)+1,LEN('Sheet 1'!A2)-FIND(" ",'Sheet 1'!A2)),'Sheet 2'!A$2:A$6,0)) 如下所示:

urls.py

但是,当我使用URL from django.conf.urls import url from django.contrib import admin from django.urls import path from api import views urlpatterns = [ url( r'^(?P<version>(v1|v2))/foo/bar', views.foo_bar, ), ] 来访问API时,出现错误消息:

http://localhost:5555/v1/foo/bar

1 个答案:

答案 0 :(得分:2)

您的foo_bar视图很可能不接受参数version

它需要定义为:

def foo_bar(request, version):
    ...