Printing data on web2py view page is different from python shell

97 views
Skip to first unread message

Maurice Waka

unread,
Mar 18, 2015, 8:38:12 AM3/18/15
to web...@googlegroups.com

When I have data from sqlite printing out to python shell such as from this code:
import sqlite 3
code
def trial_stuff()
    style =  [ 'string',....]
    id = record[0]
    place = record[5]

    if item in string == id:
        print place

In an example data, the result appears as this:

Foot complications are among the most serious and costly complications of diabetes mellitus.

Amputation of the lower extremity or part of it is usually preceded by a foot ulcer.

A strategy that includes prevention, patient and staff education, multidisciplinary treatment of foot ulcers, and close monitoring can
reduce amputation rates by 49–85%.

Therefore, several countries and organizations, such as the World Health Organization and the International Diabetes Federation, have set goals to reduce the rate of amputations by up to 50%.

When printing in web2py view:
in controller:

code......

result = trial_stuff()

in view.html:

{{extend.layout.html}}
{{Answer:}}
{{=result}}


This is what I get on view:
Answer:
Foot complications are among the most serious and costly complications of diabetes mellitus. Amputation of the lower extremity or part of it is usually preceded by a foot ulcer.A strategy that includes prevention, patient and staff education, multidisciplinary treatment of foot ulcers, and close monitoring can reduce amputation rates by 49–85%. Therefore, several countries and organizations, such as the World Health Organization and the International Diabetes Federation, have set goals to reduce the rate of amputations by up to 50%.


Is there a better way of doing it on web2py and space out my answer on view like it does on shell?

Kind regards

Leonel Câmara

unread,
Mar 18, 2015, 8:53:13 AM3/18/15
to web...@googlegroups.com
This is just how HTML works. You may want to study HTML a bit more but here's a quick n' dirty solution.

{{extend.layout.html}}
Answer:
{{=XML(result.replace('\n', '<br>'))}}

Gray Kanarek

unread,
Mar 18, 2015, 6:00:50 PM3/18/15
to web...@googlegroups.com
Could also try BEAUTIFY(), which will accept a list and print it out as a table.

Niphlod

unread,
Mar 18, 2015, 6:31:34 PM3/18/15
to web...@googlegroups.com


On Wednesday, March 18, 2015 at 11:00:50 PM UTC+1, Gray Kanarek wrote:
Could also try BEAUTIFY(), which will accept a list and print it out as a table.


but won't preserve newlines, that's pretty much the entire deal about the "issue" ^_^

Michele Comitini

unread,
Mar 18, 2015, 6:45:07 PM3/18/15
to web...@googlegroups.com
From the above code I would expect result == None


--
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 web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Maurice Waka

unread,
Mar 19, 2015, 4:05:30 AM3/19/15
to web...@googlegroups.com

Thank so much. It worked!

--
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/-rERKq_NJ2Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Maurice Waka

unread,
Mar 19, 2015, 4:07:28 AM3/19/15
to web...@googlegroups.com

Thanks Leo. It worked!

On Mar 18, 2015 3:53 PM, "Leonel Câmara" <leonel...@gmail.com> wrote:
--
Reply all
Reply to author
Forward
0 new messages