James Smith
James Smith

Reputation: 27

Django - name 'title' is not defined

An hour ago I started to make a web application, with Django. I watched this video https://www.youtube.com/watch?v=qDwdMDQ8oX4

I'm following all his steps, but after changing some stuff, I've got an error which says

title is not defined in /about/.

error message ib browser

Here's my code for the route /about/. The code is equal to my other home page, but this one doesn't work.

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    {% if title %}
      <title>Django BLog - {{ title }}</title>
    {% else %}
      <title>Django blog</title>
    {% endif %}
  </head>
  <body>
  </body>
</html>

Upvotes: 0

Views: 866

Answers (1)

Sergio
Sergio

Reputation: 334

As shown in the traceback, title is not defined in your view. This happens because title is not wrapped in quotes so it assumes it's a variable.

Add the quotation marks like so 'title' and you should be fine.

So, you should change line 29 in views.py to

return render(request, 'blog/about.html', {'title': 'About'})

Upvotes: 1

Related Questions