当我想启动金字塔服务器时,它会返回TopLevelLookupException: Can not locate 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()
答案 0 :(得分:2)
感谢@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)