Catching up on a few posts…. I’ve been making progress, but failing to post about them, so here goes:
On Day 4, which was roughly 5 days ago, I took Lecture 5 of the Learn Python Django from scratch course. Basically, this lecture was about using the ‘Django app directory’ to store the views that map to the HTML used to display the app content. Take a look at the code:
We defined a few new methods to handle a couple different cases. The first method takes care of the case where a request is made to the website for ALL of the articles in the web app. The second method takes a parameter, the article id, and it returns the article requested to the articles view for display purposes.
Where do we define these request cases? In the url.py file:
You can see the regular expression that represents the /all/ URL, which passes the request on to the articles (plural) method. The other regular expression /get/ some_number /, will pass the number in the URL as the id parameter in the article (singular) method.
Finally, we had to create the views template to handle both requests. Have a look:
Quite simple, here. For all the articles returned in either method call, the for loop in the HTML will display 1 or all of the articles data requested.
That’s it. Onto blogging the next day…