_reverse_with_prefix() argument after * must be an iterable, not int

后端 未结 2 2419
慢半拍i
慢半拍i 2021-02-20 18:32

I have used Django\'s reverse multiple times in the past but getting this error today which doesn\'t seem intuitive enough to debug:

TypeError: _rev         


        
2条回答
  •  感动是毒
    2021-02-20 19:25

    As mentioned in this comment, putting a comma at the end of the args tuple fixes it.

    scores_url = reverse('get_scores', args=(obj.pk,))
    

    (As mentioned in this SO answer, trailing comma is required for single-item tuples to disambiguate defining a tuple from an expression surrounded by parentheses)

    Alternatively, as mentioned in the docs, using a list would work fine:

    scores_url = reverse('get_scores', args=[obj.pk])
    

提交回复
热议问题