在我的模板中,我为这些文本文章对象添加了网址:
<a href="{{texto.get_absolute_url}}">Text</a>
我的文本模型对象的get_absolute_url
方法在models.py
中定义如下:
def get_absolute_url(self):
return reverse('viva.views.texto_completo', kwargs = {'anno': self.fecha_cr.strftime('%Y'),
'mes': self.fecha_cr.strftime('%m'),
'dia': self.fecha_cr.strftime('%d'),
'slug': self.slug})
和urls.py
中的相关urlpattern是这样的:
urlpatterns = patterns('',
...
url(r'^(?P<anno>\d{{4}})/(?P<mes>\d{{2}})/(?P<dia>\d{{2}})/(?P<slug>[-\w]+)/$', texto_completo),
)
Django给我一个NoReverseMatch错误:
Reverse for 'viva.views.texto_completo' with arguments '()' and keyword arguments '{'anno': '2015', 'dia': '12', 'mes': '06', 'slug': u'jacarandas-walk-johannesburgo'}' not found. 1 pattern(s) tried: ['(?P<anno>\\d{{4}})/(?P<mes>\\d{{2}})/(?P<dia>\\d{{2}})/(?P<slug>[-\\w]+)']
这看起来很奇怪,因为以前的版本运行得很好。在工作版 get_absolute_url
中定义为:
def get_absolute_url(self):
some logic to figure out 'tema' value
...
return reverse('viva.views.texto_completo', kwargs = {'tema': tema,
'anno': self.fecha_cr.strftime('%Y'),
'mes': self.fecha_cr.strftime('%m'),
'dia': self.fecha_cr.strftime('%d'),
'slug': self.slug})
,模式是这样的:
urlpatterns = patterns('',
...
url(r'^(?P<tema>[-\w]{{1,{l1}}})/(?P<anno>\d{{4}})/(?P<mes>\d{{2}})/(?P<dia>\d{{2}})/(?P<slug>[-\w]+)/$'.format(l1=settings.MAX_LENGTH_TEMA), texto_completo),
)
现在我似乎无法让新版本发挥作用。是什么给了什么?
答案 0 :(得分:3)
由于您不再使用SELECT * FROM developer WHERE username='xxx@xxxxx.xx'
2015-06-13T06:20:05.241Z log event: info -- "ControlConnection"
2015-06-13T06:20:05.241Z log event: info -- "ControlConnection"
2015-06-13T06:20:05.242Z log event: info -- "Connection"
2015-06-13T06:20:05.243Z log event: verbose -- "Connection"
2015-06-13T06:20:05.243Z log event: verbose -- "Connection"
2015-06-13T06:20:05.244Z log event: verbose -- "Connection"
2015-06-13T06:20:05.245Z log event: verbose -- "Connection"
2015-06-13T06:20:05.246Z log event: info -- "Connection"
2015-06-13T06:20:05.246Z log event: verbose -- "Connection"
2015-06-13T06:20:05.246Z log event: verbose -- "Connection"
2015-06-13T06:20:05.246Z log event: verbose -- "Connection"
2015-06-13T06:20:05.247Z log event: verbose -- "Connection"
2015-06-13T06:20:05.248Z log event: verbose -- "Connection"
2015-06-13T06:20:05.248Z log event: verbose -- "Connection"
2015-06-13T06:20:05.248Z log event: info -- "ControlConnection"
2015-06-13T06:20:05.248Z log event: info -- "ControlConnection"
2015-06-13T06:20:05.248Z log event: verbose -- "Connection"
2015-06-13T06:20:05.249Z log event: verbose -- "Connection"
2015-06-13T06:20:05.255Z log event: verbose -- "Connection"
2015-06-13T06:20:05.255Z log event: info -- "ControlConnection"
2015-06-13T06:20:05.255Z log event: verbose -- "Connection"
2015-06-13T06:20:05.256Z log event: verbose -- "Connection"
2015-06-13T06:20:05.256Z log event: verbose -- "Connection"
2015-06-13T06:20:05.258Z log event: verbose -- "Connection"
2015-06-13T06:20:05.258Z log event: info -- "ControlConnection"
2015-06-13T06:20:05.258Z log event: info -- "ControlConnection"
2015-06-13T06:20:05.258Z log event: verbose -- "Connection"
2015-06-13T06:20:05.258Z log event: verbose -- "Connection"
2015-06-13T06:20:05.258Z log event: verbose -- "Connection"
2015-06-13T06:20:05.262Z log event: verbose -- "Connection"
2015-06-13T06:20:05.273Z log event: verbose -- "Connection"
2015-06-13T06:20:05.273Z log event: verbose -- "Connection"
2015-06-13T06:20:05.274Z log event: verbose -- "Connection"
2015-06-13T06:20:05.275Z log event: verbose -- "Connection"
2015-06-13T06:20:05.275Z log event: info -- "ControlConnection"
2015-06-13T06:20:05.275Z log event: verbose -- "Connection"
2015-06-13T06:20:05.276Z log event: verbose -- "Connection"
2015-06-13T06:20:05.276Z log event: verbose -- "Connection"
2015-06-13T06:20:05.276Z log event: verbose -- "Connection"
2015-06-13T06:20:05.276Z log event: verbose -- "Connection"
2015-06-13T06:20:05.278Z log event: verbose -- "Connection"
2015-06-13T06:20:05.279Z log event: verbose -- "Connection"
2015-06-13T06:20:05.283Z log event: verbose -- "Connection"
result 1
,因此您无需逃避花括号:
.format