home_page.html:
{% extends "base.html" %}
{% block title %}
Treichle-Cup
{% endblock %}
{% block body_class %}template-homepage{% endblock %}
{% block content %}
{% endblock %}
team_rooster.html
{% extends 'base.html' %}
{% load wagtailcore_tags %}
{% block content %}
<div class="container">
{% for team in teams %}
<div class="row">
<table border="2" width="100%">
<tbody>
<tr>
<th colspan="5">{{team.team_name}}</th>
</tr>
<tr>
<td colspan="2" rowspan="3">{{team.team_logo}}</td>
<th colspan="3">Staff</th>
</tr>
<tr>
<th>Name</th>
</tr>
<tr>
<td>{{team.staff.name}}</td>
</tr>
</tbody>
</table>
</div>
{% endfor %}
</div>
{% endblock %}
很难找出wagtail视图功能的工作原理。如果我去www.mysite.com/team-rooster
,我的目标就是渲染我的team_rooster.html当我尝试渲染我的模板
时,我得到了一个属性这是一个追溯记录 http://dpaste.com/3TH3WT5
{% load static wagtailcore_tags %}
<div class="left-side sticky-left-side">
<div class="logo-icon text-center custom-nav">
<a href="{% pageurl team_rooster %}"><i class="fa fa-group fa-2x"></i></a>
<span style="top: 76px">Teams</span>
</div>
</div>
我尝试了{%pageurl page.team_rooster%},但得到了相同的错误
我的模型有以下课程
class Staff(StructBlock):
photo = ImageChooserBlock(required=False)
position = ChoiceBlock(choices=[
('headcouch', 'Headcouch'),
], icon='cup')
class Meta:
icon = 'plus'
class Spieler(StructBlock):
photo = ImageChooserBlock(required=False)
position = ChoiceBlock(choices=[
('th', 'TH'),
], icon='cup')
jahrgang = IntegerBlock(required=True)
class Meta:
icon = 'user'
class TeamRooster(Page):
team_name = models.CharField(max_length=100)
staff = StreamField([
('staff', CardsBlock(Staff(), icon="plus")),
], blank=True)
spieler = StreamField([
('spieler', CardsBlock(Spieler(), icon="user")),
], blank=True)
content_panels = [
FieldPanel('team_name', classname="col12"),
ImageChooserPanel('team_logo'),
StreamFieldPanel('staff'),
StreamFieldPanel('spieler'),
]
def __str__(self):
return self.team_name
答案 0 :(得分:1)
要从自己的模板中获取当前页面的URL,请执行以下操作:
{% pageurl self %}
OR
{% pageurl page %}
注意:您必须已加载wagtailcore_tags
,例如。 {% load wagtailcore_tags %}