css - url 中的 Django #hashtags

标签 css django

Sooo 我想做的是在 CONTACT 上添加一个链接以重定向到 HOME 并向下滚动到某些内容,但不知道如何在 django 的 url 中传递#。任何帮助表示赞赏。卷轴在家里很好,但无法通过接触使其工作。

网址

path('/#products', HomeView.as_view(), name='products'),

联系.html

<a class="nav-link" href="{% url 'core:products' %}">Products</a>

主页.html

这是在导航栏中

<a class="nav-link" style="cursor: pointer" href='#products'>Products</a>

这是我想要它滚动的地方

<a class="anchor" id="products"></a>

最佳答案

RedirectView 为此:

views.py

from django.views.generic import RedirectView
from django.urls import reverse

class ViewpostRedirectView(RedirectView):
    def get_redirect_url(*args, **kwargs):
        hash_part = "add_data_Modal"  # the data you want to add to the hash part
        return reverse("createpost") + "#{0}".format(hash_part)

urls.py

path('viewpost/', views.createpost, name='createpost'),
path('viewpost/modal/', views.ViewpostRedirectView.as_view(), name='createpost_modal')

更多信息:https://www.kite.com/python/docs/django.views.generic.RedirectView

关于css - url 中的 Django #hashtags,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63467337/

相关文章:

python - 如何在 DRF 中序列化自定义用户模型

php - 使用 dirname 和 img src 在 apache 网络服务器上显示 Logo

css - 为什么我的网站宽度小于我的屏幕分辨率

javascript - 单击显示新 div 的新 div 后如何隐藏当前 div

python - 连接 Django 调试工具栏时出现问题

python - pytest-django:这是用参数测试 View 的正确方法吗?

python - 如何为 django QuerySet 的每个条目添加一些上下文

css - 流动电路动画

html - 在响应式设计中使用 float 定位元素时出现问题

python - 如何使用 python 和 Django 高效导出大型 Excel 文件