Using Myghty templates in Django is easy.

  1. Install Myghty -
  1. edit yours views like this:
import myghty.interp as interp
from django.http import HttpResponse

interpreter = interp.Interpreter(
        data_dir = '/path/to/cache', # cache folder
        component_root = '/path/to/templates', # templates folder

def my_view(request): 
     response = HttpResponse() # A file-like object 
     interpreter.execute('mytemplate.myt', out_buffer = response) 
     return response 

It will use selected template.

You may also pass variables to the templates like this:

interpreter.execute('mytemplate.myt', out_buffer = response, request_args = {'foo' : 'banana'}) 

for a template looking like this:


This example shows how to execute a myghty template and pass the result to django template :)

from django.shortcuts import render_to_response 
 import myghty.interp as interp 
interpreter = interp.Interpreter( 
         data_dir = './cache', # path to cache dir 
         component_root = '/path/to/myghty/templates', 
class AFile(object): 
     """I'm a file :) from""" 
     __content = '' 
     def write(self, txt): 
         self.__content += txt 
     def read(self): 
         return self.__content 
def myview(request): 
         file = AFile() 
         #execute a template 
         interpreter.execute('mytemplate.myt', out_buffer = file) 
         # show it via django template 
         return render_to_response('index.html', {'content':}) 
Last modified 16 years ago Last modified on 08/15/06 19:19:32
Back to Top