Store boolean variable when submitting urls
The following URL definition must pass if present in the URL results/
:
url(r'^(?P<question_id>[0-9]+)/(?P<results>(results/)?)shorten/$', views.shorten, name='shorten')
It currently passes results/
or None
, which is simple enough:
if results:
pass
But it would be more elegant to have True
and False
. How can I do that?
source to share
You can have two URL patterns and pass results
to 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 is currently no easy way to pass a string to a results
boolean value. You could write middleware or a decorator, but that would be overkill.
source to share