我正在使用pyramid_sacrud并获取错误" 403禁止访问该资源。未经授权:sa_home权限检查失败"

时间:2015-09-25 09:52:06

标签: pyramid

我按照官方文档,一步一步地设置它。 使用浏览器指向here,此处引发403 Forbidden错误。我试图在sa_home中删除pyramid_sacrud/views/init.py函数的参数权限来解决它,虽然它可能是访问权限,但它没有登录页面。

这是我的应用程序的ini文件:

from pyramid.config import Configurator
from sqlalchemy import engine_from_config
from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.session import SignedCookieSessionFactory
from pyraid_blogr.models.models import BlogRecord, User

from .models.meta import (
    DBSession,
    Base,
)


def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    authentication_policy = AuthTktAuthenticationPolicy('your_secret', hashalg='sha512')
    authorization_policy = ACLAuthorizationPolicy()
    config = Configurator(settings=settings,
                          authentication_policy=authentication_policy,
                          authorization_policy=authorization_policy
                          )
    config.set_session_factory(SignedCookieSessionFactory('replace_your_secret'))
    config.include('pyramid_mako',)
    config.include('pyramid_sacrud',)
    settings = config.registry.settings
    settings['pyramid_sacrud.models'] = (('Group1', [BlogRecord]), ('Group2', [User]))
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('blog', '/blog/{id:\d+}/{slug}', request_method='GET')
    config.add_route('blog_action', '/blog/{action}', factory='pyraid_blogr.security.BlogRecordFactory')
    config.add_route('auth', 'sign/{action}')
    config.scan()
    return config.make_wsgi_app()

这是调试信息

  

权限pyramid_sacrud_home value' pyramid_sacrud_home'资源   第45行的文件   /Users/liu-minglei/Web-Dev/my_pyramid/pyraid_blogr/admin/views/init.py:   permission = PYRAMID_SACRUD_HOME引用视图功能   admin.views.sa_home

1 个答案:

答案 0 :(得分:0)

我创建了一个带有授权(https://github.com/ITCase/pyramid_sacrud/tree/master/example)的示例,在您的情况下,您似乎编辑了pyramid_sacrud/views/init.py文件,该文件不是您的python环境中的位置或不是重新加载服务器。对于您的应用,您必须向root_factory添加牺牲许可(http://pyramid-sacrud.readthedocs.org/en/latest/pages/permissions.html)。