Skip to content

Commit

Permalink
Added URLs, views, and templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
yahyaaly151989 committed Aug 20, 2023
1 parent 6c4e429 commit 1020e90
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 3 deletions.
Binary file modified Module01/mysite/blog/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file modified Module01/mysite/blog/__pycache__/views.cpython-311.pyc
Binary file not shown.
92 changes: 92 additions & 0 deletions Module01/mysite/blog/static/css/blog.css
Original file line number Diff line number Diff line change
@@ -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;
}
19 changes: 19 additions & 0 deletions Module01/mysite/blog/templates/blog/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% load static %}

<!DOCTYPE html>
<html>
<head>
<title>{% block title %}{% endblock %}</title>
<link href="{% static "css/blog.css" %}" rel="stylesheet">
</head>
<body>
<div id="content">
{% block content %}
{% endblock %}
</div>
<div id="sidebar">
<h2>My blog</h2>
<p>This is my blog.</p>
</div>
</body>
</html>
11 changes: 11 additions & 0 deletions Module01/mysite/blog/templates/blog/post/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "blog/base.html" %}

{% block title %}{{ post.title }}{% endblock %}

{% block content %}
<h1>{{ post.title }}</h1>
<p class="date">
Published {{ post.publish }} by {{ post.author }}
</p>
{{ post.body|linebreaks }}
{% endblock %}
19 changes: 19 additions & 0 deletions Module01/mysite/blog/templates/blog/post/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "blog/base.html" %}

{% block title %}My Blog{% endblock %}

{% block content %}
<h1>My Blog</h1>
{% for post in posts %}
<h2>
<a href="{% url 'blog:post_detail' post.id %}">
{{ post.title }}
</a>
</h2>
<p class="date">
Published {{ post.publish }} by {{ post.author }}
</p>
{{ post.body|truncatewords:30|linebreaks }}
<hr />
{% endfor %}
{% endblock %}
3 changes: 2 additions & 1 deletion Module01/mysite/blog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
app_name = 'blog'

urlpatterns = [

path('', views.post_list, name='post_list'),
path('<int:id>/', views.post_detail, name='post_detail'),
]
11 changes: 9 additions & 2 deletions Module01/mysite/blog/views.py
Original file line number Diff line number Diff line change
@@ -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})
Binary file modified Module01/mysite/db.sqlite3
Binary file not shown.

0 comments on commit 1020e90

Please sign in to comment.