Accessing Environment Variables in Templates

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# In this example we're accessing an auth profile (avatar), and a static string in a template.

# First we would need the following environment file (.env)
from environment.standard import AuthProfileGenerator
entries = {
    'avatar':AuthProfileGenerator(),
    'greeting':'Hello',
}

# views.py
from environment import ctx
from django.shortcuts import render_to_response

def hello(request):
    return render_to_response('hello.html',ctx())

# hello.html
<p>{{ env.greeting }}, {{ env.avatar }}</p>

Comments

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.