我是 django 的新手。当 url 类似于http://127.0.0.1:8000/details/music and concerts
为此,我尝试在我的
网址.py
from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('',
url(r'^details/(?P<event_cat>\w{0,50})/$', 'onthemove.views.category'),
)
我的模板 index.html 是
<div class="cat">
{% if latestevents.count > 0 %}
{% for category in latestevents %}
<a href="/details/{{ category.cat }}/">
<div id="per_cat">
<img src="{{STATIC_URL}}/static/images/music.jpg" />
<span>{{category.cat}}</span>
</div></a>
{% endfor %}
{% else %}
<span>none to show</span>
{% endif %}
其中 latestevents 从 views.py 传递为:
def searchget(request):
latestevents = events.objects.all().order_by('id')[:1]
return render_to_response('views/search.html',{'latestevents':latestevents})
但这显示错误:
The current URL, details/Music and Concerts/, didn't match any of these.
他们有什么错误吗?