首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >标记未向inclusion_tag注册

标记未向inclusion_tag注册
EN

Stack Overflow用户
提问于 2016-05-22 22:56:21
回答 1查看 702关注 0票数 1

我不会收到错误,但是,我不能让标签显示它的内容。表格的内容应该是“废话”,

文件设置是,

crudapp_tags.py

代码语言:javascript
复制
from django import template
register = template.Library()

@register.inclusion_tag("forum.html")
def results(poll):
    form = 'blah'
    return {'form': form}

模板/forum.html

代码语言:javascript
复制
{% 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/setings.py确实包含INSTALLED_APPS中的应用程序

代码语言:javascript
复制
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相同。

为什么forum.html中没有显示“blah”?

最初,这个问题是标签没有注册。这个问题现在已经用正确的装饰符号解决了。现在的问题是标签的内容没有显示。因此,我在tag contents not displaying上提出了一个新问题

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-22 23:06:32

看起来这里缺少装饰符号:register.inclusion_tag("forum.html")应该是@register.inclusion_tag("forum.html")

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37380495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档