我正在使用 slug 作为 url 的访问点。
http://127.0.0.1:8000/category/blah/ -> blah is the slug.
这是我的网址代码。
url(r'^category/(?P<category>[A-Za-z]\w*)/$', individual_category),
这是我的看法
def individual_category(request, category):
pro = get_object_or_404(Product, username= category) -> (This doesnt seem to work ))
return render_to_response('individual_category.html', {'obs':pro})
这是我的模板
<html>
<body>
<p> The list of products are </p>
<b>{{category}}</b>
{% for items in obs %}
<li>{{items.category}}</li>
<li>{{items.title}}</li>
<img src = "/images/{{items.image}}"</li>
<br>
<br>
{% endfor %}
</body>
</html>