Reputation: 31129
I try to do flexible url. I did it this way
url(r'^(&\w*)?/?$', direct_to_template,
{'template': 'basic.djhtml'}),
get_absolute_url
def get_absolute_url(self):
return "/&%s" % self.human_redble_url
The problem is an error:
direct_to_template() got multiple values for keyword argument 'template'
What does it mean? How could I fix it?
In Python interactive interpretor this regexp works
>>> 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
Upvotes: 0
Views: 604
Reputation: 599630
I don't understand what that ampersand is doing there, but never mind.
I suspect the problem is that you have not used named groups in your URL. So the captured string is being sent through to the view function as the first positional argument, which is actually template
, so it conflicts with the template keyword arg.
Use a named group - &(?P<my_arg>\w*)?/?$
- and it should work.
Upvotes: 1