Changes between Version 1 and Version 2 of MyghtyTemplatesInDjango


Ignore:
Timestamp:
08/15/2006 02:19:32 PM (9 years ago)
Author:
riklaunim@…
Comment:

extra example added

Legend:

Unmodified
Added
Removed
Modified
  • MyghtyTemplatesInDjango

    v1 v2  
    3434%m.write(foo)
    3535}}}
     36
     37This example shows how to execute a myghty template and pass the result to django template :)
     38{{{
     39from django.shortcuts import render_to_response
     40 import myghty.interp as interp
     41 
     42interpreter = interp.Interpreter(
     43         data_dir = './cache', # path to cache dir
     44         component_root = '/path/to/myghty/templates',
     45     )
     46 
     47class AFile(object):
     48     """I'm a file :) from http://blog.zabiello.com"""
     49     __content = ''
     50     def write(self, txt):
     51         self.__content += txt
     52     def read(self):
     53         return self.__content
     54 
     55def myview(request):
     56         file = AFile()
     57         #execute a template
     58         interpreter.execute('mytemplate.myt', out_buffer = file)
     59         # show it via django template
     60         return render_to_response('index.html', {'content': file.read()})
     61}}}
Back to Top