Fixed up blog posts a bit
This commit is contained in:
parent
0d7ed47d5a
commit
6ada4d0a5d
@ -3,7 +3,9 @@
|
||||
{% block content %}
|
||||
{% if posts %}
|
||||
{% for post in posts %}
|
||||
{{ post.title }}
|
||||
{% with title_links=True %}
|
||||
{% include 'blog/post.html' %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p>No posts are returned for your query.</p>
|
||||
|
8
blog/templates/blog/post.html
Normal file
8
blog/templates/blog/post.html
Normal file
@ -0,0 +1,8 @@
|
||||
<div class="post">
|
||||
<h3>{% if title_links %}<a href="{% url 'blog:read' post.created_at.year post.created_at.month post.created_at.day post.slug %}">{% endif %}{{ post.title }}{% if title_links %}</a>{% else %}<div class="plusone-container"><div class="g-plusone" data-annotation="inline" data-size="small" data-width="300"></div></div>{% endif %}</h3>
|
||||
<p class="article-date">{{ post.created_at|date:'m-d-Y :: H:i' }} by {{ post.user.first_name }} {{ post.user.last_name }}</p>
|
||||
{{ post.content|safe }}
|
||||
{% if not title_links %}
|
||||
<div class="g-plus" data-action="share" data-height="15"></div>
|
||||
{% endif %}
|
||||
</div>
|
@ -1,5 +1,5 @@
|
||||
{% extends "front_base.html" %}
|
||||
|
||||
<div class="post">
|
||||
<h3><a href="{% url 'read' post.created_at.year post.created_at.month post.created_at.day post.slug %}">{{ post.title }}</a></h3>
|
||||
</div>
|
||||
{% block content %}
|
||||
{% include 'blog/post.html' %}
|
||||
{% endblock %}
|
||||
|
12
blog/urls.py
12
blog/urls.py
@ -2,10 +2,10 @@ from django.conf.urls import patterns, url
|
||||
from blog import views
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^$', views.index, name='index'),
|
||||
url(r'^feed$', views.feed, name='feed'),
|
||||
url(r'^(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)/(?P<slug>[^/]+)$', views.read, name='read'),
|
||||
url(r'^resume', views.resume, name='resume'),
|
||||
url(r'^about', views.resume, name='about'),
|
||||
url(r'^disclaimer', views.resume, name='disclaimer'),
|
||||
url(r'^$', views.index, name='index'),
|
||||
url(r'^feed$', views.feed, name='feed'),
|
||||
url(r'^(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)/(?P<slug>[^/]+)$', views.read, name='read'),
|
||||
url(r'^resume', views.resume, name='resume'),
|
||||
url(r'^about', views.resume, name='about'),
|
||||
url(r'^disclaimer', views.resume, name='disclaimer'),
|
||||
)
|
||||
|
@ -4,8 +4,7 @@ from blog.models import Post
|
||||
|
||||
def index(request):
|
||||
last_posts = Post.objects.order_by('-created_at')[:5]
|
||||
context = { 'posts': last_posts }
|
||||
return render(request, 'blog/listing.html', context)
|
||||
return render(request, 'blog/listing.html', {'posts': last_posts})
|
||||
|
||||
def read(request, year, month, day, slug):
|
||||
post = get_object_or_404(Post, created_at__year=int(year), created_at__month=int(month), created_at__day=int(day), slug=slug);
|
||||
|
Loading…
Reference in New Issue
Block a user