我想在我的应用程序中使用角色或浏览器 ID 进行金字塔身份验证,问题是我们两个都使用我看到一个错误。
当我使用角色时,控制台会让我失望:
Import error: No module named pyramid_persona
当我使用浏览器 ID 时,我没有名为 browserid 的模块
这是我的代码:
我的查看文件
from pyramid.config import Configurator
from pyramid.response import Response
from pyramid.security import authenticated_userid
#from waitress import serve
from pyramid.config import Configurator
from pyramid.response import Response
from pyramid.security import authenticated_userid
from pyramid.exceptions import Forbidden
def hello_world(request):
userid = authenticated_userid(request)
if userid is None:
raise Forbidden()
return Response('Hello %s!' % (userid,))
我的初始化文件
from pyramid.config import Configurator
from resources import Root
import views
import pyramid_jinja2
import os
here = os.path.dirname(os.path.abspath(__file__))
settings={
'persona.secret': 'some secret',
'persona.audiences': 'http://localhost:8080'
}
settings['mako.directories'] = os.path.join(here, 'templates')
__here__ = os.path.dirname(os.path.abspath(__file__))
def make_app():
""" This function returns a Pyramid WSGI application.
"""
settings = {}
settings['mako.directories'] = os.path.join(__here__, 'templates')
config = Configurator(root_factory=Root, settings=settings)
config.include('pyramid_persona')////////////////////////THE ERROR AND TROUBLEMAKER
config.add_renderer('.jinja2', pyramid_jinja2.Jinja2Renderer)
config.add_view(views.my_view,
context=Root,
renderer='zodiac1.mako')
#config.add_route( "home", "/home")
#config.add_view(views.home_view, route_name="home", renderer="zodiac1.mako" )
config.add_static_view(name='static',
path=os.path.join(__here__, 'static'))
# config.add_route('zodiac', '/zodiac')
# config.add_view(views.home_view, route_name='zodiac', #renderer='main.mako')
#config.add_route('zodiac1', '/zodiac1')
#config.add_view(views.home_view, route_name='zodiac1', renderer='zodiac1.mako')
config.add_route('zodiac2', '/zodiac2')
config.add_view(views.zodiac2_view, route_name='zodiac2', renderer='zodiac2.mako')
config.add_route('zodiac3', '/zodiac3')
config.add_view(views.guestbook, route_name='zodiac3', renderer='zodiac3.mako')
config.add_route('hello', '/hello')
config.add_view(views.guestbook, route_name='zodiac3', renderer='zodiac3.mako')
return config.make_wsgi_app()
application = make_app()
请告诉我我做错了什么,我确定它不喜欢我如何导入 config.include('pyramid_persona')
谢谢