From 7bc5e8bee74bb0a8b879a38f69748d40558a5e0b Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 7 Feb 2018 10:13:36 +0000 Subject: Static files; basic templates --- pysite/base_route.py | 12 +++++++----- pysite/route_manager.py | 7 ++++++- static/favicon.ico | Bin 0 -> 28957 bytes static/logos/logo_discord.png | Bin 0 -> 63590 bytes templates/base.html | 17 +++++++++++++++++ templates/index.html | 19 +++++++++---------- templates/navigation.html | 18 ++++++++++++++++++ 7 files changed, 57 insertions(+), 16 deletions(-) create mode 100644 static/favicon.ico create mode 100644 static/logos/logo_discord.png create mode 100644 templates/base.html create mode 100644 templates/navigation.html diff --git a/pysite/base_route.py b/pysite/base_route.py index 16bf0984..f983c1a2 100644 --- a/pysite/base_route.py +++ b/pysite/base_route.py @@ -6,14 +6,17 @@ __author__ = "Gareth Coles" class BaseView(MethodView): + name = None # type: str + def render(self, *template_names, **context): - # thin wrapper here in case it needs to be modified later + context["current_page"] = self.name + context["view"] = self + return render_template(template_names, **context) class RouteView(BaseView): - path = None #: str - name = None #: str + path = None # type: str @classmethod def setup(cls: "RouteView", app: Flask): @@ -24,8 +27,7 @@ class RouteView(BaseView): class ErrorView(BaseView): - name = None #: str - error_code = None #: int + error_code = None # type: int @classmethod def setup(cls: "ErrorView", app: Flask): diff --git a/pysite/route_manager.py b/pysite/route_manager.py index e9e701e0..f61c4f65 100644 --- a/pysite/route_manager.py +++ b/pysite/route_manager.py @@ -16,10 +16,15 @@ DB_PORT = os.environ.get("RETHINKDB_PORT") DB_DATABASE = os.environ.get("RETHINKDB_DATABASE") DB_TABLE = os.environ.get("RETHINKDB_TABLE") +TEMPLATES_PATH = "../templates" +STATIC_PATH = "../static" + class RouteManager: def __init__(self): - self.app = Flask(__name__, template_folder="../templates") + self.app = Flask( + __name__, template_folder=TEMPLATES_PATH, static_folder=STATIC_PATH, static_url_path="/static" + ) self.app.secret_key = os.environ.get("WEBPAGE_SECRET_KEY") self.load_views() diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 00000000..046480bf Binary files /dev/null and b/static/favicon.ico differ diff --git a/static/logos/logo_discord.png b/static/logos/logo_discord.png new file mode 100644 index 00000000..2bf74ffd Binary files /dev/null and b/static/logos/logo_discord.png differ diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 00000000..9e00af20 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,17 @@ + + + + {% block head %} + Python | {% block title %}{% endblock %} + + + + + + {% endblock %} + + +{% include "navigation.html" %} +{% block content %}{% endblock %} + + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 07bd4541..418347d2 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,10 +1,9 @@ - - - - - Python | Home - - -

Coming soon:tm:

- - \ No newline at end of file +{% extends "base.html" %} +{% block title %}Home{% endblock %} +{% block content %} +
+

+ Coming soon :tm: +

+
+{% endblock %} \ No newline at end of file diff --git a/templates/navigation.html b/templates/navigation.html new file mode 100644 index 00000000..d1f1f363 --- /dev/null +++ b/templates/navigation.html @@ -0,0 +1,18 @@ +
+ +
\ No newline at end of file -- cgit v1.2.3