使用 APIView 接收参数

Receiving parameters with APIView

我有这个路由:

   url(r'^article/(?P<article_id>\d+)/', views.ArticleList.as_view())

导致这个函数:

class RSSList(APIView):
    def get(self, request, *args, **kwargs):
        article_id = kwargs.get('article_id')

但是当我尝试查询类似 /article/34

的内容时

我收到这个错误:

TypeError: get() got an unexpected keyword argument 'article_id'

如何将 article_id 传递给 get()?

谢谢

你也可以这样:

def get(self, request, article_id):
   print(article_id) #for >3.2
   print article_id # for 2.7

如果您想将其设为可选:

def get(self, request, article_id=None):