csrftoken() now works with .render_template(), closes #863

This commit is contained in:
Simon Willison 2020-06-23 20:23:30 -07:00
commit 28bb1c5189
4 changed files with 19 additions and 1 deletions

View file

@ -580,6 +580,18 @@ def test_register_routes_post(app_client):
assert "post data" == response.json["this is"]
def test_register_routes_csrftoken(tmpdir):
templates = tmpdir / "templates"
templates.mkdir()
(templates / "csrftoken_form.html").write_text(
"CSRFTOKEN: {{ csrftoken() }}", "utf-8"
)
with make_app_client(template_dir=templates) as client:
response = client.get("/csrftoken-form/")
expected_token = client.ds._last_request.scope["csrftoken"]()
assert "CSRFTOKEN: {}".format(expected_token) == response.text
def test_register_routes_asgi(app_client):
response = app_client.get("/three/")
assert {"hello": "world"} == response.json