首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么瓶子不能显示本地图像?

为什么瓶子不能显示本地图像?
EN

Stack Overflow用户
提问于 2018-04-25 08:12:49
回答 2查看 469关注 0票数 1

我是一个初学者,我想用瓶子来展示一个picture.In事实,我先保存图片。

然后,当我使用我的代码执行此操作时,我希望在div.But中显示图片。

错误消息是"GET http://localhost:8081/test.jpg 404 (Not Found)“

我的项目结构:

--testBottle.py

--test.jpg

TestBottle.py中的代码:

# -*- coding:  utf-8 -*-
import bottle
import pandas as pd
from matplotlib import pyplot as plt
import numpy as np
from scipy import optimize as opt


def generate(code, year,week):
    kion = pd.read_csv(r'D:/a.csv')
    kion.head()
    Px = np.arange(0, len(kion), 1)
    Py = kion['temp']
    plt.plot(Px, Py)
    res = opt.curve_fit(fit_func, Px, Py)
    a = res[0][0]
    b = res[0][1]
    c = res[0][2]
    d = res[0][3]
    print("a = %s" % a)
    print("b = %s" % b)
    print("c = %s" % c)
    print("d = %s" % d)
    Px2 = []
    for x in Px:
        Px2.append(a * x ** 3 + b * x ** 2 + c * x + d)
    plt.plot(Px, Py)
    plt.plot(Px, np.array(Px2))
    plt.savefig('test.jpg')
    bottle.redirect('/show')


def fit_func(x, a, b, c, d):
    return a * x ** 3 + b * x ** 2 + c * x + d


@bottle.route('/show')
def index():
    return '''  <div id="container" style="height: 200px; width:200px">
                <img src="/test.jpg"  alt="error" />
                </div>
            '''


@bottle.route('/index')
def index():
    return ''' <form action="/generate" method="post">
                 enployeeCode: <input name="enployeeCode" type="text" /><br/>
                 reportYear: <input name="reportYear" type="text" /><br/>
                 reportWeek: <input name="reportWeek" type="text" /><br/>
                 <input value="generate" type="submit">
               </form>
            '''


@bottle.route('/generate', method='POST')
def get_para():
    enployeeCode = bottle.request.POST.get('enployeeCode')
    reportYear = bottle.request.POST.get('reportYear')
    reportWeek = bottle.request.POST.get('reportWeek')
    if enployeeCode and reportYear and reportWeek:
        generate(enployeeCode, reportYear,reportWeek)

bottle.run(host='localhost', port=8081)

我在中输入了以下内容:

,然后我点击按钮。

甚至我把图片路径改成了绝对路径,如下所示:

<img src="E://test//test.jpg"  alt="error" />

也不能显示。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50012332

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档