使用AngularJS对话框模板的Pyramid视图

Using a Pyramid view for an AngularJS dialog template

本文关键字:Pyramid 视图 AngularJS 对话框 使用      更新时间:2023-09-26

我已经使用Pyramid编写了一个web应用程序,Pyramid是一个Python web框架。

在我的web应用程序的一个页面中,我想实现对话框。我正试图通过AngularUI引导程序学习AngularJS来实现这一点(这里是一个使用AngularUI的对话框示例)。

我的页面将显示总共7个对话框。这些对话框将显示文本和图像,并接收和验证输入。对话流不是线性的;有条件对话框和多个执行分支。

请看这个显示AngularUI引导对话框的示例。example.js:5-21配置对话框显示选项。参数template包含要显示的HTML:

template:  t, // OR: templateUrl: 'path/to/view.html',

其中,在该示例中,var t包含一些静态示例标记:

var t = '<div class="modal-header">'+
        '<h3>This is the title</h3>'+
        ...



现在,在Pyramid中,URL不会直接映射到文件或文件夹;而是将URL与注册的路由进行比较。因此,例如,请求http://site.com/path/to/view.html是没有意义的。相反,你会编码:

config.add_route('my_route', '/my_feature')

@view_config(route_name='my_route', renderer='/path/to/view.html')

如果您调用http://site.com/my_feature,它将呈现view.html

如何将Pyramid视图用作templateUrl

因为Pyramid将URL抽象到视图中,所以我不能为静态HTML文件(例如abc.html)提供templateUrl。我提供的任何URL都会通过Pyramid的路由系统。

我已经尝试过将templateUrl提供给静态HTML文件,并取得了成功。但是任何Pyramid路由的URL都会失败,对话框也不会显示。

解决方案是什么?


解决方案

我不小心用了template而不是templateUrl

确保上面写的是templateUrl: '/your-pyramid-view'而不是template: '/your-pyramid-view'

您应该能够使用静态视图提供静态html文件:

config.add_static_view(name='partials', path='yourpythonpackage:partials')

如果abc.html在您的pythonbackage/partials中,那么您的templateUrl可以设置为/partins/abc.html。

而且,不要忘记

config.add_renderer('.html', 'pyramid.chameleon_zpt.renderer_factory')

直接渲染前端inedx.html,而不是金字塔索引模板。