如何在html上转换python打印功能

时间:2014-04-18 14:57:30

标签: python-2.7 web2py

我正在尝试使用web2py来构建应用。我有一个简单的打印功能,用户提交关键字。字符串或int关键字指向sqlite数据库以检索行并输出数据。我需要知道 1.如何在html上使用print。 2.如何分割字符串...到目前为止我做了列表:字符串

这是我的代码:

def first():
    form = SQLFORM.factory(Field('visitor_name',
                                 label = 'Please Type Your keyword here!',
                                 requires= [IS_NOT_EMPTY(), IS_LOWER(),'list:string']))
    form.element('input[type=submit]')['_onclick'] = "return \
    confirm('Are you sure you want to submit:');"
    if form.process().accepted:
        session.visitor_name = form.vars.visitor_name        
        redirect(URL('main'))
    return dict(form=form)


def main():    
    while True:
        name = request.vars.visitor_name or redirect(URL('first'))          
        name2 = name[:]        
        for item in name2:break
        name3 = ' '.join(name2)
        import sqlite3
        id = 0
        location = ""
        conn = sqlite3.connect("keywords.db")
        c = conn.cursor()
        c.execute('select * from kmedicals')
        records = c.fetchall()
        for record in records:
            id = record[0]
            location = record[15]
            if id == name3:
                print name3.capitalize(),':' '\n',location
                break
                sys.exit()
        return dict(name=name)

我的观点...默认/ main.html:

{{extend 'layout.html'}}
{{=name}}

0 个答案:

没有答案