📜  重定向 django 中的 slug - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:12.613000             🧑  作者: Mango

代码示例1
from django.shortcuts import get_object_or_404, redirect

def post(request, slug, post_id):
    obj = get_object_or_404(Post, pk=post_id)
    if obj.slug != slug:
        return redirect('post', slug=obj.slug, post_id=obj.pk)