0
我嘗試做靈活的url。我就是這麼做的靈活的正則表達式url,Django
url(r'^(&\w*)?/?$', direct_to_template,
{'template': 'basic.djhtml'}),
get_absolute_url
def get_absolute_url(self):
return "/&%s" % self.human_redble_url
的問題是一個錯誤:
direct_to_template() got multiple values for keyword argument 'template'
是什麼意思?我怎麼修復它?
在Python交互式解釋器這個正則表達式的作品
>>> import re
>>> reg = re.compile('^(&\w*)?/?$')
>>> result = reg.match('&post1')
>>> result
<_sre.SRE_Match object at 0xb77098a0>
>>> wrong = reg.match('aergsr')
>>> print wrong
None
>>> reg.match('post1')
>>> print reg.match('post1')
None
>>> print reg.match('&post1/')
<_sre.SRE_Match object at 0xb77097a0>
>>> print reg.match('&post1:')
None
此處的&符號「/ admin」與此正則表達式不匹配。 – I159 2011-06-11 20:03:36
進一步開發應用程序的方式之一是正則表達式仍然必須是一個命名組。謝謝。 – I159 2011-06-11 20:16:53