Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
So let's now work on that all posts page
in the views.py file that is that posts function here.
Now, there, we are doing something
very simple right now.
We're passing this all posts list,
to the all posts variable in the template.
Well, this all posts list is now an empty list,
and therefore this won't work anymore.
And stepping out I wanna get all the posts
from the database.
And of course that's fairly straightforward.
We can add all posts here and keep that name if we want to,
and then reach out to post, to the post module,
objects.all.
And this gives us all the posts.
Now we can also sort those in any way if we want to,
and actually I'll do that here.
I'll also order those by date
in a descending order to put the latest post first,
but that's of course optional.
But with that, we're now having a list
of all the posts from the database
and we're passing this to all posts in the template.
So now, if we save this and we reload this post page,
we see all free posts here.
Now for a single post,
if I click on that single post we get an error.
And that makes a lot of sense
because we're clearly failing to fetch that single post now.
So now we wanna work on post detail.
And there before, we basically worked with all posts
to find that one post with the correct slug.
Now, of course, that's not what we wanna do anymore.
I wanna get rid of that line of code here,
and we can also get rid of all posts all together here,
since we're not using that anymore.
We can get rid of that date, time imports
since we're not using the date function here anymore.
And we can get rid of that (indistinct) get date function
as well, to slim this file down.
And now back in post detail,
I still wanna get my identified post.
So this name, which I used here,
and now I wanna get a single post.
And you'll learn how that works.
We can use the post model, and then objects,
and then get, instead of all.
And this gets us a single post.
And here, we then can tell Django
how this post should be identified.
In this case that slug,
so that slug field in our post model,
the value there should be equal to the slug value
we're receiving here.
So slug on the right side is this argument,
slug on the left side is the name of that property,
of that attribute in our model.
Now, of course, this could fail
and therefore we could wrap this in a try except blog
to show a 404 page, if it does fail.
But I did show you a little shortcut,
which you can use instead,
where we import from Django shortcuts, not just render,
but also get object or 404.
And with that imported, we can get our post here,
simply by instead calling get, whoops!
Get object or 404,
pass in our post model here
to let Django know for which model it should find
an entry in the database.
And then our condition, which is slug equals slug.
With that we get the identified posts.
And if we now save this,
we should not get this error anymore
but instead a different error related to our image key
which again makes sense here,
because for posted detail
I'm also accessing post.image here,
that was correct before.
Now it's .image_name, so we should fix this.
And with this fixed, if we now reload,
that's looking better.
So now that is generally working
and we are outputting all that post data again.
But of course, we also have to tag
and we have to author the author model.
And I am outputting the author here for example.
I'm simply out putting post.author like this.
And because in the author model I added str,
this is actually I'm putting my full name, so that's good,
but maybe we wanna make this clickable, that name.
We wanna turn this into a link,
and when you click it, we open the mail client.
And maybe we also wanna show the tags of a post.
Let's say here on that post page, below that title.
And therefore these are the next steps
I wanna take in the next lectures.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.