1e0fe0b2b9ef — Eddie Barraco 4 years ago
Use a context processor instead of filter
2 files changed, 7 insertions(+), 4 deletions(-)

M cogito2/app.py
M cogito2/templates/base.html
M cogito2/app.py +6 -3
@@ 28,6 28,9 @@ def article_show(id):
 
     return render_template('show.html', article=article)
 
-@app.template_filter('env')
-def env_filter(key, default):
-    return environ.get(key, default)
+@app.context_processor
+def utility_processor():
+    def get_env(key, default=None):
+        return environ.get(key, default)
+    return dict(get_env=get_env)
+

          
M cogito2/templates/base.html +1 -1
@@ 9,7 9,7 @@ 
     <body>
         <div class="container">
             <div class="page-title">
-              <h1>The {{ 'OWNER_NAME' | env('OWNER NAME') }}'s blog</h1>
+              <h1>The {{ get_env('OWNER_NAME', 'XXX') }}'s blog</h1>
             </div>
             <div class="content">
                 <article>