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?

+3


source to share


1 answer


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.

+4


source







All Articles