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 Customizing the Django Admin Customizing the Detail View Making a Text Preview

Bas Kuunk
Bas Kuunk
21,308 Points

Cannot get preview: TemplateSyntaxError

I closely followed instructions on my local machine, but get an error when I try to change the course:

TemplateSyntaxError at /admin/courses/course/24/change/ Invalid block tag on line 31: 'change_form_object_tools', expected 'endblock'. Did you forget to register or load this tag?

When I comment out line 31 "{% change_form_object_tools %}" in change_form.html, the error disappears, but I cannot see the preview.

Wesley Trayer
Wesley Trayer
13,812 Points

I got the same error, but in workspaces. (My browser is Microsoft Edge)

(A side note)
Copy and paste added a blank line between every line of code in "fieldset.html".

5 Answers

Wesley Trayer
Wesley Trayer
13,812 Points

Got it!

Change the "%" in "{% change_form_object_tools %}", to "{}", so that it looks like this: "{{ change_form_object_tools }}".

Hope this fixes the problem for you, it did for me. :)

honestly, for what these classes cost this sucks

Neil Brown
Neil Brown
22,514 Points

I had the same problem. I solved it by copying and pasting the change_form.html from the django folder installed on my computer. Lib\site-packages\django\contrib\admin\templates\admin\change_form.html.

Bronson Avila
Bronson Avila
4,160 Points

Thanks, Neil. This should be considered the correct response.

Unless your installed version of Django is completely up-to-date with the Django master branch on GitHub, then I think it's likely that some discrepancies between the two versions may lead to errors like the one seen here (I experienced it as well). I only resolved the error by following Neil's advice and copying the template files from my local installation templates rather than those on GitHub (note that I'm coding along on my local machine, not on Workspaces).

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Bas,

The reason for this is that you're using change_form.html from a modern version of Django, but the video and workspace is using 1.8.1. In the old version of Django, the {% object_tools %} block had some hard-coded HTML, but newer versions refer to a tag. If the rest of your Django version is old, that tag won't exist, hence the error.

There are two ways to address this. The simplest way is to just to use the same version of Django as the video (this is basically your only option if you are using Workspaces):

Since Django uses git for version control, we just need to find the commit for the 1.8.1 release. The Django devs make this really easy for us since they tag every commit that corresponds to a release version.

If you go to the project's repo, you'll see in the middle of the page, in a grey box, a link that says something like "206 releases". Click that and it'll take you to the Releases list.

Scroll to the bottom of the page and click Next until you get to the page with the 1.8.1 release (May 1, 2015).

Right underneath that, you'll see a link to a commit: 3d128dc.

Click it and you'll be at the commit summary page. Then click Browse files on the right in the blue box.

You will now find yourself browsing the Django project exactly as it was for version 1.8.1. Any file you open in here will be the 1.8.1 version, which you can copy-paste into your own project and have it work exactly like the video. For example, change_form.html.

The second option (probably better if you are following along on your own machine) is to use the current version of Django across the board. You might have to fix a few minor version-related issues as you progress through the course, but you're going to end up confronting these issues at some point anyway. And by using current-gen Django, you're more able to use your existing portfolio as a reference for future projects.

Hope that helps,

Alex

Wesley Trayer
Wesley Trayer
13,812 Points

Hey Alex Koumparos,

Just wanted to let you know, maybe it's been fixed since I went through, but I also ran into the problem and I was in workspaces.

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Wesley Trayer ,

I noticed that, so that's why I gave recommendations for users both in Workspaces and on their own computers. It was from Workspaces (as of today) that I got the relevant Django version (1.8.1), so the instructions should work exactly as described for Workspace users.

Moreover, if the Workspace version ever changes, the solution above will still work, the only difference will be to browse for the Django tag on GitHub that matches whatever version is in Workspaces (you can quickly check by looking at settings.py) instead of 1.8.1.

Cheers,

Alex