Locked learning resources

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

Unlock This Lesson

Locked learning resources

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

Unlock This Lesson

Creating a Dashboard View

In this lesson, you’ll use the following URLS:

  • http://127.0.0.1:8000/dashboard
  • http://127.0.0.1:8000/admin

For more information about concepts covered in this course, you can check out Django’s templates documentation.

00:00 Creating a Dashboard View. Most user management systems have some sort of main page, usually known as a dashboard. You’ll create a dashboard in this section, but because it won’t be the only page in your application, you will also create a base template to keep the looks of the website consistent. Here you won’t be using any of Django’s advanced template features, but if you do need a refresh on the template syntax, then you might want to check out Django’s template documentation at the address seen on-screen.

00:33 All templates used in this course should be placed in the users/templates directory. If the course mentions a template file users/dashboard.html, then the actual file path is users/templates/users/dashboard.html.

00:47 For base.html, the actual path is users/templates/base.html, and so on. The user’s templates directory doesn’t exist by default, so you’ll have to create it. First, here are the commands for Linux and macOS,

01:23 and here are the commands for Windows.

01:45 The structure of your project will then look as seen on-screen. Create a base template called base.html with the content seen on-screen. This base template doesn’t do very much. It shows the message Welcome to Awesome Website and defines a block called content.

02:09 This block is empty for now, and other templates are going to use it to include their own content. Now you can create a template for the dashboard. It should be called users/dashboard.html and should look as seen on-screen.

02:41 This doesn’t add a lot to the base template yet. It just shows the welcome message with a current user’s username. If a user isn’t logged in, then Django will still set the user variable using an AnonymousUser object.

02:56 An anonymous user always has an empty username, so the dashboard will show Hello, Guest! For your template to work, you need to create a view that renders it and a URL that uses the view, as seen on-screen.

03:28 Next, create a users/urls.py file and add the path for the dashboard view.

03:53 Finally, add your application’s URLs to the project’s URLs, as seen on-screen. You can now test the dashboard view. Open the address on-screen, and you should see a web page similar to this one.

04:20 Next open the admin panel at the address seen on-screen and log in as the admin user. When you return to the dashboard, it should look different. As you can see, your new template correctly displays the name of the currently logged-in user.

04:45 Now that you have a working dashboard, in the next section, you’ll start working with Django user management.

Avatar image for edggoncalves

edggoncalves on Feb. 6, 2023

Not sure if it’s just me, but in my scenario, I couldn’t import dashboard without giving close to the full path to views.

Avatar image for edggoncalves

edggoncalves on Feb. 6, 2023

Found the reason why. I just mixed up the placement of the urls.py.

Avatar image for thomabr4

thomabr4 on May 4, 2023

I don’t understand how…

Hello, {{ user.username|default:'Guest' }}!
{% endblock %}

…works. How does the template have access to the user model? Also, we didn’t create this model so I assume user is a prebuilt Django model?

Become a Member to join the conversation.