When using web.py how can I checkis a parameter exists in the URL?

25 Views Asked by At

I'm using web.py https://webpy.org/ for providng access to simple python script like http://hosturl.com.scriptname?param1=something&param2=somethingelse

I see how I can retrieve the values of the parameters using

import web
param1 = web.input().param1
param2 = web.input().param2

However I'm stuck when I try to check if the param2, for example, even exists.

I've tried

if web.input().param2:

but that gives me an error message

<class 'AttributeError'> at /getmonthlyPV
1

There are 1 best solutions below

0
carbontracking On

Groan....

what I needed was

if hasattr(web.input(),"param2"):

Alot to be said for reading the error messages, they're actually trying to help :(