###前提・実現したいこと
作成したページ上に背景を変えたい
###発生している問題・エラーメッセージ
エラーは発生しないが、ページの背景が真っ白のまま変わらない
エラーメッセージ
###該当のソースコード
```#!/user/bin/env python # -*- coding: utf-8 -*- from bottle import route, run, template, request, static_file, url, get, post, response, error import sys, codecs import random import time import urllib.request import urllib.parse import urllib3 import re import xml.etree.ElementTree as ET sys.stdout = codecs.getwriter("utf-8")(sys.stdout) @route("/") def html_index(): return template("index") @route("/static/<filepath:path>", name="static_file") def static(filepath): return static_file(filepath, root="./static") @view("hello_template") def hello(name, count): return dict(name=name, count=count, url=url) class GoogleSuggestAPI: def __init__(self): self.base_url = 'http://www.google.co.jp/complete/search?output=toolbar&q=' self.xml_re = re.compile('<CompleteSuggestion><suggestion data="(.+?)"/><num_queries int="(.+?)"/></CompleteSuggestion>', re.DOTALL) def get(self, query): try: reader = urllib.request.urlopen(self.base_url + urllib.parse.quote_plus(query)) except Exception as e: print (e) return None buf=reader.read() print(buf) buf = buf.decode('sjis',"ignore") root = ET.fromstring(buf) Res=[] for c in root: dat=c[0] attrs=dat.attrib suggest=attrs["data"] L = len(query) #L文字目以降を取り出す suggest=suggest[L:] #空白を削除する suggest=suggest.strip() Res.append(suggest) print (Res) return Res marks = ['ハンバーグ','カレー','ラーメン'] food = random.choice(marks) #ボタンの生成 @get("/login") def login(): hp = """ <form action="/login" method="post"> 料理名を入力!!: <input name="dish" type="text" /> <input value="Answer" type="submit" /> </form> """ B = [] if '__main__' == __name__: gsapi = GoogleSuggestAPI() result_list = gsapi.get(food + " ") if result_list is None: return ('Error') exit() for result in result_list: B.append(result + '<br>') return ( hp + "".join(B) ) @route("/login", method="POST") def do_login(): dish = request.forms.decode().get( 'dish' ) if check_login(dish): return "<p>正解です !</p>" else: return "<p>不正解です !</p>" def check_login(dish): if (food.encode('utf-8')) == (dish.encode('utf-8')): return True else: return False @error(404) def error404(error): return template("404") run(host="localhost", port=8080, debug=True, reloader=True) #hello_template.tpl <img src="{{url('static_file', filepath="image.jpg")}}"> ###試したこと 公開されているプログラム(@viewの所)を参考にしましたが上手くいきませんでした。 ###補足情報(言語/FW/ツール等のバージョンなど) 言語はpythonでフレームワークにbottleを使用しています。
問題のソースコードがうまく貼られていないので修正お願いします
回答1件
あなたの回答
tips
プレビュー