Individual blog pages - Django Web Development with Python 10

preview_player
Показать описание
In this 10th Django web development with Python tutorial, we're going to cover creating more dynamic URLs. In our case, we need to have URL handling for a URL that has something like /blog/2/, where the 2 corresponds to the 2nd blog post.

As you may have guessed, Django saw this coming, and has you covered. In our case, and in many cases, the 2 is the table's Primary Key. A primary key is a unique identifier per table in a database, no other entry should have the same primary key as another. Because of this, having a Primary Key makes for an easy way to lookup elements and is common practice. Because of this, Django has built this premise in quite deeply.

Рекомендации по теме
Комментарии
Автор

For those of you on Django 2.0 +
path('(?P<pk>(\d+))', DetailView.as_view(model=Post, template_name="blog/post.html")),
will not work.
USE:
from django.urls import re_path
re_path('(?P<pk>(\d+))', DetailView.as_view(model=Post, template_name="blog/post.html")),

MrCrocker
Автор

these were the easiest tutorials i have ever seen that show you how to make a simple useful blog, django is awsome, thank u Harrison

ermalabiti
Автор

Please make more videos like users commenting and liking the blogs and registration for the users and stuff :)

Rijndhadu
Автор

This series got me realy, realy excited about Django. I love it...

noisytim
Автор

Very approachable Django tutorial. Good job.

adaw.
Автор

In case anyone might find it useful, in Django 2 the path statement to replace the url statement for showing the blog posts is:

path('<int:pk>', DetailView.as_view(model=Post, template_name='blog/post.html')),

This does in fact say the same thing as the url statement with the regex and will only accept numbers (no SQL injection).

PS. sorry about not displaying the code as code - this is my very first comment on YouTube! (I will find out about formatting code - whether I could just have used HTML ...)

richardsedger
Автор

Took your course after Mozilla basic course on Django in text form. Solidified my understanding firmly!

MurtagBY
Автор

Hey sentdex!

Decision in post.html to make <div> tag is default container class was not pretty than col-sm-10, if your menu is col-sm-2 class.
So this can look like this:
<div class = "col-sm-10">
{{post.body|safe|linebreaks}}
</div>

Thank you for all your tutorials!

kain
Автор

Really good tuts. I not good understand english, but understand this tut :D Thank you a lot man!

tadeuskozlovski
Автор

I love your videos ! Thanks a lot for a great explanation of Django :)

kamiillka
Автор

no rendering of a post.html template through an error called 404 ----> post.html is not opening when I clicked to the title block... but in my browser search bar the primary is showing .... I don't know what to do ---> failure of tutorial 10

SuDbeat
Автор

in my admin page instead of showing title of the blogs it's showing post object for every blog that i've written.
but in the home page the title of the blog is shown. What is the problem??

ankeshkumarsuman
Автор

These have been great for getting me to understand Django. I'm having a far easier time understanding this than Flask, and I really liked Flask. I'm excited.

*Question, though:* I'm trying to make a random generator that picks from several banks of words and mashes a small sentence out of the words. I essentially need *4 separate tables* full of words, but I only need to take *one word out of each table*, at random. I've figured out how to order_by to get a random result, because my table will be far fewer than a few hundred entries per table, so it shouldn't be too slow.

Do I need to have 4 separate classes (to make different tables) in my app's model.py?

Neceros
Автор

to improve your windows experience: open a folder, click "Organize" in the top left corner, "folder and search options", "view", uncheck "hide extensions for known file types"

skillgambling
Автор

the class name was Post, but in post.html, you could use post.title and post.body without referencing 'post'. I thought we should use Post.body here instead of post.body. Can you explain this? I am a little confused here because in blog.html, you used 'post' after you reference it with {% for post in object_list %}, but in post.html, you directly used post.

elimujiangebula
Автор

I don't understand how we are able to reference the 'P'ost contents by using 'p'ost in post.html

vathsasri
Автор

Hi Sentdex, can you please explain how the post (p in lower) in post.html is working? Means it has not been defined anywhere..

bijaysharma
Автор

It would be great if you covered how to add categories in this series. Categories are one of the 'tough' parts in Django for many people but I am speaking for myself too. Thanks.

kwameboame
Автор

i have a doubt.... in your blog.html you actually created the variable "post" by doing {% for post in object_list %} but in the post.html we started using post as a variable without even creating one. Please explain how we got the post variable in post.html :)

blazzy
Автор

Great tutorial, got to this point and we're already using a database - Python/ Django rocks...!

One thing why don't you have file extensions showing in Windows though.. it really bugs me! :)

DaveMcGarry
visit shbcf.ru