Hello all, I'm new to web.py and working on using it with some vendor APIs.
Basic overview, I have the user input some text, web.py takes that text and
sends it to a python script that queries the API, the API returns results
and the results are rendered into a form. The results are always python
dictionary items.
The problem I am having is using IF statements to test if a dictionary key
exists. For instance, the API will return a dictionary key 'next' with a
URL as its value if there are more results to search display. If there are
no more results the 'next' key is not present.
In my template the code looks like
$if results['next']
<a href=$results['next']>Click here for more results</a>
This works fine if the API returns that there are more results to display.
If there are no more results I get an Key Exception error that the key
'next' does not exist, when I want it to just continue rendering the page
without creating the href tag and link.
I've even added an 'else' statement to handle any Key errors but that did
not work. I've tried using 'Try' 'Except' catches as well but the page will
always fail to load with the Key Exception error.
Am I doing something wrong, or are the IF statements in web.py not working
as they should in normal python?
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/d/optout.