| | 1 | Using Myghty templates in Django is easy. |
| | 2 | |
| | 3 | 1. Install Myghty - [http://www.myghty.org/ Myghty.org] |
| | 4 | |
| | 5 | 2. edit yours views like this: |
| | 6 | |
| | 7 | {{{ |
| | 8 | import myghty.interp as interp |
| | 9 | from django.http import HttpResponse |
| | 10 | |
| | 11 | interpreter = interp.Interpreter( |
| | 12 | data_dir = '/path/to/cache', # cache folder |
| | 13 | component_root = '/path/to/templates', # templates folder |
| | 14 | ) |
| | 15 | |
| | 16 | |
| | 17 | def my_view(request): |
| | 18 | response = HttpResponse() # A file-like object |
| | 19 | interpreter.execute('mytemplate.myt', out_buffer = response) |
| | 20 | return response |
| | 21 | }}} |
| | 22 | It will use selected template. |
| | 23 | |
| | 24 | You may also pass variables to the templates like this: |
| | 25 | {{{ |
| | 26 | interpreter.execute('mytemplate.myt', out_buffer = response, request_args = {'foo' : 'banana'}) |
| | 27 | }}} |
| | 28 | for a template looking like this: |
| | 29 | {{{ |
| | 30 | <%args> |
| | 31 | foo |
| | 32 | </%args> |
| | 33 | |
| | 34 | %m.write(foo) |
| | 35 | }}} |