Monday, August 13, 2007

Motion Detector With Reflector

begin with Django 6 - a real page II

Another feature is access to the templates, the dictionary elements, objects and arrays. Most seem obvious, but worthy of mention.

Dictionary:



In [15]: from django.template import Context, Template
In [16]: t = Template ("" "I'm osoba.nazwisko {{}}. {{Osoba.imie {{}}}}
osoba.nazwisko ....: The latest film I had {{}} osoba.liczbaZyc live "" ")
In [18]: james = {'name': 'James',' name ':' Blonde ',' liczbaZyc ': '5'}
In [19]: c = Context ({'person': james})
In [20]: t.render (c)
Out [20]: 'I'm a Blond. James Blond \\ nThe latest film I had five live '



object (of course to their own classes of objects referenced in the same way):



In [24]: from django.template import Context, Template
In [25]: import datetime
In [26]: d = datetime.date (2007, 7, 14)
In [27]: d.month
Out [27]: 7
In [28]: t = Template ('Month date.month {{}} {{year Lord date.year }}.')
In [29]: c = Context ({' date ': d})
In [30]: t.render (c)
Out [30]: 'Month of seven years Lord 2007. "
In [31]: c = Context ({'date': datetime.date (2007, 6, 14)})
In [32]: t.render (c)
Out [32]: 'Lord Month 6 years , 2007. "



array elements (upper and calling - you can call the method, but only parameterless, most spots can be used repeatedly, do not use parentheses when calling):



In [48]: from django . template import Template, Context
In [49]: t = Template ('Now with the agent's number two: {{ agenci.2.upper }}.')
In [50]: t.render (Context ({'agents': ['James', 'Bolo', 'Olo']}))
Out [50]:' Now with the agent's number two: OLO. "



As for the presentation layer, these elements are really a lot. In the event that someone was afraid that his name conflict occurs, an item search order after the period is as follows (for ab): a key in the dictionary (a ['b']), an attribute of an object (ab), calling (ab ()) , a reference to an array (a [b]). Still
word about handling exceptions in methods. Can cause that the exception was ignored (obviously not a good way of handling each exception.) The Django template happens when the exception object is to set a special variable: silent_variable_failure = True
can also protect you from calling methods (for example, one that has side effects):



def write (self ): = True
zapis.alters_data



Another important element is to preserve the templates at the time to appeal to non-existent variable. If it is not reconfigured Django is incorrect references are ignored (empty string). It is worth remembering, if only because the case-sensitive.