The following url definition should pass whether results/ is present in the url:
url(r'^(?P<question_id>[0-9]+)/(?P<results>(results/)?)shorten/$', views.shorten, name='shorten')
Currently it passes results/ or None which is sufficient for a simple:
if results:
pass
But it would be more elegant to have True and False. How could this be done?
You could have two URL patterns and pass results in the kwargs:
url(r'^(?P<question_id>[0-9]+)/results/shorten/$', views.shorten, {'results': True}, name='shorten'),
url(r'^(?P<question_id>[0-9]+)/shorten/$', views.shorten, {'results': False}, name='shorten'),
If you don't want to do this, then there isn't currently a simple way to cast the results string to a boolean value. You could write a middleware or decorator, but that would be overkill.