Django Environment

  • 966 views
Uploaded on

Lightning talk from django-nyc on 10/8/2008. Google project is http://code.google.com/p/django-environment

Lightning talk from django-nyc on 10/8/2008. Google project is http://code.google.com/p/django-environment

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
966
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
43
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. django-environment environment variables for django
  • 2. use case
  • 3. repeated access of data I wanted to be able to access a consistent per-user data set. UNIX-like variables such as $USER, $HOME or any other arbitrary $VARIABLE. I wanted to access them in views and in templates.
  • 4. usage in application
  • 5. in views from environment import env def hello(request): print ‘Hello accessed by’, env.avatar return render_to_response(‘hello.html’,{})
  • 6. in templates # views.py from environment import env def hello(request): return render_to_response(‘hello.html’,{‘env’:env}) # hello.html <p>Hello {{ env.avatar }}</p>
  • 7. shortcut # views.py from environment import ctx def hello(request): return render_to_response(‘hello.html’,ctx()) # hello.html <p>Hello {{ env.avatar }}</p>
  • 8. local variables # views.py from environment import lctx def hello(request): message = ‘Howdy’ return render_to_response(‘hello.html’,lctx()) # hello.html <p>{{ message }}, {{ env.avatar }}</p> # output Howdy, Loren
  • 9. setup
  • 10. installation • add ‘environment’ to INSTALLED_APPS • add ‘environment.EnvironmentMiddleware’ to MIDDLEWARE_CLASSES. • add ‘ENVPATH’ to settings.py. Should be path to directory where your .env file will live.
  • 11. environment file # myapp.env from environment.standard import RequestParameterGenerator, AuthProfileGenerator entries = ( ‘params’:RequestParameterGenerator(), ‘avatar’:AuthProfileGenerator(), ‘foo’:’bar’, )
  • 12. generators • String • RequestAttribute • StringDict • AuthProfile • URI • RequestParameter • Function • ConditionalAttribute • Cookie
  • 13. Thanks. Questions?