from django.shortcuts import render, get_object_or_404
from django.utils import timezone
from .models import Post
# Create your views here.
def post_list(request):
posts = Post.objects.filter(title__contains='post')
return render(request, 'blog/post_list.html', {'posts':posts})
def post_details(request, pk):
posts = get_object_or_404(Post, pk)
return render(request, 'blog/post_details.html', {'posts': posts})
from django.urls import path
from . import views
urlpatterns = [
path('', views.post_list, name='post_list'),
path('posts/<int: pk>/', views.post_details, name='post_details')
]
{% load static %}
<!DOCTYPE html>
<head>
<title>Django reloaded</title>
<link rel="stylesheet" type="text/css" href="{% static 'css/blog.css' %}">
</head>
<body>
<h1>Django Girls Blog </h1>
{% block content %}
{% endblock %}
</body>
</html>
{% extends 'blog/base.html' %}
{% block content %}
{% if post.published_date %}
<h1>{{post.title}}</h1>
{% endif %}
<div>
<p>{{post.body}}</p>
<p><b>{{post.published_date}}</b></p>
</div>
}
{% endblock %}
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/92d0fe6d-dc88-4423-9645-402284ac9877%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
To post to this group, send email to djang...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0a4369bc-2538-4bf7-aaf7-b09be339abec%40googlegroups.com.