python - Wrong posts sequence at home page [Django app] -
at home-page i've got exhibited posts on blog, they're sorted incorrectly, oldest post newest(it has reversed). use querysets sort posts order published date in views.py
def home(request):    posts = post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')    return render(request, "home.html", {'posts': posts}) and that's home.html source code:
{% extends "c:\myapp\blog\templates\base.html" %}  {% block content %}  	{% post in posts %}  		<div class="post">  			<div class="date">  				{{ post.published_date }}  			</div>  			<h1><a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a></h1>  			  			<p>{{ post.text|linebreaksbr }}</p>  		</div>  	{% endfor %}  {% endblock content %}could me in reverse these posts? in advance.
you want add - string argument in order_by cause queryset in descending order.
def home(request):    posts = post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')    return render(request, "home.html", {'posts': posts}) notice .order_by('-published_date')
Comments
Post a Comment