我没有得到任何错误,但我无法让标签显示它的内容。 '形式的内容'应该是' blah',
文件设置是,
crudapp_tags.py
from django import template
register = template.Library()
@register.inclusion_tag("forum.html")
def results(poll):
form = 'blah'
return {'form': form}
模板/ forum.html
{% extends 'index.html' %}
{% load crudapp_tags %}
{% results poll %}
<p>aaa</p>
{% block homepage %}
<p>bbb</p> <!-- Only this displays -->
{% if form %}
<p>Form exists</p>
{% endif %}
{% for item in form %}
<p>This is {{ item }}</p>
{% endfor %}
<div>
<p>{% if user.is_authenticated %}Add a New Topic: <a href="{% url 'topic_form' %}"><span class="glyphicon glyphicon-plus"></span></a>{% endif %}</p>
</div>
<div>
<p>{{ totalposts.count }} posts, {{ totaltopics.count }} topics, {{ totalusers.count }} users, {{ totalviews.numviews}} views</p>
</div>
<div class="post">
{% if pModel %}
<div class="table-responsive">
<table class='table table-striped table-hover'>
<thead>
<tr>
<th>Topic</th>
<th>Topic Started By</th>
<th>Last Active</th>
<th class="table-cell-center">Views</th>
<th class="table-cell-center">Posts</th>
</tr>
</thead>
<tbody>
{% for item in pModel %}
<tr>
<td><a href="{% url 'thread' item.topic_id %}">{{ item.topic.topic }}</a></td>
<td><a href="{% url 'profile' item.topic.author_id %}">{{ item.topic.topicAuthor }}</a></td>
<td class="icon-nowrap">{{ item.pub_date|timesince:current_time}}</td>
<td class="table-cell-center">{{ item.topic.views }}</td>
<td class="table-cell-center">{{ item.freq }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</div>
</div>
{% endblock %}
crudProject / settings.py确实包含INSTALLED_APPS中的应用
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bootstrapform',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'tinymce',
'crudapp',
]
设置似乎与此主题Django - Simple custom template tag example
中的答案相同为什么&#39;等等?没有在forum.html中显示?
最初这个问题是标签没有注册。现在已经使用正确的装饰符号修复了该问题。现在的问题是标签的内容没有显示。因此,我在Django inclusion_tag contents not displaying
创建了一个新问题由于
答案 0 :(得分:3)
您似乎在这里缺少装饰符号:
register.inclusion_tag("forum.html")
应为@register.inclusion_tag("forum.html")