2
Is there any simpler way to do that?
if "id_parada" in request.GET:
id_parada = request.GET["id_parada"]
else:
id_parada = ''
2
Is there any simpler way to do that?
if "id_parada" in request.GET:
id_parada = request.GET["id_parada"]
else:
id_parada = ''
3
The simplest way is:
id_parada = request.GET.get("id_parada", "")
In this case you are using the method .get()
to retrieve the contents of the key id_parada
in request.GET
and, if it does not exist, return "" (the default is None
).
Show, Thanks solved perfectly!
This is the link to the documentation, if anyone is interested...
Browser other questions tagged python-3.x django django-rest-framework
You are not signed in. Login or sign up in order to post.
Leandro, you have checked this reply: In Python there is ternary operation? ?
– Luiz Augusto
Luiz already improved a little would be like this
id_parada = request.GET["id_parada"] if "id_parada" in request.GET else ''
– Leandro Markes