feat: loaded new template on views.py

parent f5660e23
{% if posts_list %} {% if posts_list %}
<ul> <ul>
{% for post in posts_list %} {% 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 %} {% endfor %}
</ul> </ul>
{% else %} {% else %}
......
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from django.template import loader
from .models import Post, Reply from .models import Post, Reply
# Create your views here. # Create your views here.
def index(request): def index(request):
posts_list = Post.objects.order_by("pub_date") posts_list = Post.objects.order_by("pub_date")
output = "<br>".join([p.post_title for p in posts_list]) template = loader.get_template("forum/index.html")
view = "Welcome to Widget's Forum! <br>" + output context = {
return HttpResponse(view) "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!") # return HttpResponse("Welcome to Widget's forum!")
# def welcome(request): # 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