gpt4 book ai didi

django - 如何使重定向 View 跳转到django中的一个部分

转载 作者:行者123 更新时间:2023-12-05 03:03:33 25 4
gpt4 key购买 nike

所以我的模板中有一个部分:

<div id='comments'>Comments go here</div>

现在我想让我的 django 重定向功能重定向到这个页面并跳转到这个 div id。

return redirect('post_detail', post.slug)

我在哪里输入 '/#comments' 让它在重定向时跳转到那里

最佳答案

redirect (reverse('post_detail', post.slug) + '#comments')

https://docs.djangoproject.com/en/2.1/topics/http/shortcuts/#examples

关于django - 如何使重定向 View 跳转到django中的一个部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53788600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com