special chars in view, utf8 issue ?!

37 views
Skip to first unread message

António Ramos

unread,
Feb 12, 2020, 6:12:41 AM2/12/20
to web...@googlegroups.com
Hello i cant understand how to solve this issue.
I have a record with portuguese characters 
"Ações de cada um" that passing it to  the view results in a different value.
How do i understand it to solve it ?

image.png
This is the result in my view 
My layout has  <meta charset="utf-8">
and my view is just

{{=a}}

image.png
and this is my controller
# -*- coding: utf-8 -*-
def execdal():

    ret=[]
    a=db(db.apps.id==1).select(db.apps.icon,db.apps.url,db.apps.bg,db.apps.title,orderby=db.apps.id).as_list()
    return dict(a=a)

Clemens

unread,
Feb 12, 2020, 8:19:11 AM2/12/20
to web...@googlegroups.com
Hello Ramos,

since I can't see your screenshot, I have to guess. But in German we also our special characters and I encode these by the following procedure:

import sys
import cgi # I first missed this to mention

def convert_special_chars(label):
    if sys.version_info[0]==2: # python 2.x
        label = label.decode('utf-8')
    label = cgi.escape(label)
    label = label.encode('ascii', 'xmlcharrefreplace')

    return label

Have a try! Hope it helps!

Best regards
Clemens

António Ramos

unread,
Feb 13, 2020, 1:35:24 PM2/13/20
to web...@googlegroups.com
my solution   .decode('utf8').encode('latin1')
just did it without thinking... dont know what i´m doing but it works...

                      {{temp=db(db.apps.id>0).select(db.apps.icon,db.apps.url,db.apps.bg,db.apps.title,orderby=db.apps.id)}}
                      {{for x in temp:}}
                      {{=XML({"url":x["url"],"icon":x["icon"],"title":x['title'].decode('utf8').encode('latin1'),"bg":x["bg"]}) }},
                      {{pass}}

Em qua., 12 de fev. de 2020 às 13:19, Clemens <clemens....@claret-clover.de> escreveu:
Hello Ramos,

since I can't see your screenshot, I have to guess. But in German we also our special characters and I encode these by the following procedure:

import re
import sys

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/b63a8e8e-717a-41e7-b2fd-476dae50ebed%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages