Add Bootstrap simple template and error handling
This commit is contained in:
@@ -2,11 +2,13 @@ from flask import Flask
|
||||
from config import Config
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_login import LoginManager
|
||||
from flask_bootstrap import Bootstrap
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)
|
||||
db = SQLAlchemy(app)
|
||||
login = LoginManager(app)
|
||||
login.login_view = "login"
|
||||
bootstrap = Bootstrap(app)
|
||||
|
||||
from app import routes, models
|
||||
from app import routes, models, errors
|
||||
|
||||
13
code/app/errors.py
Normal file
13
code/app/errors.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from flask import render_template
|
||||
from app import app, db
|
||||
|
||||
|
||||
@app.errorhandler(404)
|
||||
def not_found_error(error):
|
||||
return render_template("404.html"), 404
|
||||
|
||||
|
||||
@app.errorhandler(500)
|
||||
def internal_error(error):
|
||||
db.session.rollback()
|
||||
return render_template("500.html"), 500
|
||||
@@ -40,3 +40,9 @@ def logout():
|
||||
@login_required
|
||||
def admin():
|
||||
return render_template("admin.html", title="Admin Page")
|
||||
|
||||
|
||||
@app.route("/nuke")
|
||||
@login_required
|
||||
def nuke():
|
||||
return render_template("nuked.html", title="NUKE THE SYSTEM!")
|
||||
|
||||
6
code/app/templates/404.html
Normal file
6
code/app/templates/404.html
Normal file
@@ -0,0 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block app_content %}
|
||||
<h1>Sorry, we couldn't find that</h1>
|
||||
<p><a href="{{ url_for('index') }}">Back</a></p>
|
||||
{% endblock %}
|
||||
8
code/app/templates/500.html
Normal file
8
code/app/templates/500.html
Normal file
@@ -0,0 +1,8 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block app_content %}
|
||||
<h1>An unexpected error has occurred</h1>
|
||||
<p>The administrator has been notified!</p>
|
||||
<p>If he gets too many notifications, we might replace him with an AI</p>
|
||||
<p><a href="{{ url_for('index') }}">Back</a></p>
|
||||
{% endblock %}
|
||||
@@ -1,6 +1,7 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Hi, {{ current_user.username }}!</h1>
|
||||
<h1>Hey, {{ current_user.username }}!</h1>
|
||||
Do you want to nuke the database?
|
||||
<li><a href="{{ url_for('nuke') }}">Yes, I want to burn down the world</a></li>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,30 +1,49 @@
|
||||
<html>
|
||||
<head>
|
||||
{% if title %}
|
||||
<title>{{ title }} - IGDB</title>
|
||||
{% else %}
|
||||
<title>Welcome to IGDB</title>
|
||||
{% endif %}
|
||||
</head>
|
||||
<body>
|
||||
<div>IGDB:
|
||||
<a href="{{ url_for('index') }}">Home</a>
|
||||
{% if current_user.is_anonymous %}
|
||||
<a href="{{ url_for('login') }}">Login</a>
|
||||
{% else %}
|
||||
<a href="{{ url_for('admin') }}">Administration</a>
|
||||
<a href="{{ url_for('logout') }}">Logout</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<hr>
|
||||
{% extends 'bootstrap/base.html' %}
|
||||
|
||||
{% block title %}
|
||||
IGDB
|
||||
{% endblock %}
|
||||
|
||||
{% block navbar %}
|
||||
<nav class="navbar navbar-default">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
|
||||
<span class="sr-only">Toggle navigation</span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="{{ url_for('index') }}">Microblog</a>
|
||||
</div>
|
||||
<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>
|
||||
</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('admin') }}">Administration</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() %}
|
||||
{% if messages %}
|
||||
<ul>
|
||||
{% for message in messages %}
|
||||
<li>{{ message }}</li>
|
||||
<div class="alert alert-info" role="alert">{{ message }}</div>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% block content %}{% endblock %} </body>
|
||||
</html>
|
||||
|
||||
{# application content needs to be provided in the app_content block #}
|
||||
{% block app_content %}{% endblock %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>IGDB: International Glacier Database</h1>
|
||||
The IGDB is a database, that uses data from the <a href="https://dx.doi.org/10.5904/wgms-fog-2019-12">WGMS</a> to illustrate the consequences of climate change.
|
||||
<h1 id="igdb-internation-glacier-database">IGDB: Internation Glacier Database</h1>
|
||||
<p>The IGDB is a database, that uses data from the <a href="http://dx.doi.org/10.5904/wgms-fog-2018-11">WGMS</a> to illustrate the consequences of climate change.</p>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,24 +1,12 @@
|
||||
{% extends "base.html" %}
|
||||
{% extends 'base.html' %}
|
||||
{% import 'bootstrap/wtf.html' as wtf %}
|
||||
|
||||
{% block content %}
|
||||
{% block app_content %}
|
||||
<h1>Sign In</h1>
|
||||
<form action="" method="post" novalidate>
|
||||
{{ form.hidden_tag() }}
|
||||
<p>
|
||||
{{ form.username.label }}<br>
|
||||
{{ form.username(size=32) }}<br>
|
||||
{% for error in form.username.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.remember_me() }} {{ form.remember_me.label }}</p>
|
||||
<p>{{ form.submit() }}</p>
|
||||
</form>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
{{ wtf.quick_form(form) }}
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
{% endblock %}
|
||||
|
||||
13
code/app/templates/nuked.html
Normal file
13
code/app/templates/nuked.html
Normal file
@@ -0,0 +1,13 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1 id="youre-the-boss">You're the boss!</h1>
|
||||
<ol type="1">
|
||||
<li>Stop the web server, and then execute:</li>
|
||||
<pre class="shell"><code>mysql -u root -p</code></pre>
|
||||
<li><p>Introduce MySQL's root password</p></li>
|
||||
<li><p>Execute these statements:</p></li>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sql"><code class="sourceCode sql"><span id="cb2-1"><a href="#cb2-1"></a><span class="kw">DROP</span> <span class="kw">DATABASE</span> IGDB;</span>
|
||||
<span id="cb2-2"><a href="#cb2-2"></a><span class="kw">DROP</span> <span class="fu">USER</span> IGDB@LOCALHOST;</span></code></pre></div>
|
||||
{% endblock %}
|
||||
</ol>
|
||||
Reference in New Issue
Block a user