Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Forms Model Forms Handling Multiple Form Classes

Angel Rivera Vega
Angel Rivera Vega
13,713 Points

{{ block.super }} does not work in question_form.py

My code in question_form.py is the following:

{ % extends "courses/layout.html" %}
{% load course_extras %}

{% block title %}New question for{{ quiz.title }} | {{ quiz.course.title }} {{ block.super }}{% endblock %}

{% block breadcrumbs %}
  <li><a href="{% url 'courses:detail' pk=quiz.course.pk %}">{{ quiz.course.title }}</a></li>
  <li><a href="{% url 'courses:quiz' course_pk=quiz.course.pk step_pk=quiz.pk %}">{{ quiz.title }}</a></li>
{% endblock %}

{% block content %}
  <div class="row columns">
    {{ block.super }}
    <h1>Make a new question</h1>
    <form method="POST" action="">
      {% csrf_token %}
      {{ form.as_p }}
      <input type="submit" class="button" value="Save">
    </form>
  </div>
{% endblock %}

When I run the code, the screen shows me this: "'BlockNode' object has no attribute 'context'. Did you use {{ block.super }} in a base template?"

Let me know any possible solution or question about this problem.

Are you intentionally putting html and Jinja into a python file? They should be written in a .html file. It is possible that this is just a typo, but might be somewhere to start.

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Looks like your problem is in line 1 - you need to remove the space between your opening curly brace and the percent sign. Django isn't able to pull in layout.html, which is why super isn't working.