generated from app-generator/jinja-atlantis-dark
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathviews.py
42 lines (29 loc) · 887 Bytes
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- encoding: utf-8 -*-
"""
Copyright (c) 2019 - present AppSeed.us
"""
# Flask modules
from flask import render_template, request
from jinja2 import TemplateNotFound
# App modules
from app import app
# App main route + generic routing
@app.route('/', defaults={'path': 'index.html'})
@app.route('/<path>')
def index(path):
try:
# Detect the current page
segment = get_segment( request )
# Serve the file (if exists) from app/templates/FILE.html
return render_template( path, segment=segment )
except TemplateNotFound:
return render_template('page-404.html'), 404
# Helper - Extract current page name from request
def get_segment( request ):
try:
segment = request.path.split('/')[-1]
if segment == '':
segment = 'index'
return segment
except:
return None