我正在尝试 url 模板标签并偶然发现一个问题:
Caught NoReverseMatch while rendering: Reverse for ''location'' with arguments
'(<City: New York>,)' and keyword arguments '{}' not found.
在我的模板文件中,我有:
{% url 'location' city_name=city.name %}
网址.py
url(r'^location/(?P<city_name>.*)/$', CityView.as_view(), name="location"),
模型.py
def get_absolute_url(self):
return "/location/%s" % self.name