Skip to content

Commit 17a44bf

Browse files
committed
add section 25 26
1 parent 52753f1 commit 17a44bf

File tree

38 files changed

+821
-0
lines changed

38 files changed

+821
-0
lines changed

section25/application/Pipfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[[source]]
2+
3+
url = "https://pypi.python.org/simple"
4+
verify_ssl = true
5+
name = "pypi"
6+
7+
8+
[packages]
9+
10+
flask = "*"
11+
flask-sqlalchemy = "*"
12+
flask-script = "*"
13+
14+
15+
[dev-packages]
16+
17+
18+
19+
[requires]
20+
21+
python_version = "3.6"

section25/application/Pipfile.lock

Lines changed: 93 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from flask import Flask
2+
from flask_sqlalchemy import SQLAlchemy
3+
4+
app = Flask(__name__)
5+
app.config.from_object('flask_blog.config')
6+
7+
db = SQLAlchemy(app)
8+
9+
from flask_blog.views import views, entries
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SQLALCHEMY_DATABASE_URI = 'sqlite:///flask_blog.db'
2+
SQLALCHEMY_TRACK_MODIFICATIONS = True
3+
DEBUG = True
4+
SECRET_KEY = 'secret key'
5+
USERNAME = 'john'
6+
PASSWORD = 'due123'
12 KB
Binary file not shown.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from flask_blog import db
2+
from datetime import datetime
3+
4+
class Entry(db.Model):
5+
__tablename__ = 'entries'
6+
id = db.Column(db.Integer, primary_key=True)
7+
title = db.Column(db.String(50), unique=True)
8+
text = db.Column(db.Text)
9+
created_at = db.Column(db.DateTime)
10+
11+
def __init__(self, title=None, text=None):
12+
self.title = title
13+
self.text = text
14+
self.created_at = datetime.utcnow()
15+
16+
def __repr__(self):
17+
return '<Entry id:{} title:{} text:{}>'.format(self.id, self.title, self.text)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from flask_script import Command
2+
from flask_blog import db
3+
4+
5+
class InitDB(Command):
6+
"create database"
7+
8+
def run(self):
9+
db.create_all()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.card {
2+
margin: 0.25rem;
3+
}
4+
5+
.blog-body {
6+
padding: 1.25em;
7+
}
8+
9+
* {
10+
font-family: 'Mplus 1p';
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% extends "layout.html" %}
2+
{% block body %}
3+
<form action="{{ url_for('update_entry', id=entry.id) }}" method=post class=add-entry>
4+
<div class="form-group">
5+
<label for="InputTitle">タイトル</label>
6+
<input type="text" class="form-control" id="InputTitle" name=title value={{ entry.title }}>
7+
</div>
8+
<div class="form-group">
9+
<label for="InputText">本文</label>
10+
<textarea class="form-control" id="InputText" name=text rows="3">{{ entry.text | safe }}</textarea>
11+
</div>
12+
<button type="submit" class="btn btn-primary">更新</button>
13+
</form>
14+
15+
{% endblock %}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% extends "layout.html" %}
2+
{% block body %}
3+
<ul class="list-group list-group-flush">
4+
5+
{% for entry in entries %}
6+
<div class="card">
7+
<div class="card-body">
8+
<h5 class="card-title">{{ entry.title }}</h5>
9+
<a href="{{ url_for('show_entry', id=entry.id) }}" class="card-link">続きを読む</a>
10+
</div>
11+
</div>
12+
{% else %}
13+
投稿がありません
14+
{% endfor %}
15+
</ul>
16+
{% endblock %}

0 commit comments

Comments
 (0)