开发者

Problem with get_abosulute_url when using @models.permalink decorator in django

开发者 https://www.devze.com 2023-02-26 19:22 出处:网络
Having some trouble using the permalink decorator when defining get_absolute_url for one of my models that i just cant seem to figure out!

Having some trouble using the permalink decorator when defining get_absolute_url for one of my models that i just cant seem to figure out!

Im calling object.get_absolute_url() but it doesn't seem to return anything whilst using the permalink decorator.

model.py

@models.permalink
def get_absolute_url(self):
    return ('view_gig', (), {
        'id': self.id,
        'token': self.token})

urls.py

(r'^gigs/(?P<id>[\d+])/(?P<token>[\w+])(/?)', view_gig),

template

<a href="{{ gig.get_absolute_url }}">View More Info</a>

stragely if i开发者_如何学Go remove

@models.permalink

from the get_absolute_url() definition its returns

('view_gig', (), {'id': self.id, 'token': self.token})

in the url in the template.

this is driving me insane thanks in advance!!


I think you need to use:

(r'^gigs/(?P<id>\d+)/(?P<token>[\w-]+)(/?)', view_gig),


What if you try (r'^gigs/(?P<id>[\d+])/(?P<token>[\w+])', view_gig), ?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号