Chapter 11: Facelift (v0.11)
This commit is contained in:
parent
14f6f99ea9
commit
542fa42312
|
@ -6,6 +6,7 @@ from flask_sqlalchemy import SQLAlchemy
|
||||||
from flask_migrate import Migrate
|
from flask_migrate import Migrate
|
||||||
from flask_login import LoginManager
|
from flask_login import LoginManager
|
||||||
from flask_mail import Mail
|
from flask_mail import Mail
|
||||||
|
from flask_bootstrap import Bootstrap
|
||||||
from config import Config
|
from config import Config
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
@ -15,6 +16,7 @@ migrate = Migrate(app, db)
|
||||||
login = LoginManager(app)
|
login = LoginManager(app)
|
||||||
login.login_view = 'login'
|
login.login_view = 'login'
|
||||||
mail = Mail(app)
|
mail = Mail(app)
|
||||||
|
bootstrap = Bootstrap(app)
|
||||||
|
|
||||||
if not app.debug:
|
if not app.debug:
|
||||||
if app.config['MAIL_SERVER']:
|
if app.config['MAIL_SERVER']:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block app_content %}
|
||||||
<h1>Not Found</h1>
|
<h1>Not Found</h1>
|
||||||
<p><a href="{{ url_for('index') }}">Back</a></p>
|
<p><a href="{{ url_for('index') }}">Back</a></p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block app_content %}
|
||||||
<h1>An unexpected error has occurred</h1>
|
<h1>An unexpected error has occurred</h1>
|
||||||
<p>The administrator has been notified. Sorry for the inconvenience!</p>
|
<p>The administrator has been notified. Sorry for the inconvenience!</p>
|
||||||
<p><a href="{{ url_for('index') }}">Back</a></p>
|
<p><a href="{{ url_for('index') }}">Back</a></p>
|
||||||
|
|
|
@ -1,6 +1,17 @@
|
||||||
<table>
|
<table class="table table-hover">
|
||||||
<tr valign="top">
|
<tr>
|
||||||
<td><img src="{{ post.author.avatar(36) }}"></td>
|
<td width="70px">
|
||||||
<td><a href="{{ url_for('user', username=post.author.username) }}">{{ post.author.username }}</a> says:<br>{{ post.body }}</td>
|
<a href="{{ url_for('user', username=post.author.username) }}">
|
||||||
|
<img src="{{ post.author.avatar(70) }}" />
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ url_for('user', username=post.author.username) }}">
|
||||||
|
{{ post.author.username }}
|
||||||
|
</a>
|
||||||
|
says:
|
||||||
|
<br>
|
||||||
|
{{ post.body }}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -1,34 +1,50 @@
|
||||||
<!doctype html>
|
{% extends 'bootstrap/base.html' %}
|
||||||
<html>
|
|
||||||
<head>
|
{% block title %}
|
||||||
{% if title %}
|
{% if title %}{{ title }} - Microblog{% else %}Welcome to Microblog{% endif %}
|
||||||
<title>{{ title }} - Microblog</title>
|
{% endblock %}
|
||||||
{% else %}
|
|
||||||
<title>Welcome to Microblog</title>
|
{% block navbar %}
|
||||||
{% endif %}
|
<nav class="navbar navbar-default">
|
||||||
</head>
|
<div class="container">
|
||||||
<body>
|
<div class="navbar-header">
|
||||||
<div>
|
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
|
||||||
Microblog:
|
<span class="sr-only">Toggle navigation</span>
|
||||||
<a href="{{ url_for('index') }}">Home</a>
|
<span class="icon-bar"></span>
|
||||||
<a href="{{ url_for('explore') }}">Explore</a>
|
<span class="icon-bar"></span>
|
||||||
{% if current_user.is_anonymous %}
|
<span class="icon-bar"></span>
|
||||||
<a href="{{ url_for('login') }}">Login</a>
|
</button>
|
||||||
{% else %}
|
<a class="navbar-brand" href="{{ url_for('index') }}">Microblog</a>
|
||||||
<a href="{{ url_for('user', username=current_user.username) }}">Profile</a>
|
|
||||||
<a href="{{ url_for('logout') }}">Logout</a>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
|
||||||
|
<ul class="nav navbar-nav">
|
||||||
|
<li><a href="{{ url_for('index') }}">Home</a></li>
|
||||||
|
<li><a href="{{ url_for('explore') }}">Explore</a></li>
|
||||||
|
</ul>
|
||||||
|
<ul class="nav navbar-nav navbar-right">
|
||||||
|
{% if current_user.is_anonymous %}
|
||||||
|
<li><a href="{{ url_for('login') }}">Login</a></li>
|
||||||
|
{% else %}
|
||||||
|
<li><a href="{{ url_for('user', username=current_user.username) }}">Profile</a></li>
|
||||||
|
<li><a href="{{ url_for('logout') }}">Logout</a></li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
{% with messages = get_flashed_messages() %}
|
{% with messages = get_flashed_messages() %}
|
||||||
{% if messages %}
|
{% if messages %}
|
||||||
<ul>
|
|
||||||
{% for message in messages %}
|
{% for message in messages %}
|
||||||
<li>{{ message }}</li>
|
<div class="alert alert-info" role="alert">{{ message }}</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% block content %}{% endblock %}
|
|
||||||
</body>
|
{# application content needs to be provided in the app_content block #}
|
||||||
</html>
|
{% block app_content %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -1,23 +1,11 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
{% import 'bootstrap/wtf.html' as wtf %}
|
||||||
|
|
||||||
{% block content %}
|
{% block app_content %}
|
||||||
<h1>Edit Profile</h1>
|
<h1>Edit Profile</h1>
|
||||||
<form action="" method="post">
|
<div class="row">
|
||||||
{{ form.hidden_tag() }}
|
<div class="col-md-4">
|
||||||
<p>
|
{{ wtf.quick_form(form) }}
|
||||||
{{ form.username.label }}<br>
|
</div>
|
||||||
{{ form.username(size=32) }}<br>
|
</div>
|
||||||
{% for error in form.username.errors %}
|
|
||||||
<span style="color: red;">[{{ error }}]</span>
|
|
||||||
{% endfor %}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{{ form.about_me.label }}<br>
|
|
||||||
{{ form.about_me(cols=50, rows=4) }}<br>
|
|
||||||
{% for error in form.about_me.errors %}
|
|
||||||
<span style="color: red;">[{{ error }}]</span>
|
|
||||||
{% endfor %}
|
|
||||||
</p>
|
|
||||||
<p>{{ form.submit() }}</p>
|
|
||||||
</form>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
{% import 'bootstrap/wtf.html' as wtf %}
|
||||||
|
|
||||||
{% block content %}
|
{% block app_content %}
|
||||||
<h1>Hi, {{ current_user.username }}!</h1>
|
<h1>Hi, {{ current_user.username }}!</h1>
|
||||||
{% if form %}
|
{% if form %}
|
||||||
<form action="" method="post">
|
{{ wtf.quick_form(form) }}
|
||||||
{{ form.hidden_tag() }}
|
<br>
|
||||||
<p>
|
|
||||||
{{ form.post.label }}<br>
|
|
||||||
{{ form.post(cols=32, rows=4) }}<br>
|
|
||||||
{% for error in form.post.errors %}
|
|
||||||
<span style="color: red;">[{{ error }}]</span>
|
|
||||||
{% endfor %}
|
|
||||||
</p>
|
|
||||||
<p>{{ form.submit() }}</p>
|
|
||||||
</form>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for post in posts %}
|
{% for post in posts %}
|
||||||
{% include '_post.html' %}
|
{% include '_post.html' %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if prev_url %}
|
<nav aria-label="...">
|
||||||
<a href="{{ prev_url }}">Newer posts</a>
|
<ul class="pager">
|
||||||
{% endif %}
|
<li class="previous{% if not prev_url %} disabled{% endif %}">
|
||||||
{% if next_url %}
|
<a href="{{ prev_url or '#' }}">
|
||||||
<a href="{{ next_url }}">Older posts</a>
|
<span aria-hidden="true">←</span> Newer posts
|
||||||
{% endif %}
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="next{% if not next_url %} disabled{% endif %}">
|
||||||
|
<a href="{{ next_url or '#' }}">
|
||||||
|
Older posts <span aria-hidden="true">→</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,26 +1,14 @@
|
||||||
{% extends "base.html" %}
|
{% extends 'base.html' %}
|
||||||
|
{% import 'bootstrap/wtf.html' as wtf %}
|
||||||
|
|
||||||
{% block content %}
|
{% block app_content %}
|
||||||
<h1>Sign In</h1>
|
<h1>Sign In</h1>
|
||||||
<form action="" method="post" novalidate>
|
<div class="row">
|
||||||
{{ form.hidden_tag() }}
|
<div class="col-md-4">
|
||||||
<p>
|
{{ wtf.quick_form(form) }}
|
||||||
{{ form.username.label }}<br>
|
</div>
|
||||||
{{ form.username(size=32) }}<br>
|
</div>
|
||||||
{% for error in form.username.errors %}
|
<br>
|
||||||
<span style="color: red;">[{{ error }}]</span>
|
|
||||||
{% endfor %}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{{ form.password.label }}<br>
|
|
||||||
{{ form.password(size=32) }}<br>
|
|
||||||
{% for error in form.password.errors %}
|
|
||||||
<span style="color: red;">[{{ error }}]</span>
|
|
||||||
{% endfor %}
|
|
||||||
</p>
|
|
||||||
<p>{{ form.remember_me() }} {{ form.remember_me.label }}</p>
|
|
||||||
<p>{{ form.submit() }}</p>
|
|
||||||
</form>
|
|
||||||
<p>New User? <a href="{{ url_for('register') }}">Click to Register!</a></p>
|
<p>New User? <a href="{{ url_for('register') }}">Click to Register!</a></p>
|
||||||
<p>
|
<p>
|
||||||
Forgot Your Password?
|
Forgot Your Password?
|
||||||
|
|
|
@ -1,37 +1,11 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
{% import 'bootstrap/wtf.html' as wtf %}
|
||||||
|
|
||||||
{% block content %}
|
{% block app_content %}
|
||||||
<h1>Register</h1>
|
<h1>Register</h1>
|
||||||
<form action="" method="post">
|
<div class="row">
|
||||||
{{ form.hidden_tag() }}
|
<div class="col-md-4">
|
||||||
<p>
|
{{ wtf.quick_form(form) }}
|
||||||
{{ form.username.label }}<br>
|
</div>
|
||||||
{{ form.username(size=32) }}<br>
|
</div>
|
||||||
{% for error in form.username.errors %}
|
|
||||||
<span style="color: red;">[{{ error }}]</span>
|
|
||||||
{% endfor %}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{{ form.email.label }}<br>
|
|
||||||
{{ form.email(size=64) }}<br>
|
|
||||||
{% for error in form.email.errors %}
|
|
||||||
<span style="color: red;">[{{ error }}]</span>
|
|
||||||
{% endfor %}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{{ form.password.label }}<br>
|
|
||||||
{{ form.password(size=32) }}<br>
|
|
||||||
{% for error in form.password.errors %}
|
|
||||||
<span style="color: red;">[{{ error }}]</span>
|
|
||||||
{% endfor %}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{{ form.password2.label }}<br>
|
|
||||||
{{ form.password2(size=32) }}<br>
|
|
||||||
{% for error in form.password2.errors %}
|
|
||||||
<span style="color: red;">[{{ error }}]</span>
|
|
||||||
{% endfor %}
|
|
||||||
</p>
|
|
||||||
<p>{{ form.submit() }}</p>
|
|
||||||
</form>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,23 +1,11 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
{% import 'bootstrap/wtf.html' as wtf %}
|
||||||
|
|
||||||
{% block content %}
|
{% block app_content %}
|
||||||
<h1>Reset Your Password</h1>
|
<h1>Reset Your Password</h1>
|
||||||
<form action="" method="post">
|
<div class="row">
|
||||||
{{ form.hidden_tag() }}
|
<div class="col-md-4">
|
||||||
<p>
|
{{ wtf.quick_form(form) }}
|
||||||
{{ form.password.label }}<br>
|
</div>
|
||||||
{{ form.password(size=32) }}<br>
|
</div>
|
||||||
{% for error in form.password.errors %}
|
|
||||||
<span style="color: red;">[{{ error }}]</span>
|
|
||||||
{% endfor %}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{{ form.password2.label }}<br>
|
|
||||||
{{ form.password2(size=32) }}<br>
|
|
||||||
{% for error in form.password2.errors %}
|
|
||||||
<span style="color: red;">[{{ error }}]</span>
|
|
||||||
{% endfor %}
|
|
||||||
</p>
|
|
||||||
<p>{{ form.submit() }}</p>
|
|
||||||
</form>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,16 +1,11 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
{% import 'bootstrap/wtf.html' as wtf %}
|
||||||
|
|
||||||
{% block content %}
|
{% block app_content %}
|
||||||
<h1>Reset Password</h1>
|
<h1>Reset Password</h1>
|
||||||
<form action="" method="post">
|
<div class="row">
|
||||||
{{ form.hidden_tag() }}
|
<div class="col-md-4">
|
||||||
<p>
|
{{ wtf.quick_form(form) }}
|
||||||
{{ form.email.label }}<br>
|
</div>
|
||||||
{{ form.email(size=64) }}<br>
|
</div>
|
||||||
{% for error in form.email.errors %}
|
|
||||||
<span style="color: red;">[{{ error }}]</span>
|
|
||||||
{% endfor %}
|
|
||||||
</p>
|
|
||||||
<p>{{ form.submit() }}</p>
|
|
||||||
</form>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block app_content %}
|
||||||
<table>
|
<table class="table table-hover">
|
||||||
<tr valign="top">
|
<tr>
|
||||||
<td><img src="{{ user.avatar(128) }}"></td>
|
<td width="256px"><img src="{{ user.avatar(256) }}"></td>
|
||||||
<td>
|
<td>
|
||||||
<h1>User: {{ user.username }}</h1>
|
<h1>User: {{ user.username }}</h1>
|
||||||
{% if user.about_me %}<p>{{ user.about_me }}</p>{% endif %}
|
{% if user.about_me %}<p>{{ user.about_me }}</p>{% endif %}
|
||||||
|
@ -15,28 +15,35 @@
|
||||||
<p>
|
<p>
|
||||||
<form action="{{ url_for('follow', username=user.username) }}" method="post">
|
<form action="{{ url_for('follow', username=user.username) }}" method="post">
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
{{ form.submit(value='Follow') }}
|
{{ form.submit(value='Follow', class_='btn btn-default') }}
|
||||||
</form>
|
</form>
|
||||||
</p>
|
</p>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>
|
<p>
|
||||||
<form action="{{ url_for('unfollow', username=user.username) }}" method="post">
|
<form action="{{ url_for('unfollow', username=user.username) }}" method="post">
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
{{ form.submit(value='Unfollow') }}
|
{{ form.submit(value='Unfollow', class_='btn btn-default') }}
|
||||||
</form>
|
</form>
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<hr>
|
|
||||||
{% for post in posts %}
|
{% for post in posts %}
|
||||||
{% include '_post.html' %}
|
{% include '_post.html' %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if prev_url %}
|
<nav aria-label="...">
|
||||||
<a href="{{ prev_url }}">Newer posts</a>
|
<ul class="pager">
|
||||||
{% endif %}
|
<li class="previous{% if not prev_url %} disabled{% endif %}">
|
||||||
{% if next_url %}
|
<a href="{{ prev_url or '#' }}">
|
||||||
<a href="{{ next_url }}">Older posts</a>
|
<span aria-hidden="true">←</span> Newer posts
|
||||||
{% endif %}
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="next{% if not next_url %} disabled{% endif %}">
|
||||||
|
<a href="{{ next_url or '#' }}">
|
||||||
|
Older posts <span aria-hidden="true">→</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue