1

私は、HTTPGETとPOSTをテストするためにBottleとHTMLを試しています。私は、ユーザーがパラメーターとして色名を入力する必要があるこのコードを作成しました。それが事前定義されたリストに存在する場合は、見つかったものを印刷して色を表示する必要があります。しかし、どうすれば引数を渡すことができるのかわかりません。オレンジ、赤などのデフォルト値を試してみると、問題なく動作します。

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)
4

2 に答える 2

2

あなたはそのようなことを試すことができます:

@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)

これで試すこともできます:

from bottle import Bottle, run, view, request

app = Bottle()

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

残りはtemplate/html/cssの質問です

于 2012-08-16T13:45:51.667 に答える
1

あなたが探しているのはHTMLとCSSです。

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

テンプレートを使用してページを作成します。

于 2012-08-16T13:36:43.203 に答える