Is there a way to have a default parameter passed to a action in the case where the regex didnt match anything using django?
urlpatterns = patterns('',(r'^test/(?P<name>.*)?$','myview.displayName'))
#myview.py
def displayName(request,name):
# write name to response or something
I have tried setting the third parameter in the urlpatterns to a dictionary containing ' and giving the name parameter a default value on the method, none of which worked. the name parameter always seems to be None. I really dont want to code a check for None if i could set a default value.
Clarification: here is an example of what i was changing it to.
def displayName(request,name='Steve'):
return HttpResponse(name)
#i also tried
urlpatterns = patterns('',
(r'^test/(?P<name>.*)?$',
'myview.displayName',
dict(name='Test')
)
)
when i point my browser at the view it displays the text 'None'
Any ideas?