【发布时间】:2015-09-13 16:12:45
【问题描述】:
我有一个小型简历网站,在点击反向 URL 时没有呈现不同的模板。
站点/脚本/模板/脚本/index.html:
<p>were at main</p>
<a href="{% url 'scripts:python' %}">python</a>
<br/>
<a href="{% url 'scripts:bash' %}">bash</a>
这些链接 'python' 和 'bash' 在 URL 栏中有效,它们将我们带到 localhost:scripts/bash/ 和 localhost:scripts/python/,但显示的网页完全相同(index.html 或 localhost :scripts/)
网站/脚本/urls.py:
from django.conf.urls import patterns, include, url
from scripts import views
urlpatterns = patterns('',
url(r'$', views.index, name='index'),
url(r'python/$', views.access_python, name='python'),
url(r'bash/$', views.access_bash, name='bash'),
)
网站/脚本/views.py:
from django.shortcuts import render
def index(request):
return render(request, 'scripts/index.html')
def access_python(request):
return render(request, 'scripts/python.html')
def access_bash(request):
return render(request, 'scripts/bash.html')
site/urls.py(带有 settings.py 的主文件夹):
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'scripts/', include('scripts.urls', namespace='scripts')),
)
单击“bash”应该检索:
站点/脚本/模板/脚本/bash.html:
<p>we're at bash</p>
为什么反向查找会到达正确的 URL,但不会调用该 URL 模式所需的关联视图?谢谢
【问题讨论】:
标签: python django django-urls