diff options
author | 2018-02-07 10:13:36 +0000 | |
---|---|---|
committer | 2018-02-07 10:13:36 +0000 | |
commit | 7bc5e8bee74bb0a8b879a38f69748d40558a5e0b (patch) | |
tree | 2a12cbf3363fcf2989bccdf01b655f35c52f792f /pysite | |
parent | Merge pull request #1 from discord-python/feature/gunicorn-config (diff) |
Static files; basic templates
Diffstat (limited to 'pysite')
-rw-r--r-- | pysite/base_route.py | 12 | ||||
-rw-r--r-- | pysite/route_manager.py | 7 |
2 files changed, 13 insertions, 6 deletions
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() |