我想在主文件中使用许多宏(调用)。从头开始调用页眉,正文和页脚。
我正在将金字塔框架与变色龙一起使用。
这是home.pt
const GET_USER_PLAYIST = gql`
{
playlists(where: { users: { id: 1 } }) {
name
id
}
}
`;
head和base都有自己的文件,工作正常,但页脚没有 这是head.pt
<metal:macro use-macro="head">
</metal:macro>
<metal:macro use-macro="base">
<!-- HOME CONTENT-->
.
.
.
</metal:macro><!--metal macro base end-->
<metal:macro use-macro="footer">
</metal:macro>
这是footer.pt
<!DOCTYPE html>
<html lang="en">
<head>
<!--Bootsrap 4 CDN-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet"
href="${request.static_url('proyect_name:static/ds_style.css') }"/>
</head>
view.py
</body>
</html>
文件的一部分__init __。py
from pyramid.renderers import get_renderer
from pyramid.interfaces import IBeforeRender
from pyramid.events import subscriber
@subscriber(IBeforeRender)
def globals_factory(event):
master = get_renderer('templates/head.pt').implementation()
event['head'] = master
master = get_renderer('templates/base.pt').implementation()
event['base'] = master
master = get_renderer('templates/pie.pt').implementation()
event['pie'] = master
master = get_renderer('templates/base_dashboard.pt').implementation()
event['base_dashboard'] = master
@view_defaults(renderer='templates/home.pt')
class DSViews:
def __init__(self, request):
self.request = request
self.logged_in = request.authenticated_userid
@view_config(route_name='home', renderer='templates/home.pt')
def home(self):
return {'name': 'home'}
@view_config(route_name='head', renderer='templates/head.pt')
def head(self):
return {'name': 'head'}
@view_config(route_name='base', renderer='templates/base.pt')
def base(self):
return {'name': 'base'}
@view_config(route_name='pie', renderer='templates/pie.pt')
def pie(self):
return {'name': 'pie'}
来自调试器
#permited uris
config.add_route('home', '/')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
##internal parts
config.add_route('base', '/base')
config.add_route('head', '/head')
config.add_route('pie', '/pie')
config.add_route('dashboard', '/dashboard')