Django bootstrap按钮点击后激活active

现在有个需求,就是在导航栏上有若干个按钮,我想实现的功能是当点击某个按钮后修改文字颜色,这样网站会更人性化。现总结方法如下:

index.html:

<ul class="navbar-nav mr-auto">
	<li class="nav-item">
		<a class="nav-link {% if isactive == 'home' %}active{% endif %}" href="{% url 'home' %}">Home</a>
	</li>
	<li class="nav-item">
		<a class="nav-link {% if isactive == 'about' %}active{% endif %}" href="{% url 'about' %}">About</a>
	</li>
</ul>

app.views.py

def home(reqeust):
	isactive = "home"
	return render(request, "home.html", {"isactive":isactive})
	
def about(reqeust):
	isactive = "about"
	return render(request, "about.html", {"isactive":isactive})



MARSGGBO原创





2019-8-12



posted @ 2019-08-12 15:46  marsggbo  阅读(1154)  评论(0编辑  收藏  举报