Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit908e5db

Browse files
committed
AWS and Heroku Code
1 parent60d2584 commit908e5db

File tree

47 files changed

+1078
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1078
-0
lines changed

‎Django_Blog/13-AWS-S3-Uploads/django_project/blog/__init__.py

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fromdjango.contribimportadmin
2+
from .modelsimportPost
3+
4+
admin.site.register(Post)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fromdjango.appsimportAppConfig
2+
3+
4+
classBlogConfig(AppConfig):
5+
name='blog'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated by Django 2.1 on 2018-08-28 02:32
2+
3+
fromdjango.confimportsettings
4+
fromdjango.dbimportmigrations,models
5+
importdjango.db.models.deletion
6+
importdjango.utils.timezone
7+
8+
9+
classMigration(migrations.Migration):
10+
11+
initial=True
12+
13+
dependencies= [
14+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
15+
]
16+
17+
operations= [
18+
migrations.CreateModel(
19+
name='Post',
20+
fields=[
21+
('id',models.AutoField(auto_created=True,primary_key=True,serialize=False,verbose_name='ID')),
22+
('title',models.CharField(max_length=100)),
23+
('content',models.TextField()),
24+
('date_posted',models.DateTimeField(default=django.utils.timezone.now)),
25+
('author',models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,to=settings.AUTH_USER_MODEL)),
26+
],
27+
),
28+
]

