python - 未渲​​染页面上的 Pyramid 错误

标签 python pyramid

我遇到了一个非常奇怪的错误。不知何故,无论我在哪个页面上,它都会加载我想要的页面,然后尝试加载另一个页面(但由于我不打算转到该页面,所以它寻找的变量不存在,所以它给了我控制台中的错误)

这是我的路线:

config.add_route('editdata', '/{userurl}/{dataname}/edit')
config.add_route('viewdata', '/{userurl}/{dataname}')
config.add_route('profile', '/{userurl}')

如果我进入编辑数据页面,该页面加载正常,但在我的调试屏幕中,我收到与配置文件页面相关的错误(我知道我在该部分,因为我放置了打印语句来输出我所在的函数,并且错误与该页面的 sql 相关,与编辑页面无关)。

我已经更改了路由的顺序,但仍然收到错误,我在某些函数中使用了一些名为 profile 的变量,因此我什至尝试将路由名称更改为 profile1,但仍然收到错误。当我注释掉配置文件路径(在 init 和 View 中)时,错误消失了,但显然我的配置文件区域无法访问。

关于我可以尝试解决此问题的任何建议吗?除了 route 的之外,我没有看到任何对我的个人资料 View 的引用(没有页面重定向到个人资料,但在 jinja2 的每个页面上,我都有一个到个人资料的链接,但我也有到其他页面的链接,但没有得到错误)。

如果它有帮助,这里是回溯(我所做的只是转到 View 数据页面,根本没有转到个人资料页面)。:

C:\Users\lostsoul\Desktop>C:\Users\lostsoul\GoogleDrive\pyramidtut\Scripts\pserve.
exe C:\Users\lostsoul\GoogleDrive\pyramidtut\tutorial\development.ini --reload
Starting subprocess with file monitor
Starting server in PID 4016.
serving on http://0.0.0.0:6543
we are viewing the data
****
Variables are:
monkey
dog
*****
we are in profile section
2012-07-19 00:07:01,388 ERROR [pyramid_debugtoolbar][Dummy-2] Exception at http:
//localhost:6543/favicon.ico
traceback url: http://localhost:6543/_debug_toolbar/exception?token=c0660cf901de
bc8c3af7&tb=67564912
Traceback (most recent call last):
  File "C:\Users\lostsoul\GoogleDrive\pyramidtut\lib\site-packages\pyramid_debugt
oolbar-1.0.2-py2.7.egg\pyramid_debugtoolbar\toolbar.py", line 122, in toolbar_tw
een
    response = _handler(request)
  File "C:\Users\lostsoul\GoogleDrive\pyramidtut\lib\site-packages\pyramid_debugt
oolbar-1.0.2-py2.7.egg\pyramid_debugtoolbar\panels\performance.py", line 69, in
noresource_timer_handler
    result = handler(request)
  File "C:\Users\lostsoul\GoogleDrive\pyramidtut\lib\site-packages\pyramid-1.3.2-
py2.7.egg\pyramid\tweens.py", line 20, in excview_tween
    response = handler(request)
  File "C:\Users\lostsoul\GoogleDrive\pyramidtut\lib\site-packages\pyramid_tm-0.5
-py2.7.egg\pyramid_tm\__init__.py", line 100, in tm_tween
    response = handler(request)
  File "C:\Users\lostsoul\GoogleDrive\pyramidtut\lib\site-packages\pyramid-1.3.2-
py2.7.egg\pyramid\router.py", line 164, in handle_request
    response = view_callable(context, request)
  File "C:\Users\lostsoul\GoogleDrive\pyramidtut\lib\site-packages\pyramid-1.3.2-
py2.7.egg\pyramid\config\views.py", line 333, in rendered_view
    result = view(context, request)
  File "C:\Users\lostsoul\GoogleDrive\pyramidtut\lib\site-packages\pyramid-1.3.2-
py2.7.egg\pyramid\config\views.py", line 471, in _requestonly_view
    response = view(request)
  File "c:\users\lostsoul\googledrive\pyramidtut\tutorial\tutorial\views.py", lin
e 109, in profile
    profile_info = DBSession.query(data).filter(data.owner==profileda
ta.id).all()
AttributeError: 'NoneType' object has no attribute 'id'

您可以看到(靠近顶部)它成功渲染了 View 数据 View (输出变量并告诉我这就是我所在的位置),但由于某种原因它也加载了个人资料页面。我很困惑为什么它会这样做以及加载它的请求来自哪里。

最佳答案

如果您查看粘贴顶部附近,您会发现生成错误的 URL 是 '/favicon.ico',每当您访问您的网站时浏览器都会请求该 URL。该路径匹配您的个人资料网址 '/{userurl}' 的正则表达式。

关于python - 未渲​​染页面上的 Pyramid 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11553840/

相关文章:

python - 尝试在 Pyramid oauth 提供程序中生成请求 token 时出现无效签名错误

python - 如何在pygame中绘制透明线

python - 按列表中出现的频率对列表进行排序

python - sockets可以用来在python中连接不同网络上的多台计算机吗?

python - Pyramid 读取http数据

python - Pyramid/SQLAlchemy 显示对象

python - 使用 Python Egg/Wheel 打包共享对象(库)

尽管有 __init__.py,Python 仍无法导入自定义模块

python - 如何链接到 css 文件中的静态图像?

python - 分离实例错误: Instance <TCustomer at 0x428ddf0> is not bound to a Session