Python 金字塔响应显示在控制台日志中,而不是第页

Python 金字塔响应显示在控制台日志中,而不是第页,python,pyramid,Python,Pyramid,我正在尝试制作我的第一个金字塔应用程序,我想我在回复方面有一个基本的障碍 我有一个元组列表,我想把它们打印到一个网页上,但是网页是空白的,列表显示在终端窗口中。整个应用程序: from wsgiref.simple_server import make_server from pyramid.config import Configurator from pyramid.response import Response from photoCollect import photoCollect

我正在尝试制作我的第一个金字塔应用程序,我想我在回复方面有一个基本的障碍

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

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
导入urllib
作为pd进口熊猫
def photoCollect():
#拉照片目录
我的路径=”http://gwynniebee.com/photos"
mylines=urllib.urlopen(mypath).readlines()
#精简网页,只保留照片名称
photonames=[]
对于myline中的项目:
如果项目中的“.jpg”:
k=项。替换(“方法
photoCollect()
打印输出:

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

您想返回照片列表

return photoList
如果没有
return
语句,默认返回值为
None
,而
Response(None)
将导致一个空页面

使用
返回
函数photoCollect()的调用者实际上接收到该列表。

方法打印输出:

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

您想返回照片列表:

return photoList
如果没有
return
语句,默认返回值为
None
,而
Response(None)
将导致一个空页面


使用
返回
调用
photoCollect()
函数实际接收该列表。

那么
photoCollect
做什么呢?它返回一个包含一些照片名称的元组列表。photoCollect的代码正确吗,错误在该方法中。
photoCollect
做什么呢?它返回一个包含一些照片名称的元组列表。photoCollec的代码正确吗tRight,错误就在这个方法中。当我将
print
更改为
return
时,我得到以下错误:“AssertionError:write()参数必须是string”@quaintm:然后首先将该列表转换为字符串。当我将
print
更改为
return
时,我得到以下错误:“AssertionError:write()参数必须是字符串“@quaintm:然后首先将该列表转换为字符串。