Manu Hack schrieb: > Hi all, > > I have successfully constructed an example following the following doc: > > http://docs.turbogears.org/1.0/GenerateFigures#preview > > Now what I want to do is to have the figure in my page with tag <img> > instead of displaying it in a separate page. > > here is an what I have derived from the doc: > > def sample_fig(self): > fig = matplotlib.figure.Figure(figsize=(9, 6)) > fig.Name = "Sinewave" > ax = fig.add_subplot(111) > ax.set_xlabel("angle") > ax.set_ylabel("amplitude") > t = arange(0.0, 2.0, 0.01) > s1 = sin(2*pi*t) > ax.plot(t, s1, color="k") > return fig > > @expose(template="mysite.templates.figure") > def testfigure(self): > outdict['fig'] = self.sample_fig() > canvas = FigureCanvasAgg(outdict['fig']) > rendered_fig = StringIO.StringIO() > canvas.print_figure(rendered_fig) > outdict['rendered_fig'] = rendered_fig.getvalue() > return outdict > > The above code would run okay, but I don't know how I can display the > the "rendered_fig" in the template figure.html. Thanks a lot!
You need to have two controller methods. One that like above creates an image, and returns the raw data (no templating, no nothing). I don't know out of my head how to do that, but I guess pylons docs will have an example. And then you create a page that contains <img src="/testfigure"/> You can *not* return a HTML-page with an image directly embedded! That's simply not supported by HTML itself. Diez --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~---

