django bootstrap dropdown not working

折月煮酒 提交于 2021-02-11 18:24:12

问题


I am building website based in django. I am using bootstrap dropdown in navbar to collapse navbar on low resolution i.e. mobile view, but on clicking button navbar not getting dropdown.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>

<nav id="main-menu" class="navbar" role="navigation">
        <div class="navbar-header">
            <button type="button" class="btn btn-navbar navbar-toggle" data-toggle="collapse"
                    data-target=".navbar-cat-collapse">
                <span class="sr-only">Toggle Navigation</span>
                <i class="fa fa-bars"></i>
            </button>
        </div>
        <div class="collapse navbar-collapse navbar-cat-collapse">
            <ul class="nav navbar-nav">
                <li><a href="{% url 'home_page' %}">Home</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Pages</a></li>
                <li><a href="{% url 'contact_page' %}">Contact Us</a></li>
            </ul>
        </div>
    </nav>

回答1:


as far as I know bootstrap uses its own javascript library for doing animated stuff like collapsing and so on. so you need to import their js file as well. put this line below your first <script> tag

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

note that because bootstrap js library uses jquery, you must put this line below importing jquery. otherwise it won't work.



来源:https://stackoverflow.com/questions/41415746/django-bootstrap-dropdown-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!