传递参数作为HTML属性

2024-10-02 08:25:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用瓶子和HTML来测试httpget和POST。我写了这段代码,它要求用户输入一个颜色名称作为参数,如果它出现在预定义列表中,那么它应该打印找到并显示颜色。但我不知道怎样才能通过辩论。如果我尝试默认值,如橙色、红色等,效果很好。在

from bottle import*
import socket

@error(404)
def error404(error):
    return '<p align=center><b>Sorry, a screw just dropped.Well, we are hoping to find it soon.</b></p>'

@get('/New/rem_serv/:arg')
def nextstep(arg):
_colorlist=['Red','Green','Blue','Yellow','Orange','Black','White']

if arg in _colorlist:
    return "Found the same color \n","<p style='font-weight:bold; text-align:center; background-color:arg;'>" + str(arg)
else:
    return error404(404)

addrIp = socket.getaddrinfo(socket.gethostname(), None)
addrIp = addrIp[0][4][0]
run(host=addrIp, port=80)

Tags: import瓶子return颜色defhtmlargerror
2条回答

你要找的是HTML和CSS。在

<span style="color:red"><b>This is red</b></span>

使用template生成页面。在

你可以试试这样的方法:

@app.route('/New/rem_serv/:arg')
@view('template.tpl')
def nextstep(arg):
   _colorlist=['Red','Green','Blue','Yellow','Orange','Black','White']
    if arg in _colorlist: 
        context = {'result': "Found the same color %s" % arg}
     else:
        context = {'result': "color not found"}
    return (context)

你也可以试试这个:

^{pr2}$

剩下的问题是template/html/css

相关问题 更多 >

    热门问题