Python Django Tutorial: Full-Featured Web App Part 3 - Templates
Why Stack Overflow recommends it
Stack Overflow users link it when they are following the series and need the reference walkthrough for template context, base.html inheritance and static CSS loading, or as a model for debugging their own copy.
Recommended by 2 people across 2 different months, 2019 to 2022.
What it is
Part 3 of Corey Schafer's Django blog series covers templates: returning richer HTML from views, passing variables to templates as context, and building a base template with inheritance. It also adds Bootstrap and static CSS to the project. It is a 45-minute screen-recorded coding tutorial.
What people said
Recommends aimlesslegs · 2019-01 · Stack Overflow · on “How can I get bootstrap to center this rendered django template?”
I've seen in some tutorials (possibly for earlier versions of Bootstrap) that divs with class "container" are supposed to automatically center. <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> <title>Results</title> <!-- Bootstrap core CSS --> <link rel="stylesheet" href=" [LINK] " integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> </head> <body> <div class="containter"> <p>I sh
Recommends Humza · 2021-01 · Stack Overflow · on “Django: active Home link”
are you using a base.html with templates that build on that? because if not then try look up some tutorials like this [this video] which will show you what my answer is doing. if you can't see the menu then it's because you're not using the template which has the block filled in
Cites James Smith · 2019-02 · Stack Overflow · on “Django - name 'title' is not defined”
An hour ago I started to make a web application, with Django. I watched this video [this video] I'm following all his steps, but after changing some stuff, I've got an error which says title is not defined in /about/. 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>
Cites Geara0 · 2019-10 · Stack Overflow · on “Why html skips my variable and how can I fix it?”
The whole point is that "{{some_variable}}" just disappears in my work, while that not happens in any other example (that i could find) views.py def home(request): data = { 'title':'Main page' } home.html <title>{{ title }}</title> browser page => show code <title></title> Why he just skipped title ? It definitely worked in the tutorial. I'm trying to achieve page title being "Main page", but i want to do it by reffering to title dictionary. I'm saying about tutorial as example of the same code, that worked. But if anyone needs to watch smth similar: [this video] 16:00 And my thanks goes to... furas (Please write it as answer, I need to tick it) I did return render(request, 'blog/home.html') But
Cites Braden · 2020-05 · Stack Overflow · on “Django project will not load in CSS files”
I am currently directly following the tutorial here: [this video] about setting up a blog website through Django. When I attempt to load in my CSS files, I obtain the same screen that the person in the video was achieving @38:01, when he claims the css wasn't loading in (I have restarted my server many times so that isn't the issue). For reference it should look like the screen @38:51 No colors and the header bar is mixed with the page header. I am able to open up the css through the source code on the browser, so it must be being referenced correctly; however here is my relevant code: to reference the static files in settings.py (Note I had it exactly like how it is in the video and changed it t
Cites BlackMagic · 2021-02 · Stack Overflow · on “Bootstrap Code not Displaying Correctly in Webpage”
So I am practicing working with Python and Django using Corey Schafer's YouTube series, where we are just making a blog page. [this video] Everything was going well, but when I added the bootstrap code I noticed that my web page wasn't showing up how I expected. In the tutorial his page originally showed up exactly how mine did, but he was able to kill the terminal and refresh the page to have it load correctly. When I attempted that nothing happened. I also tried to clear my browser cache as he suggested could be a potential solution, but that didn't help much either. Here is my main.css in my templates\blog\static\blog directory: body { background: #fafafa; color: #333333; margin-top: 5rem; } h
Cites Crownofhay · 2021-10 · Stack Overflow · on “Template Inheritance Does Not Work - Django Tutorial”
I am following Corey Schafer' Django tutorial [this video] . I have reached where I have to create a base.html template inheritance. After adjusting everything according to my project and running the server, my webpage presents itself as a source code in html format. click to see the page after server run [LINK] . My views.py code: from django.shortcuts import render from django.http import HttpResponse from django.template import loader # Create your views here. def index(request): text = "welcome to the website - python" posts = [ { 'title': 'The Fault in Our Stars', 'price': '3.0 BD', 'post_date': '24-10-2021' }, { 'title': 'The Black Swan', 'price': '3.5 BD', 'post_date': '23-10-2021' }, { 't
Cites Amir Guliyev · 2022-12 · Stack Overflow · on “Problem with INSTALLED_APPS in django settings.py file”
If I try to add blog.apps.BlogConfig string to INSTALLED_APPS (to define the blog app), local server won't start giving me an error. Photos attached below: [LINK] [LINK] I am expecting for the separate section to appear on site. Was doing it by tutorial of the Youtuber Corey Schafer: [this video]