Django Environment

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    Django Environment - Presentation 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?

    + Loren DavieLoren Davie, 2 years ago

    custom

    722 views, 1 favs, 0 embeds more stats

    Lightning talk from django-nyc on 10/8/2008. Googl more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 722
      • 722 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 25
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories