links in texts stoded in a database

60 views
Skip to first unread message

jonas

unread,
Dec 24, 2013, 5:19:28 PM12/24/13
to web...@googlegroups.com
Hi

How do you put links to other sites in a text that is stored in a database? for example, I have a blogg where all coments, posts etc are stored in a database. Everytime I add a post I do it from the admin interface by adding new entries in the database. But adding a link in the text is not working because it is simple interpretated as plain text. how do I solve this?

the blogg: http://md1frejo.pythonanywhere.com/kontra

thanks in advance


黄祥

unread,
Dec 24, 2013, 9:53:50 PM12/24/13
to web...@googlegroups.com
i think you can achieve it with put the rich text editor in your form input
ref:

another way is with put the html code in your input text area form or either use markmin.
the first is the easiest.

best regards,
stifan

Jonas Fredriksson

unread,
Dec 27, 2013, 4:01:52 PM12/27/13
to web...@googlegroups.com
I tried ckeditor and I've got an editor in admin so I can insert links, so far so good.
but the text is still rendered plain with html tags visible.

my function and db in db.py: (text field is the field I want to insert links into)

def advanced_editor(field,text):
    return TEXTAREA(_id = str(text).replace('.','_'), _name=field.text, _class='text ckeditor', value=text , _cols=80)

db.define_table('blog',
        Field('date','datetime',default=request.now),
        Field('image','upload'),
        Field('imageTitle','text',default="image text"),
        Field('title','text',default='imager text here...'),
        Field('text','text',default='blog text here...',widget=advanced_editor),
        Field('votes','integer',default=0),
        Field('plus','integer',default=0),
        Field('minus','integer',default=0))
    #        format = '%(title)s')


--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/yukzpnZe4GQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jonas Fredriksson

unread,
Dec 29, 2013, 2:59:13 PM12/29/13
to web...@googlegroups.com
just to clarify, my problem is that html tags in my input text area is just rendered as tags, naturally because the field is classified as text and nothing else. I need to render the html elements when displaying text.

黄祥

unread,
Dec 29, 2013, 8:46:55 PM12/29/13
to web...@googlegroups.com
if that the case please use XML() function on your view.
e.g.
{{for i, row in enumerate(rows):}}
{{=DIV(XML(T(row.table_field), sanitize = True) ) }}
{{pass}}

best regards,
stifan

黄祥

unread,
Dec 29, 2013, 9:29:45 PM12/29/13
to web...@googlegroups.com
another way around is define it on the represent for your table text field.
e.g.
table.table_field.represent = lambda v, r: XML(v, sanitize = True)

the difference for previous code in this one you can use it for grid without define it again on your view.

if you use string type field, yet it can be done with represent also
e.g.
table.website.represent = lambda website, field: \
A(website, _title = T("View Website"), _target = "_blank", _href = "%s" % website)

best regards,
stifan

Jonas Fredriksson

unread,
Dec 30, 2013, 3:40:17 AM12/30/13
to web...@googlegroups.com
the XML function solved the problem:


{{for i, row in enumerate(rows):}}
{{=DIV(XML(T(row.table_field), sanitize = True) ) }}
{{pass}}

thanks.



--
Reply all
Reply to author
Forward
0 new messages