ApathyBear
ApathyBear

Reputation: 9595

get_absolute_url() django docs example returns syntax error

I have this model:

class Invite(models.Model):
    user = models.OneToOneField(User)
    cookie = models.SlugField()
    token = models.SlugField()

    def __unicode__(self):
        return u"%s's invite" % (self.user)

    def get_absolute_url(self):
        return (reverse('invite'), args=[self.token])

The final line, return (reverse('invite'), args=[self.token]), returns a syntax error. When I remove the args= part, it seems to work fine though.

I have three questions regarding this:

  1. Why is arg= in this example returning a syntax error while the django docs uses a similiar example here.

  2. How am I supposed to successfully key into this list/check the contents of the list without assigning it a name?

  3. Does return require () to work with more than one variable? Since im using python 2.7.5 wouldn't a simple , suffice?

Thanks!

Upvotes: 0

Views: 258

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599620

You have the closing parenthesis in the wrong place. args is an argument to reverse.

return (reverse('invite', args=[self.token]))

Upvotes: 2

Related Questions