Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Create Your Templates: Part 1

In this lesson, you’re going to revisit templates and deal with the TemplateDoesNotExist error you saw in the previous lesson.

You’re going to make a new html file, all_projects.html, in your double folder structure. When you’ve created your template and made sure Django knows where to find it, it can be rendered.

Comments & Discussion

reblark on Oct. 29, 2019

When I shut everything down and then return, how do I get back into the virtual environment in the directory where my app is?

reblark on Oct. 29, 2019

I am using Pycharm. I made a change in, removing project_list and replacing it with all_projects. I cannot start the server because it keeps returning an attribute err that the module projects.views has no attribute ‘project_list’. Clearly, it still sees project_list and doesn’t recognize the change in code. How do I fix this?

Martin Breuss RP Team on Oct. 30, 2019

Virtual environment

You can always access your virtual environment by moving into the folder that contains your virtual environment folder, and then activating it with the following command:

source your_env_name/bin/activate

You should see the name of your venv pop up on the left side of your command prompt. That means that you’ve successfully activated it.

Changes in

It’s difficult to say what exactly is happening in your case. There could be many reasons for this and it’s difficult to diagnose without seeing your code. However, here are a couple of tips of what you can check up on:

  • Double-check your projects/ file. Did you edit this file, or maybe accidentally another one?
  • Check in your file whether you are still pointing to a function called project_list in your URLs
  • If neither of those resolves it, head over and google your error

Hope this helps resolving it

Siggi Berg on Dec. 30, 2019

Hi there. Exciting stuff Django but I have a problem with having the database object to show up in the browser. * <QuerySet [<Project: Project object (1)>]> (no datbase object) The django code in all_projects.html may be wrong but I can´t figure it out. This is how it looks like: * <body> {{ projects }}\n {% for project in projects %}\n \t<p>{{ project.description }}</p>\n {% endfor %}

grinsekatz007 on April 19, 2020

do i need to activate django templating language somewhere ? because in my case, its being ignored. Im using Pycharm

kind regards

Martin Breuss RP Team on April 19, 2020

Hi @Siggi Berg, totally missed your comment here. Did you manage to figure this out? I assume your code in the template looked like this:

{{ projects }}
{% for project in projects %}
    <p>{{ project.description }}</p>
{% endfor %}

The code looks fine as long as you are passing a QuerySet object containing all your Project objects to the template:

  • {{ projects }} will display a string of the QuerySet object - this might look like the string you posted in your question: <QuerySet [<Project: Project object (1)>]> (= a QuerySet object containing one Project object). You don’t need to display this collection. Instead you do what you did below with the
  • {% for item in collection %}. This will iterate over all the Project objects inside of your QuerySet object, and create a paragraph containing the description of each Project

So I’d need to know in more detail what is being displayed in the template when it renders, and what you are passing in. Maybe these hints can help someone else running into a similar issue.

Martin Breuss RP Team on April 19, 2020

Hello @grinsekatz007. There’s no need to activate the Django templating language anywhere. If you are working with the file within a Django project context, and the file has a .html ending, then Django templating language should work.

Can you describe in more detail what you are doing and what is/isn’t working? You could also link to a GitHub repo with your code, that makes it easier to check and refer to what’s going on.

tomislavm021 on July 20, 2020

I keep getting the error : Class ‘Project’ has no ‘objects’ member

What can i do?

Martin Breuss RP Team on July 21, 2020

Hi @tomislavm021 - are you receiving this as an error or as a warning? If it is a warning, which means your code still works as expected, then it might be related to some linter tool that you have installed on your text editor. Check out this StackOverflow answer for more details.

If it’s actually an error, meaning that your app doesn’t work because of it, then please share a link to your code repo so I can take a look. The most likely place to check on for possible errors would be - e.g. is your model inheriting from Django’s models.Model?

Hope this helps!

mathv87 on July 28, 2020

I had a similar problem with this task. However I found out that it is very important to not confuse the {{ }} with {% %}. It generates the error message “could not parse ..” when you would for example write something like {{% %}}.

Martin Breuss RP Team on July 30, 2020

Thanks for sharing @mathv87. :) Yes, in Django’s templating language there’s a difference to keep in mind between:

  • Template Variables: which are used to display the value of variables present in your code, and which use the {{ }} syntax, and
  • Template Logic: which is used to write code logic inside your template, that Django will execute. Code blocks use the {% %} syntax

As you mentioned, Django will tell you if something’s wrong in that department with an error message similar to “Could not parse” if you try to use syntax aside from those two. That’s good, because you get helpful feedback :)

Become a Member to join the conversation.