python - Regarding django's template, display blog titles one by one without using loop -
currently, challenging build blogsite django.
regarding building blog site, made html following structure using bootstrap(list.html). in structure, don't know how apply title of blog {{ post.title }} using such {% post in posts %}. design image of blog site , simplified sample code expression follows.
div.box-sample{ display: -webkit-flex; display: -moz-flex; display: -ms-flex; display: -o-flex; display: flex; flex-flow: row nowrap; height:300px; } div.box-sample-1{ width:300px; margin:10px; background:#eeeeee; } div.box-sample-2{ width:300px; margin:10px; background:#eeeeee; display: flex; flex-flow: column nowrap; align-items: center; justify-content:center; } div.box-sample-2-1{ width:250px; height:200px; background:#ffebcd; } div.box-sample-2-2{ width:250px; height:200px; background:#fffacd; } body > div > div.box-sample-2 > div > div.box-sample-2-1 > p{ margin-top: 0px; } <body> <div class="box-sample"> <div class="box-sample-1"> <p>{{ post.title }} </p> <!--title no.1--> </div> <div class="box-sample-2"> <div class="box-sample-2-1"> <p>{{ post.title }}</p> <!--title no.2--> </div> <div class="box-sample-2-2"> <p>{{ post.title }}</p> <!--title no.3--> </div> </div> </div> </body> as method apply titles , summaries of blog articles tag in django, see methods in article on internet bunding summary part of title, author, , main text of blog article , sandwiching in loop.
i referred these articles , tried these solutions, there issue each method. cannot implement want.
1. method of sandwiching
<div class="box-sample"> in loop.
-->in method, whole design in attached image loop, different design whole website designed.
2. method of adding class of django
<div class = "box - sample - *"> which located above {{post.title}}, , sandwiching them in loop.
-->this method doesn't work well. example, design collapse because loop if sandwiching in loop.
3. method applying loop each element such
<div class="box-sample-1"> or
<div class="box-sample-2-2"> -->as matter of course, latest article title displayed each element.
as solution other above method, thought using loop in html structure difficult, stopped using loop. , though considered displaying blog title in order putting filter or arguments, etc in {{ post.title }}.
based on idea, searched filters , arguments applied, however, cannot find it.
as ideal method me solve issue, first, retrieving data array title data stored, such post.title [1], post.title [2]..., , these data display {{post.title [1]}}, {{post.title [2]}}... in form.
however, know there no such method. there way closer this?
below descriptions file structure , contents other html in django. teach me element should add or change in these files?
model.py django.db import models django.utils import timezone django.contrib.auth.models import user django.core.urlresolvers import reverse class post(models.model): status_choices = ( ('draft', 'draft'), ('published', 'published'), ) title = models.charfield(max_length=250) class meta: ordering = ('-publish',) def __str__(self): return self.title view.py rom django.shortcuts import render, get_object_or_404 django.core.paginator import paginator, emptypage, pagenotaninteger django.views.generic import listview class postlistview(listview): queryset = post.published.all() context_object_name = 'posts' paginate_by = 10 template_name = 't_env/post/list.html' def post_detail(request, year, month, day, post): post = get_object_or_404(post, slug=post, status='published', publish__year=year, publish__month=month, publish__day=day) return render(request, 't_env/post/detail.html', {'post': post})
if try show {{posts}}, have informations on screen ?
what have writing on urls.py ? have :
# urls.py django.conf.urls import url posts.views import postlistview urlpatterns = [ url(r'^posts/$', postlistview.as_view()), ]
Comments
Post a Comment