Login

Accessing Environment Variables in Templates

Author:
LorenDavie
Posted:
July 31, 2008
Language:
HTML/template
Version:
Not specified
Score:
0 (after 0 ratings)

This snippet uses the django-environment project. Django-environment is used to provide "environment variables" to django apps.

 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>

More like this

  1. Bootstrap Accordian by Netplay4 5 years, 10 months ago
  2. Bootstrap theme for django-endless-pagination? by se210 8 years, 10 months ago
  3. Bootstrap theme for django-endless-pagination? by se210 8 years, 10 months ago
  4. Reusable form template with generic view by roldandvg 8 years, 11 months ago
  5. Pagination Django with Boostrap by guilegarcia 9 years, 1 month ago

Comments

Please login first before commenting.