URL重定向,如果网址错误

时间:2010-05-08 23:51:04

标签: django django-urls

我的书模型中有这种方法:

    def get_absolute_url(self):
        return "/book/%s/%s/%i/%i/" % ( self.book_title, self.book_editor, self.book_pages, self.id)

所以每本书的网址都是这样的:

example.com/book/the-bible/gesu-crist/938/12/

我希望如果网址中存在错误,那么我会通过在网址末尾使用book.id重定向到真实网址。

例如,如果我去:

example.com/book/A-bible/gesu-crist/938/12/

我将被重定向到:

example.com/book/the-bible/gesu-crist/938/12/

我该怎么做?

1 个答案:

答案 0 :(得分:0)

您可以创建custom HTTP 404 handler

相关问题