I solved it by using doing the following:
def show():
import requests
import json
url = "https://10.10.10.10/api/2.6/"
object_type = "config_templates/index"
data = requests.get(url + object_type, verify=False, auth=('user',
'password'))
json_input = data.text
try:
decoded = json.loads(json_input)
names = [entry['name'] for entry in decoded['config_templates']]
ids = [entry['id'] for entry in decoded['config_templates']]
return dict(names=names, ids=ids)
except (ValueError, KeyError, TypeError):
return "JSON format error"
Created the view to look like this:
{{extend 'layout.html'}}
<h2>List of Templates</h2><br /><p>
{{for temp_name,temp_id in zip(names,ids):}}
<p><b>{{=(A(temp_name, _href=URL("details", args=[temp_id])))}}</b></p>
{{pass}}</p>
On Friday, July 18, 2014 9:17:06 PM UTC-6, Sif Baksh wrote:
>
> Greetings all first attempt to write an app besides Hello world.
> I can run the script below as a python script and it returns 52 entries.
>
> When I run it in web2py it only show me one result.
> It's an API call that get results in JSON format.
>
>
> def index():
>
> import requests
> import json
> url = "https://10.10.10.1/api/2.6/"
> object_type = "config_templates/search"
> data = requests.get(url + object_type, verify=False, auth=('user',
> 'userpwd'))
> json_input = data.text
> try:
> decoded = json.loads(json_input)
> for entry in decoded['config_templates']:
> return entry['name']
> except (ValueError, KeyError, TypeError):
> return "JSON format error"
>
>
> Is there something I'm missing?
>
> Thanks in advance,
> Sif
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.