feat: loaded new template on views.py

parent f5660e23
{% if posts_list %}
<ul>
{% for post in posts_list %}
<li><a href="/posts/{{ post.id }}">{{ posts.post_title }}</a></li>
<li><a href="/forum/{{ author.id }}">{{ post.post_title }}</a></li>
{% endfor %}
</ul>
{% else %}
......
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from .models import Post, Reply
# Create your views here.
def index(request):
posts_list = Post.objects.order_by("pub_date")
output = "<br>".join([p.post_title for p in posts_list])
view = "Welcome to Widget's Forum! <br>" + output
return HttpResponse(view)
template = loader.get_template("forum/index.html")
context = {
"posts_list": posts_list,
}
return HttpResponse(template.render(context, request))
# output = "<br>".join([p.post_title for p in posts_list])
# view = "Welcome to Widget's Forum! <br>"
# return HttpResponse(view)
# return HttpResponse("Welcome to Widget's forum!")
# def welcome(request):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment