我有一个版本为1.2.4的django应用程序并更新为1.6.5,我已经将很多网址结构从{% url name %}
更改为{% url 'name' %}
但是在一个地方它导致了我以下
回溯
File "/home/user/.virtualenvs/proj/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in _populate
278. lookup_str = callback.__module__ + "." + callback.__name__
Exception Type: TypeError at /store/
Exception Value: coercing to Unicode: need string or buffer, instancemethod found
导致错误的模板代码
<ul id="product-tabs">
<li class="passive"><span><a href={% url "webstore_new" passive_year %}>{{ passive_year }}</a></span></li>
<li><span><a href={% url "webstore_new" active_year %}>{{ active_year }}</a></span></li>
</ul>
那么上面模板代码中的url标记有什么问题?
修改
views.py
def products(request, year=None):
current_site = Site.objects.get_current()
present_year = datetime.datetime.now().year
if Products.objects.filter(year__contains = present_year+1):
active_year = present_year + 1
passive_year = present_year
else:
active_year = present_year
passive_year = present_year - 1
products = Products.objects.filter(Q(site=current_site, year=year))
.....
......
.......
variables = {
'obj': products,
'active_year': active_year,
'passive_year': passive_year,
}
response = RequestContext(request, variables)
return render_to_response('new/store/webstore.html', response)