update,
This commit is contained in:
5
tunmnlu/task_1/Q5/flaskapp/__init__.py
Normal file
5
tunmnlu/task_1/Q5/flaskapp/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from flask import Flask
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
from flaskapp import routes
|
26
tunmnlu/task_1/Q5/flaskapp/routes.py
Normal file
26
tunmnlu/task_1/Q5/flaskapp/routes.py
Normal file
@@ -0,0 +1,26 @@
|
||||
""" routes.py - Flask route definitions
|
||||
|
||||
Flask requires routes to be defined to know what data to provide for a given
|
||||
URL. The routes provided are relative to the base hostname of the website, and
|
||||
must begin with a slash."""
|
||||
from flaskapp import app
|
||||
from flask import render_template
|
||||
from wrangling_scripts.Q5 import data_wrangling, username
|
||||
|
||||
header, table = data_wrangling()
|
||||
|
||||
# The following two lines define two routes for the Flask app, one for just
|
||||
# '/', which is the default route for a host, and one for '/index', which is
|
||||
# a common name for the main page of a site.
|
||||
#
|
||||
# Both of these routes provide the exact same data - that is, whatever is
|
||||
# produced by calling `index()` below.
|
||||
@app.route('/')
|
||||
@app.route('/index')
|
||||
def index():
|
||||
"""Renders the index.html template"""
|
||||
# Renders the template (see the index.html template file for details). The
|
||||
# additional defines at the end (table, header, username) are the variables
|
||||
# handed to Jinja while it is processing the template.
|
||||
return render_template('index.html', table=table, header=header,
|
||||
username=username())
|
46
tunmnlu/task_1/Q5/flaskapp/static/style.css
Normal file
46
tunmnlu/task_1/Q5/flaskapp/static/style.css
Normal file
@@ -0,0 +1,46 @@
|
||||
body {
|
||||
font-family: Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
table > caption {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
table > caption > h1 {
|
||||
font-size: 2em;
|
||||
font-weight: bold;
|
||||
margin: 0 0 0 0;
|
||||
}
|
||||
|
||||
thead {
|
||||
border-bottom: 1px solid black;
|
||||
background-color: #DCDCDC;
|
||||
}
|
||||
|
||||
thead th {
|
||||
font-weight: bold;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
td, th {
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
}
|
||||
|
||||
tbody > tr:first-child {
|
||||
border-top: 1.5px solid black;
|
||||
}
|
||||
|
||||
tbody tr:hover {
|
||||
background-color: #F5F5F5;
|
||||
}
|
||||
|
||||
tbody tr.star-trek {
|
||||
font-style: italic;
|
||||
color: blue;
|
||||
}
|
53
tunmnlu/task_1/Q5/flaskapp/templates/index.html
Normal file
53
tunmnlu/task_1/Q5/flaskapp/templates/index.html
Normal file
@@ -0,0 +1,53 @@
|
||||
{#- This is a Jinja template - Flask uses Jinja as its templating engine. Jinja
|
||||
will process this file looking for directives to define a template based on
|
||||
the passed-in variables. This template relies on the `table`, `header`, and
|
||||
`username` variables to be declared.
|
||||
|
||||
A Jinja directive will start with a "{%" and Jinja comments will begin with
|
||||
a "{#". Both are ended with the same symbol and the closing brace "}".
|
||||
|
||||
If a dash "-" is provided before the opening or closing symbol for a
|
||||
directive, Jinja will ignore all whitespace up to that side of the directive
|
||||
in the template. -#}
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Flask Example</title>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<table>
|
||||
<caption>
|
||||
<h1>Movies</h1>
|
||||
{#- Templates can output variables inside {{...}}, like below #}
|
||||
<small>Data wrangled by {{username}}</small>
|
||||
</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
{#- Templates can also iterate over variables, producing the contents
|
||||
of the template (between the "for" and the "endfor" directives) for
|
||||
each element in the specified collection #}
|
||||
{%- for col in header %}
|
||||
<th>{{ col }}</th>
|
||||
{%- endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{%- for row in table %}
|
||||
{#- It is also possible to add "if" statements, the contents of these
|
||||
templates (between the "if" and "endif" directives) are inserted only
|
||||
if the supplied statement evaluates to `True`.
|
||||
|
||||
The directive in the line below will only add the class "star-trek"
|
||||
if the title contains the string "Star Trek" exactly. #}
|
||||
<tr {%- if 'Star Trek' in row[1] %} class='star-trek' {%- endif %}>
|
||||
{%- for col in row %}
|
||||
<td>{{ col }}</td>
|
||||
{%- endfor %}
|
||||
</tr>
|
||||
{%- endfor -%}
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user