简体   繁体   English

Django REST Framework URLPathVersioning不起作用

[英]Django REST Framework URLPathVersioning not working

I followed the guide here to add versioning to our API. 我按照此处的指南将版本添加到我们的API中。 This is what the urls.py looks like: 这是urls.py样子:

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,
    ),
]

However, when I hit my API with the URL http://localhost:5555/v1/foo/bar I get an error: 但是,当我使用URL http://localhost:5555/v1/foo/bar API时,出现错误消息:

TypeError at /v1/foo/bar
foo_bar() got an unexpected keyword argument 'version'

Most likely your foo_bar view does not accept the argument version . 您的foo_bar视图很可能不接受参数version

It needs to be defined as: 它需要定义为:

def foo_bar(request, version):
    ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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