首页 > 解决方案 > 导航栏按钮一键失效

问题描述

我创建了博客表单......突然我注意到导航栏/菜单栏中的博客按钮有问题。单击“博客”按钮后,它会变得功能失调。那就是我只能点击一次。

如果我输入网址“..../blog”,我可以访问该页面。

我尝试在 blog.url 之前添加我的应用程序名称,因为我有一些线程提出了它。它没有用。我删除了迁移,从头开始再次创建博客应用程序......同样的想法发生了。我可以假设它与 project/urls.py 或菜单栏有关。我重新输入了所有代码......我仍然有这个问题。

与往常一样,我们非常感谢任何输入!

这是一个 Youtube 短片,可以更好地可视化我的问题。 blogBu​​tton 问题 以下是一些代码以防万一:

博客/urls.py:

from django.urls import path
from .views import (
    PostListView,
    PostDetailView,
    PostCreateView,
    PostUpdateView,
    PostDeleteView
)
from . import views


urlpatterns = [
    path('', PostListView.as_view(), name='blog_index'),
    path('post/<int:pk>/', PostDetailView.as_view(), name='post_detail'),
    path('post/new/', PostCreateView.as_view(), name='post-create'),
    path('post/<int:pk>/update/', PostUpdateView.as_view(), name='post-update'),
    path('post/<int:pk>/delete/', PostDeleteView.as_view(), name='post-delete'),
    path("<category>/", views.blog_category, name="blog_category"),

项目/urls.py:

path('accounts/', include('django.contrib.auth.urls')),
    path('blog/', include('blog.urls')),
    path('about/', include('about.urls'))

导航栏.html:

博客
                    <li class="nav-item mx-0 mx-lg-1"><a class="nav-link py-3 px-0 px-lg-3 js-scroll-trigger {% if request.path == contact_url %} active {%endif%}" href="{{ contact_url }}">Contact</a></li>
                    {% if user.is_authenticated %}

视图.py:

    class PostListView(ListView):
        model = Post
        template_name = 'blog/blog_index.html'  # <app>/<model>_<viewtype>.html
        context_object_name = 'posts'
        ordering = ['-created_on']

blog_index.html:
  ,

标签: cssbootstrap-4django-formsdjango-templates

解决方案


推荐阅读