Django18初体验
1413 浏览 5 years, 11 months
25 URL NAMES AS LINKS
版权声明: 转载请注明出处 http://www.codingsoho.com/在trydjango18目录下面创建文件views.py
添加about函数
from django.shortcuts import render
def about(request):
return render(request, "about.html", {})
在urls.py中添加url
urlpatterns = patterns('',
url(r'^about/$', 'trydjango18.views.about', name='about'),
)
在navbar.html添加about和contact相关的内容
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<!--
<li class="active"><a href="#">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
-->
<li class="active"><a href="{% url 'home' %}">Home</a></li>
<li><a href="{% url 'about' %}">About</a></li>
<li><a href="{% url 'contact' %}">Contact</a></li>
可以用{% url '???' %}来代替显式的url