Archive

Posts Tagged ‘render’

[flask] show render time on a page

August 22, 2015 Leave a comment

Problem
For debugging purposes, I wanted to see the rendering time of each page.

Solution
I found a solution here. Here are the links:

Note that Flask-DebugToolbar is very useful but it really slowed down my application. I even switched it off and I only use it when I want to debug something. When the issue is solved I switch it off again.

[django] create a formatted string with the Django template system

August 4, 2014 Leave a comment

Problem
In an application I wanted to send formatted HTML emails. For producing the body of the email, I wanted to use the Django template system. The task is very similar to creating a view. The difference is that I don’t want to send back the HTML to the client in the browser but I want to store it in a string.

Solution
The solution is very simple:

from django.template.loader import render_to_string

def email():
    context = {'some_key': 'some_value'}
    html = render_to_string('APP_NAME/email.html', context)
    send_email(html)

This tip is from here.