python - TopLevelLookupException : Can not locate template for uri

标签 python pyramid

当我想启动我的 Pyramid 服务器时,它返回 TopLevelLookupException: Can not located template for uri 错误。请解释一下问题出在哪里

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
from pyramid.view import view_config
import tweepy
import os

consumer_key=""
consumer_secret=""
access_key = ""
access_secret = "" 
here = os.path.dirname(os.path.abspath(__file__))

也许,问题出在这个“这里”对象上。

def twitterfeed(request):
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_key, access_secret)
    api = tweepy.API(auth)
    statuses =  tweepy.Cursor(api.friends_timeline).items(20)
    data = Response('\n'.join([s.text.encode('utf8') for s in statuses]))
    print type(data)
    return {"data": data}


if __name__ == '__main__':
    settings = {}
    settings['reload_all'] = True
    settings['debug_all'] = True
    settings['mako.directories'] = os.path.join(here, 'templates')
    config = Configurator()
    config.add_view(twitterfeed, route_name='list', renderer='list.mako')
    config.add_route('list', '/')
    app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 8000, app)
    server.serve_forever()

最佳答案

感谢@swietyy,我的代码现在可以运行了

def twitterfeed(request):
   auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
   auth.set_access_token(access_key, access_secret)
   api = tweepy.API(auth)
   statuses =  tweepy.Cursor(api.friends_timeline).items(20)
   data = [s.text.encode('utf8') for s in statuses]
   return {"data": data}
#...
#...
#...
config = Configurator(settings=settings)

关于python - TopLevelLookupException : Can not locate template for uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14588047/

相关文章:

python - 优化python文件比较脚本

javascript - 如何使用selenium python点击链接

python - 从 Pyramid Web 应用程序配置 Blaze 并启动 Bokeh 服务器

python - 在 Pyramid 中编写应用程序,组合它们并重用它们的代码

python - 当 MongoDB 用作数据库时使用哪个 python web 框架(django 或 django-norel 或 Pyramid )

嵌套解释器中的 python Cmd 模块自动完成错误

python - python unittest 中的 Mock.patch 可以用于两条路径

python - 值错误: I/O operation on closed file in Pyramid

python - 更改 session cookie的超时时间是否存在安全风险?

python - 如何在 pandas 中保存 lmplot