5

I have this routing:

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

which leads to this function:

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

But when I try to query something like /article/34

I get this error:

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

How can I pass article_id to get()?

Thank you

kambi
  • 3,291
  • 10
  • 37
  • 58
  • 3
    `RSSList` is not the problem, you are missing `*args, **kwargs` somewhere else. Maybe in `ArticleList` instead of `RSSList`? – hoefling Nov 06 '17 at 12:42
  • You're using `ArticleList` class in your routing! But you're fetching `article_id` inside of `RSSList` class instead! – AbdolHosein Jul 05 '19 at 20:25

1 Answers1

10

You can get like this also:

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

If you want to make it optional:

def get(self, request, article_id=None):
Taufiq Rahman
  • 5,600
  • 2
  • 36
  • 44
Man Programmer
  • 5,300
  • 2
  • 21
  • 21