Untitled
plain_text
a month ago
1.1 kB
15
Indexable
Never
from django.http import HttpResponse from django.shortcuts import render # Create your views here. from .models import Article def get_articles(request): articles = Article.objects.filter(status=2) html_response = """ <html> <head> <title>List of articles</title> </head> <body> """ if len(articles) > 0: html_response += """ <table border="1"> <thead> <td>Title</td> <td>Author</td> <td>Published date</td> </thead> <tbody> """ for article in articles: html_response += """ <tr> <td>{}</td> <td>{}</td> <td>{}</td> </tr> """.format(article.title, article.author, article.published_date_start) html_response += """ </tbody> </table> """ html_response += """ </body> </html> """ return HttpResponse(html_response)