mardi 5 mai 2015

What is the Flask version of Django's render_to_string function?

So, I'm trying to learn TDD for Flask, by translating this code to Flask. I've been trying to find how to render a template to a string for a while now. Here is what I have tried:

render_template(...)
render_template_string(...)
make_response(render_template(...)).data

and none of them seem to work. The error in each case seems to be AttributeError: 'NoneType' object has no attribute 'app' in templating.py's render_template function.

My test code is as follows:

def test_home_page_can_save_POST_request(self):
    rv = c.post('/', data = {'item_text':"A new list item"})
    self.assertIn("A new list item", rv.data)

    # or whatever will work.
    self.assertEqual(rv.data, make_response(render_template('home.html',new_item_text='A new list item')).data)

Aucun commentaire:

Enregistrer un commentaire