Listing news
Let's go ahead and display the news articles in news.html
:
- In
/news/views.py
, add the following in bold:from django.shortcuts import render from .models import News def news(request): newss = News.objects.all() return render(request, 'news.html', {'newss':newss})
We retrieve the news objects from the database and then pass them to news.html
.
- In
/news/templates/news.html
, display the news objects with the following code:<!DOCTYPE html> <html> <head> <title>Movies App</title> <link href="https://cdn.jsdelivr.net/npm/ [email protected]/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous"> </head> <body...