diff --git a/Module01/mysite/blog/__pycache__/urls.cpython-311.pyc b/Module01/mysite/blog/__pycache__/urls.cpython-311.pyc index 54405dd..7fd192e 100644 Binary files a/Module01/mysite/blog/__pycache__/urls.cpython-311.pyc and b/Module01/mysite/blog/__pycache__/urls.cpython-311.pyc differ diff --git a/Module01/mysite/blog/__pycache__/views.cpython-311.pyc b/Module01/mysite/blog/__pycache__/views.cpython-311.pyc index 9bd4309..4a30d2a 100644 Binary files a/Module01/mysite/blog/__pycache__/views.cpython-311.pyc and b/Module01/mysite/blog/__pycache__/views.cpython-311.pyc differ diff --git a/Module01/mysite/blog/static/css/blog.css b/Module01/mysite/blog/static/css/blog.css new file mode 100644 index 0000000..9047395 --- /dev/null +++ b/Module01/mysite/blog/static/css/blog.css @@ -0,0 +1,92 @@ +body { + margin:0; + padding:0; + font-family:helvetica, sans-serif; +} + +a { + color:#00abff; + text-decoration:none; +} + +h1 { + font-weight:normal; + border-bottom:1px solid #bbb; + padding:0 0 10px 0; +} + +h2 { + font-weight:normal; + margin:30px 0 0; +} + +#content { + float:left; + width:60%; + padding:0 0 0 30px; +} + +#sidebar { + float:right; + width:30%; + padding:10px; + background:#efefef; + height:100%; +} + +p.date { + color:#ccc; + font-family: georgia, serif; + font-size: 12px; + font-style: italic; +} + +/* pagination */ +.pagination { + margin:40px 0; + font-weight:bold; +} + +/* forms */ +label { + float:left; + clear:both; + color:#333; + margin-bottom:4px; +} +input, textarea { + clear:both; + float:left; + margin:0 0 10px; + background:#ededed; + border:0; + padding:6px 10px; + font-size:12px; +} +input[type=submit] { + font-weight:bold; + background:#00abff; + color:#fff; + padding:10px 20px; + font-size:14px; + text-transform:uppercase; +} +.errorlist { + color:#cc0033; + float:left; + clear:both; + padding-left:10px; +} + +/* comments */ +.comment { + padding:10px; +} +.comment:nth-child(even) { + background:#efefef; +} +.comment .info { + font-weight:bold; + font-size:12px; + color:#666; +} \ No newline at end of file diff --git a/Module01/mysite/blog/templates/blog/base.html b/Module01/mysite/blog/templates/blog/base.html new file mode 100644 index 0000000..d2a462f --- /dev/null +++ b/Module01/mysite/blog/templates/blog/base.html @@ -0,0 +1,19 @@ +{% load static %} + + + + + {% block title %}{% endblock %} + + + +
+ {% block content %} + {% endblock %} +
+ + + \ No newline at end of file diff --git a/Module01/mysite/blog/templates/blog/post/detail.html b/Module01/mysite/blog/templates/blog/post/detail.html new file mode 100644 index 0000000..5f7f8d8 --- /dev/null +++ b/Module01/mysite/blog/templates/blog/post/detail.html @@ -0,0 +1,11 @@ +{% extends "blog/base.html" %} + +{% block title %}{{ post.title }}{% endblock %} + +{% block content %} +

{{ post.title }}

+

+ Published {{ post.publish }} by {{ post.author }} +

+ {{ post.body|linebreaks }} +{% endblock %} diff --git a/Module01/mysite/blog/templates/blog/post/list.html b/Module01/mysite/blog/templates/blog/post/list.html new file mode 100644 index 0000000..2afbce1 --- /dev/null +++ b/Module01/mysite/blog/templates/blog/post/list.html @@ -0,0 +1,19 @@ +{% extends "blog/base.html" %} + +{% block title %}My Blog{% endblock %} + +{% block content %} +

My Blog

+ {% for post in posts %} +

+ + {{ post.title }} + +

+

+ Published {{ post.publish }} by {{ post.author }} +

+ {{ post.body|truncatewords:30|linebreaks }} +
+ {% endfor %} +{% endblock %} diff --git a/Module01/mysite/blog/urls.py b/Module01/mysite/blog/urls.py index 1e2b93b..d73bb7b 100644 --- a/Module01/mysite/blog/urls.py +++ b/Module01/mysite/blog/urls.py @@ -4,5 +4,6 @@ app_name = 'blog' urlpatterns = [ - + path('', views.post_list, name='post_list'), + path('/', views.post_detail, name='post_detail'), ] \ No newline at end of file diff --git a/Module01/mysite/blog/views.py b/Module01/mysite/blog/views.py index 91ea44a..976f23a 100644 --- a/Module01/mysite/blog/views.py +++ b/Module01/mysite/blog/views.py @@ -1,3 +1,10 @@ -from django.shortcuts import render +from django.shortcuts import render, get_object_or_404 +from .models import Post -# Create your views here. +def post_list(request): + posts = Post.objects.all() + return render(request, 'blog/post/list.html', {'posts': posts}) + +def post_detail(request, id): + post = get_object_or_404(Post, id=id, status=Post.Status.PUBLISHED) + return render(request, 'blog/post/detail.html', {'post': post}) \ No newline at end of file diff --git a/Module01/mysite/db.sqlite3 b/Module01/mysite/db.sqlite3 index 74f5c46..5b5b283 100644 Binary files a/Module01/mysite/db.sqlite3 and b/Module01/mysite/db.sqlite3 differ