【问题标题】:URL redirection if wrong url如果 URL 错误,则 URL 重定向
【发布时间】:2010-05-08 23:51:04
【问题描述】:

我的书本模型中有这个方法:

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

所以每本书的url都是这样的:

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

如果 url 中有错误,我希望通过在 url 末尾使用 book.id 重定向到真实的 url。

例如,如果我去:

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

我将被重定向到:

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

我该怎么做?

【问题讨论】:

    标签: django django-urls


    【解决方案1】:

    你可以创建custom HTTP 404 handler

    【讨论】:

      猜你喜欢
      • 2018-01-06
      • 2012-09-12
      • 1970-01-01
      • 1970-01-01
      • 2012-11-01
      • 1970-01-01
      • 2015-04-12
      • 2016-03-23
      • 1970-01-01
      相关资源
      最近更新 更多