Since nobody responded, i figured i should revisit the documentation. Here are the answers to my own questions:
1. To add a variable from an external file, i simply redefined the value page_list inside the view. That causes it to be included in the local context and added to locals(). In the appenv.py file i simply renamed page_list to pages and in the view i added 'page_list = pages'. 2. If i don't want to use locals(), i found that i should simply manually create a dictionary passing all values required. >From Chapter 7, Forms: For 1. "[..] locals(), which will include all variables defined at that point in the function’s execution.[..]" For 2. "[..] locals() incurs a small bit of overhead, because when you call it, Python has to create the dictionary dynamically. If you specify the context dictionary manually, you avoid this overhead." Django has great documentation. One remaining question for people who have vast experience creating reusable django applications, is if the appenv.py file is a good approach if my goal is to write django applications with reuse in mind. Thanks in advance for your response. On Mon, May 25, 2009 at 1:52 PM, jon michaels <joniama...@gmail.com> wrote: > Hi list, > > In an attempt to follow the DRY principle and keep environment > specific variables separate from my application code, i decided to put > a number of application specific variables in a different file. > > So i have a file like this: > > --- > u...@host:~/program$ more appenv.py > ###### > # app environment specific variables > ###### > > page_list = ('index','editor','upload') > server_list = ('localhost','remotehost') > --- > This file will hold more variables, but for the sake of simplicity, i > just show two here. > > In the beginning of my views.py i did an import: > from app.appenv import page_list, server_list > > I have several views where the server_list tuple is used inside the > view definition. > That works fine. > > The page list, however, is only read by the template. > > I always pass locals() to the template and when defining server_list > inside the view definition, that works fine; the template can access > it. The following line however, doesn't work for me: > return render_to_response('static', locals(), page_list) > > My question is twofold: > > 1) How do i add page_list to locals()? > 2) What can i do if i don't want to pass locals(), but more than two > arguments to render_to_response? > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---