Django request.GET

Asked

Viewed 598 times

2

Is there any simpler way to do that?

 if "id_parada" in request.GET:
     id_parada = request.GET["id_parada"]
 else:
     id_parada = ''

1 answer

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).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.