1

I am not getting ay errors but, I can not get the tag to display it's contents. The contents of 'form' should be 'blah',

File set up is,

enter image description here

crudapp_tags.py

from django import template
register = template.Library()

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

templates/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 does contain the app in 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',
]

The setup seems the same as the answer in this thread, Django - Simple custom template tag example

Why is 'blah' not displaying in forum.html?

Initially this problem was that the tag was not registering. That issue has now been fixed with the correct decorator notation. The issue now is that the contents of the tag are not displaying. Therefore I have created a new question at Django inclusion_tag contents not displaying

Thanks

Community
  • 1
  • 1
Shane G
  • 3,129
  • 10
  • 43
  • 85

1 Answers1

3

Looks like you're missing decoration notation here: register.inclusion_tag("forum.html") should be @register.inclusion_tag("forum.html")

intelis
  • 7,829
  • 14
  • 58
  • 102
  • Thank, I see that I forgot the @ and have put it in now. I also changed the error to what it currently is and put in to the question the complete forum.html file. Still getting the error that the tag is not registered. – Shane G May 22 '16 at 23:16
  • I appears that the commented out line wasn't being ignored, and there was an extra {% endblock %} on line 7. No errors now but 'blah' is not appearing. – Shane G May 23 '16 at 06:31
  • 1
    I added this if statement to forum.html {% results poll %} {% if form %}

    Form exists

    {% endif %} and 'Frorm exists' is not displaying, so I know 'form' in not getting to forum.html
    – Shane G May 23 '16 at 06:37
  • I brought the 'if' inside the {% block homepage %} but still not displaying 'Form' – Shane G May 23 '16 at 06:53
  • I should post this issue again as it has become a different question. Previously the tag wasn't registering, but now it's content is displaying. – Shane G May 23 '16 at 12:16