Skip to content

Commit

Permalink
Modified templates to display posts from datebase
Browse files Browse the repository at this point in the history
  • Loading branch information
findman committed Feb 21, 2016
1 parent 2d379b8 commit ae98273
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
20 changes: 20 additions & 0 deletions blog/templates/blog/post_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div>
<h1><a href="/">Django Girls Blog</a></h1>
</div>

{% for post in posts %}
<div>
<p>published: {{ post.published_date }}</p>
<h1><a href="">{{ post.title }}</a></h1>
<p>{{ post.text|linebreaks }}</p>
</div>
{% endfor %}
</body>
</html>
6 changes: 6 additions & 0 deletions blog/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.conf.urls import url
from . import views

urlpatterns=[
url(r'^$',views.post_list,name='post_list')
]
7 changes: 7 additions & 0 deletions blog/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
from django.shortcuts import render
from django.utils import timezone
from .models import Post

# Create your views here.

def post_list(request):
posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
return render(request,'blog/post_list.html',{'posts':posts})

3 changes: 2 additions & 1 deletion mysite/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.conf.urls import include,url
from django.contrib import admin

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'',include('blog.urls')),
]

0 comments on commit ae98273

Please sign in to comment.