Permalink
Browse files

Add base template and error template

  • Loading branch information...
greyli committed Dec 30, 2018
1 parent 7f167d2 commit cfc08fa28ee477ff704713da48b1531817eab934
Showing with 111 additions and 33 deletions.
  1. +12 −2 app.py
  2. +44 −6 static/style.css
  3. +12 −0 templates/404.html
  4. +28 −0 templates/base.html
  5. +15 −25 templates/index.html
14 app.py
@@ -71,8 +71,18 @@ class Movie(db.Model):
year = db.Column(db.String(4))


@app.context_processor
def inject_user():
user = User.query.first()
return dict(user=user)


@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404


@app.route('/')
def index():
user = User.query.first()
movies = Movie.query.all()
return render_template('index.html', user=user, movies=movies)
return render_template('index.html', movies=movies)
@@ -5,15 +5,32 @@ body {
font-family: Helvetica, Arial, sans-serif;
}

footer {
color: #888;
margin-top: 15px;
.avatar {
width: 40px;
}

nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}

nav li {
float: left;
}

nav li a {
display: block;
color: white;
text-align: center;
padding: 10px;
padding: 8px 12px;
text-decoration: none;
}

.avatar {
width: 40px;
nav li a:hover {
background-color: #111;
}

.movie-list {
@@ -36,8 +53,29 @@ footer {
background-color: #f8f9fa;
}

.float-right {
float: right;
}

.imdb {
font-size: 12px;
font-weight: bold;
color: black;
text-decoration: none;
background: #F5C518;
border-radius: 5px;
padding: 3px 5px;
}

.totoro {
display: block;
margin: 0 auto;
height: 100px;
}

footer {
color: #888;
margin-top: 15px;
text-align: center;
padding: 10px;
}
@@ -0,0 +1,12 @@
{% extends 'base.html' %}

{% block content %}
<ul class="movie-list">
<li>
Page Not Found - 404
<span class="float-right">
<a href="{{ url_for('index') }}">Go Back</a>
</span>
</li>
</ul>
{% endblock %}
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
{% block head %}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ user.name }}'s Watchlist</title>
<link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" type="text/css">
{% endblock %}
</head>
<body>

<h2>
<img alt="Avatar" class="avatar" src="{{ url_for('static', filename='images/avatar.png') }}">
{{ user.name }}'s Watchlist
</h2>
<nav>
<ul>
<li><a href="{{ url_for('index') }}">Home</a></li>
</ul>
</nav>
{% block content %}{% endblock %}
<footer>
<small>&copy; 2018 <a href="http://helloflask.com/tutorial">HelloFlask</a></small>
</footer>
</body>
</html>
@@ -1,25 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{ user.name }}'s Watchlist</title>
<link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" type="text/css">
</head>
<body>
<h2>
<img alt="Avatar" class="avatar" src="{{ url_for('static', filename='images/avatar.png') }}">
{{ user.name }}'s Watchlist
</h2>
<p>{{ movies|length }} Titles</p>
<ul class="movie-list">
{% for movie in movies %}
<li>{{ movie.title }} - {{ movie.year }}</li>
{% endfor %}
</ul>
<img alt="Walking Totoro" class="totoro" src="{{ url_for('static', filename='images/totoro.gif') }}">
<footer>
<small>&copy; 2018 <a href="http://helloflask.com/tutorial">HelloFlask</a></small>
</footer>
</body>
</html>
{% extends 'base.html' %}

{% block content %}
<p>{{ movies|length }} Titles</p>
<ul class="movie-list">
{% for movie in movies %}
<li>{{ movie.title }} - {{ movie.year }}
<span class="float-right">
<a class="imdb" href="https://www.imdb.com/find?q={{ movie.title }}" target="_blank" title="Find this movie on IMDb">IMDb</a>
</span>
</li>
{% endfor %}
</ul>
<img alt="Walking Totoro" class="totoro" src="{{ url_for('static', filename='images/totoro.gif') }}" title="to~to~ro~">
{% endblock %}

0 comments on commit cfc08fa

Please sign in to comment.