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/