GET_ABSOLUTE_URL() explained.
Let’s begin by changing the Models.py file a bit and adding the get_absolute_url() value so we can specify the URL so we can get a Master copy of that page we want to grab. This is also called the following: CANONICAL URL for the object. The following links should help clear things up for you.
get_absolute_url() Link Here &. reverse() utility link here
What we did was change a couple items within the MODELs.py file and list.html file. What we changed is adding a simple django def…. to the Models.py file with is the get_absolute_url() and then we added or changed one line on the html file (list.html). We removed this line
<a href=”{% url ‘blog:post_detail’ post.id %}”>
changed it to look like this now which connects to the Models.py definition – <a href=”{{ post.get_absolute_url }}”>
Change and manipulate URLs.py paths.
Now, let’s create the SEO friendly URLs path for all post within our blog project. We will be using the ‘publish date’ and ‘slug values’. Doing this provide all search engines such as; Google and Bing the ability to index our website pages. Another, piece to this puzzle is making each post unique so we do not have any duplicates uploaded to our database and to do that we will add the following; (unique_for_date= ‘ADD NAME HERE’ You will add this on the (slug) variable within the Post Class inside the Models.py file.
unique_for_date click here for details. (scroll down to that name in bold).
Next, as we have made changes to the Models.py file we must do what???? (makemigrations). to update. do the following type into your terminal.
python manage.py makemigrations
python manage.py migrate
Edit your URLs.py file now.
path(‘<int:id>/’, views.post_detail, name=”post_detail”),
change to this at the bottom
path(‘<int:year>/<int:month>/<int:day>/<slug:post>/’, views.post_detail, name=”post_detail”),
To understand above click on this link for Path Convertors.
Now, modify your VIews.py file as below:

Lastly, modify the Models.py file as such below:

Make sure this code above is inside the Post function. I made the mistake and Had it post inside the Meta function and it did not work but would not show you an error. I submitted my concern on the Django channel and One engineer just answer with a one statement saying ‘Its wrong, move it under Post function.’ that was it and we got the following

Here is the single output once link is clicked:

Pagination Class by Django
First we edit our views.py file and add the following code for pagination our on website blog.
Within the post_list function add these lines: (
post_list = Post.published.all()
paginator = Paginator(post_list, 3)
page_number = request.GET.get(‘page’, 1)
posts = paginator.page(page_number)
Next, create the html template which will utilize this pagination function and make sure its inside the templates folder only no where else.

Lastly add the include statement for this template into your list.html file. Add it under the {% endfor %} statement and then refresh your site and you should see only 3 links on the home page and the next/paginator at the bottom so you can toggle between pages. Pretty cool stuff here and how it all connects and works.
Pagination Errors & Error Handling
Add the ‘EmptyPage” exception to the import statement which matches the paginator import. It s on the same line. Next, create your (try except functionality inside the views ‘post_list’ function. This function protects your code or website from sending you an error or blowing up. The page will present you with the last known post on the site. No matter if you add a page 3 or page 23 it will return the very last post.
That was handling the error for an integer above. Now lets handle anything that is not an integer. Add the following code to the views.py file:
PageNotAnInteger on the import statement
except PageNotAnInteger right above the except EmptyPage exception.
Pagination Information and link
Class Based Views vs Function Based Views
First, they are implemented as Python Objects instead of functions.
Advantages of Class Based Views:
- Organized code by HTTP methods (GET, POST, PUT) in separate methods instead of branching.
- Use Multiple inheritance to create reusable view classes (known as MIXINS)