‎Django_Blog/13-AWS-S3-Uploads/django_project/blog/migrations/__init__.py

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
fromdjango.dbimportmodels
2+
fromdjango.utilsimporttimezone
3+
fromdjango.contrib.auth.modelsimportUser
4+
fromdjango.urlsimportreverse
5+
6+
7+
classPost(models.Model):
8+
title=models.CharField(max_length=100)
9+
content=models.TextField()
10+
date_posted=models.DateTimeField(default=timezone.now)
11+
author=models.ForeignKey(User,on_delete=models.CASCADE)
12+
13+
def__str__(self):
14+
returnself.title
15+
16+
defget_absolute_url(self):
17+
returnreverse('post-detail',kwargs={'pk':self.pk})
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
body {
2+
background:#fafafa;
3+
color:#333333;
4+
margin-top:5rem;
5+
}
6+
7+
h1,h2,h3,h4,h5,h6 {
8+
color:#444444;
9+
}
10+
11+
ul {
12+
margin:0;
13+
}
14+
15+
.bg-steel {
16+
background-color:#5f788a;
17+
}
18+
19+
.site-header .navbar-nav .nav-link {
20+
color:#cbd5db;
21+
}
22+
23+
.site-header .navbar-nav .nav-link:hover {
24+
color:#ffffff;
25+
}
26+
27+
.site-header .navbar-nav .nav-link.active {
28+
font-weight:500;
29+
}
30+
31+
.content-section {
32+
background:#ffffff;
33+
padding:10px20px;
34+
border:1px solid#dddddd;
35+
border-radius:3px;
36+
margin-bottom:20px;
37+
}
38+
39+
.article-title {
40+
color:#444444;
41+
}
42+
43+
a.article-title:hover {
44+
color:#428bca;
45+
text-decoration: none;
46+
}
47+
48+
.article-content {
49+
white-space: pre-line;
50+
}
51+
52+
.article-img {
53+
height:65px;
54+
width:65px;
55+
margin-right:16px;
56+
}
57+
58+
.article-metadata {
59+
padding-bottom:1px;
60+
margin-bottom:4px;
61+
border-bottom:1px solid#e3e3e3
62+
}
63+
64+
.article-metadataa:hover {
65+
color:#333;
66+
text-decoration: none;
67+
}
68+
69+
.article-svg {
70+
width:25px;
71+
height:25px;
72+
vertical-align: middle;
73+
}
74+
75+
.account-img {
76+
height:125px;
77+
width:125px;
78+
margin-right:20px;
79+
margin-bottom:16px;
80+
}
81+
82+
.account-heading {
83+
font-size:2.5rem;
84+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% extends "blog/base.html" %}
2+
{% block content %}
3+
<h1>About Page</h1>
4+
{% endblock content %}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{% load static %}
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
6+
<!-- Required meta tags -->
7+
<metacharset="utf-8">
8+
<metaname="viewport"content="width=device-width, initial-scale=1, shrink-to-fit=no">
9+
10+
<!-- Bootstrap CSS -->
11+
<linkrel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"crossorigin="anonymous">
12+
13+
<linkrel="stylesheet"type="text/css"href="{% static 'blog/main.css' %}">
14+
15+
{% if title %}
16+
<title>Django Blog - {{ title }}</title>
17+
{% else %}
18+
<title>Django Blog</title>
19+
{% endif %}
20+
</head>
21+
<body>
22+
<headerclass="site-header">
23+
<navclass="navbar navbar-expand-md navbar-dark bg-steel fixed-top">
24+
<divclass="container">
25+
<aclass="navbar-brand mr-4"href="{% url 'blog-home' %}">Django Blog</a>
26+
<buttonclass="navbar-toggler"type="button"data-toggle="collapse"data-target="#navbarToggle"aria-controls="navbarToggle"aria-expanded="false"aria-label="Toggle navigation">
27+
<spanclass="navbar-toggler-icon"></span>
28+
</button>
29+
<divclass="collapse navbar-collapse"id="navbarToggle">
30+
<divclass="navbar-nav mr-auto">
31+
<aclass="nav-item nav-link"href="{% url 'blog-home' %}">Home</a>
32+
<aclass="nav-item nav-link"href="{% url 'blog-about' %}">About</a>
33+
</div>
34+
<!-- Navbar Right Side -->
35+
<divclass="navbar-nav">
36+
{% if user.is_authenticated %}
37+
<aclass="nav-item nav-link"href="{% url 'post-create' %}">New Post</a>
38+
<aclass="nav-item nav-link"href="{% url 'profile' %}">Profile</a>
39+
<aclass="nav-item nav-link"href="{% url 'logout' %}">Logout</a>
40+
{% else %}
41+
<aclass="nav-item nav-link"href="{% url 'login' %}">Login</a>
42+
<aclass="nav-item nav-link"href="{% url 'register' %}">Register</a>
43+
{% endif %}
44+
</div>
45+
</div>
46+
</div>
47+
</nav>
48+
</header>
49+
<mainrole="main"class="container">
50+
<divclass="row">
51+
<divclass="col-md-8">
52+
{% if messages %}
53+
{% for message in messages %}
54+
<divclass="alert alert-{{ message.tags }}">
55+
{{ message }}
56+
</div>
57+
{% endfor %}
58+
{% endif %}
59+
{% block content %}{% endblock %}
60+
</div>
61+
<divclass="col-md-4">
62+
<divclass="content-section">
63+
<h3>Our Sidebar</h3>
64+
<pclass='text-muted'>You can put any information here you'd like.
65+
<ulclass="list-group">
66+
<liclass="list-group-item list-group-item-light">Latest Posts</li>
67+
<liclass="list-group-item list-group-item-light">Announcements</li>
68+
<liclass="list-group-item list-group-item-light">Calendars</li>
69+
<liclass="list-group-item list-group-item-light">etc</li>
70+
</ul>
71+
</p>
72+
</div>
73+
</div>
74+
</div>
75+
</main>
76+
77+
<!-- Optional JavaScript -->
78+
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
79+
<scriptsrc="https://code.jquery.com/jquery-3.2.1.slim.min.js"integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"crossorigin="anonymous"></script>
80+
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"crossorigin="anonymous"></script>
81+
<scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"crossorigin="anonymous"></script>
82+
</body>
83+
</html>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{% extends "blog/base.html" %}
2+
{% block content %}
3+
{% for post in posts %}
4+
<articleclass="media content-section">
5+
<imgclass="rounded-circle article-img"src="{{ post.author.profile.image.url }}">
6+
<divclass="media-body">
7+
<divclass="article-metadata">
8+
<aclass="mr-2"href="{% url 'user-posts' post.author.username %}">{{ post.author }}</a>
9+
<smallclass="text-muted">{{ post.date_posted|date:"F d, Y" }}</small>
10+
</div>
11+
<h2><aclass="article-title"href="{% url 'post-detail' post.id %}">{{ post.title }}</a></h2>
12+
<pclass="article-content">{{ post.content }}</p>
13+
</div>
14+
</article>
15+
{% endfor %}
16+
{% if is_paginated %}
17+
18+
{% if page_obj.has_previous %}
19+
<aclass="btn btn-outline-info mb-4"href="?page=1">First</a>
20+
<aclass="btn btn-outline-info mb-4"href="?page={{ page_obj.previous_page_number }}">Previous</a>
21+
{% endif %}
22+
23+
{% for num in page_obj.paginator.page_range %}
24+
{% if page_obj.number == num %}
25+
<aclass="btn btn-info mb-4"href="?page={{ num }}">{{ num }}</a>
26+
{% elif num> page_obj.number|add:'-3' and num<page_obj.number|add:'3' %}
27+
<aclass="btn btn-outline-info mb-4"href="?page={{ num }}">{{ num }}</a>
28+
{% endif %}
29+
{% endfor %}
30+
31+
{% if page_obj.has_next %}
32+
<aclass="btn btn-outline-info mb-4"href="?page={{ page_obj.next_page_number }}">Next</a>
33+
<aclass="btn btn-outline-info mb-4"href="?page={{ page_obj.paginator.num_pages }}">Last</a>
34+
{% endif %}
35+
36+
{% endif %}
37+
{% endblock content %}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% extends "blog/base.html" %}
2+
{% block content %}
3+
<divclass="content-section">
4+
<formmethod="POST">
5+
{% csrf_token %}
6+
<fieldsetclass="form-group">
7+
<legendclass="border-bottom mb-4">Delete Post</legend>
8+
<h2>Are you sure you want to delete the post "{{ object.title }}"</h2>
9+
</fieldset>
10+
<divclass="form-group">
11+
<buttonclass="btn btn-outline-danger"type="submit">Yes, Delete</button>
12+
<aclass="btn btn-outline-secondary"href="{% url 'post-detail' object.id %}">Cancel</a>
13+
</div>
14+
</form>
15+
</div>
16+
{% endblock content %}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{% extends "blog/base.html" %}
2+
{% block content %}
3+
<articleclass="media content-section">
4+
<imgclass="rounded-circle article-img"src="{{ object.author.profile.image.url }}">
5+
<divclass="media-body">
6+
<divclass="article-metadata">
7+
<aclass="mr-2"href="{% url 'user-posts' object.author.username %}">{{ object.author }}</a>
8+
<smallclass="text-muted">{{ object.date_posted|date:"F d, Y" }}</small>
9+
{% if object.author == user %}
10+
<div>
11+
<aclass="btn btn-secondary btn-sm mt-1 mb-1"href="{% url 'post-update' object.id %}">Update</a>
12+
<aclass="btn btn-danger btn-sm mt-1 mb-1"href="{% url 'post-delete' object.id %}">Delete</a>
13+
</div>
14+
{% endif %}
15+
</div>
16+
<h2class="article-title">{{ object.title }}</h2>
17+
<pclass="article-content">{{ object.content }}</p>
18+
</div>
19+
</article>
20+
{% endblock content %}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% extends "blog/base.html" %}
2+
{% load crispy_forms_tags %}
3+
{% block content %}
4+
<divclass="content-section">
5+
<formmethod="POST">
6+
{% csrf_token %}
7+
<fieldsetclass="form-group">
8+
<legendclass="border-bottom mb-4">Blog Post</legend>
9+
{{ form|crispy }}
10+
</fieldset>
11+
<divclass="form-group">
12+
<buttonclass="btn btn-outline-info"type="submit">Post</button>
13+
</div>
14+
</form>
15+
</div>
16+
{% endblock content %}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{% extends "blog/base.html" %}
2+
{% block content %}
3+
<h1class="mb-3">Posts by {{ view.kwargs.username }} ({{ page_obj.paginator.count }})</h1>
4+
{% for post in posts %}
5+
<articleclass="media content-section">
6+
<imgclass="rounded-circle article-img"src="{{ post.author.profile.image.url }}">
7+
<divclass="media-body">
8+
<divclass="article-metadata">
9+
<aclass="mr-2"href="{% url 'user-posts' post.author.username %}">{{ post.author }}</a>
10+
<smallclass="text-muted">{{ post.date_posted|date:"F d, Y" }}</small>
11+
</div>
12+
<h2><aclass="article-title"href="{% url 'post-detail' post.id %}">{{ post.title }}</a></h2>
13+
<pclass="article-content">{{ post.content }}</p>
14+
</div>
15+
</article>
16+
{% endfor %}
17+
{% if is_paginated %}
18+
19+
{% if page_obj.has_previous %}
20+
<aclass="btn btn-outline-info mb-4"href="?page=1">First</a>
21+
<aclass="btn btn-outline-info mb-4"href="?page={{ page_obj.previous_page_number }}">Previous</a>
22+
{% endif %}
23+
24+
{% for num in page_obj.paginator.page_range %}
25+
{% if page_obj.number == num %}
26+
<aclass="btn btn-info mb-4"href="?page={{ num }}">{{ num }}</a>
27+
{% elif num> page_obj.number|add:'-3' and num<page_obj.number|add:'3' %}
28+
<aclass="btn btn-outline-info mb-4"href="?page={{ num }}">{{ num }}</a>
29+
{% endif %}
30+
{% endfor %}
31+
32+
{% if page_obj.has_next %}
33+
<aclass="btn btn-outline-info mb-4"href="?page={{ page_obj.next_page_number }}">Next</a>
34+
<aclass="btn btn-outline-info mb-4"href="?page={{ page_obj.paginator.num_pages }}">Last</a>
35+
{% endif %}
36+
37+
{% endif %}
38+
{% endblock content %}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fromdjango.testimportTestCase
2+
3+
# Create your tests here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
fromdjango.urlsimportpath
2+
from .viewsimport (
3+
PostListView,
4+
PostDetailView,
5+
PostCreateView,
6+
PostUpdateView,
7+
PostDeleteView,
8+
UserPostListView
9+
)
10+
from .importviews
11+
12+
urlpatterns= [
13+
path('',PostListView.as_view(),name='blog-home'),
14+
path('user/<str:username>',UserPostListView.as_view(),name='user-posts'),
15+
path('post/<int:pk>/',PostDetailView.as_view(),name='post-detail'),
16+
path('post/new/',PostCreateView.as_view(),name='post-create'),
17+
path('post/<int:pk>/update/',PostUpdateView.as_view(),name='post-update'),
18+
path('post/<int:pk>/delete/',PostDeleteView.as_view(),name='post-delete'),
19+
path('about/',views.about,name='blog-about'),
20+
]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp