gpt4 book ai didi

python - Pyramid 响应显示在控制台日志中,而不是页面上

转载 作者:太空宇宙 更新时间:2023-11-04 10:42:03 24 4
gpt4 key购买 nike

我正在尝试制作我的第一个 Pyramid 应用程序,我想我在响应方面遇到了一个基本的问题。

我有一个元组列表,我想将它们打印到网页上,但网页是空白的,列表出现在终端窗口中。整个应用:

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
from photoCollect import photoCollect

def printPhotos(request):
photoTable = photoCollect()
return Response(photoTable)

if __name__ == '__main__':
config = Configurator()
config.add_route('productlist','/productlist')
config.add_view(printPhotos, route_name='productlist')
app = config.make_wsgi_app()
server = make_server('0.0.0.0', 8080, app)
server.serve_forever()

photoCollect定义为:

import urllib
import pandas as pd

def photoCollect():
# pull photo directory
mypath = "http://gwynniebee.com/photos"
mylines = urllib.urlopen(mypath).readlines()

# strip down web page to retain just photo names
photonames = []
for item in mylines:
if ".jpg" in item:
k = item.replace('<',' ')
splitItem = k.split(" ")
for x in splitItem:
if "=" not in x and ".jpg" in x:
photonames.append(x)

photoFrame = pd.DataFrame(photonames, columns=['name'])

# break photo names into vendor-color-order
photoFrame['name2'] = photoFrame['name'].apply(lambda x: x.replace('.jpg',''))
s = photoFrame['name2'].apply(lambda x: pd.Series(x.split('-')))

# concat vendor-color into style
s['style'] = s[0] + "-" + s[1]
s['order'] = s[2]
photoFrame = photoFrame.join(s)

# find first photo for each style and recreate photo name
styleMin = photoFrame.groupby('style')['order'].min()
photoName = pd.DataFrame(styleMin)
photoName = photoName.reset_index()
photoName['name'] = photoName['style'] + "-" + photoName['order']+".jpg"

# generate list to send to web
webList = pd.DataFrame("http://gwynniebee.com/photos/"+ photoName['name'])
webList['style'] = photoName['style']

webList = webList.set_index('name')
photoList = list(webList.itertuples())

print photoList

如何让列表显示在网页上?我很困惑为什么响应显示在日志中而不是页面上。

最佳答案

photoCollect() 方法打印输出:

print photoList

打印将数据写入sys.stdout,在运行 WSGI 服务器时重定向到日志。

您想返回photoList:

return photoList

如果没有 return 语句,默认返回值为 None,并且 Response(None) 会生成一个空页面。

通过 returnphotoCollect() 函数的调用者实际上收到了该列表。

关于python - Pyramid 响应显示在控制台日志中,而不是页面上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20012084/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com