Fix template_filter decorator to support both usage styles and update docstring; update CHANGES.rst
This commit is contained in:
parent
c94824744c
commit
6ff24afee8
3 changed files with 42 additions and 23 deletions
24
tests/test_template_filters.py
Normal file
24
tests/test_template_filters.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import pytest
|
||||
from flask import Flask, render_template_string
|
||||
|
||||
def test_template_filter_without_parentheses():
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.template_filter
|
||||
def double(x):
|
||||
return x * 2
|
||||
|
||||
with app.app_context():
|
||||
output = render_template_string("{{ 2 | double }}")
|
||||
assert output == "4"
|
||||
|
||||
def test_template_filter_with_parentheses():
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.template_filter()
|
||||
def triple(x):
|
||||
return x * 3
|
||||
|
||||
with app.app_context():
|
||||
output = render_template_string("{{ 3 | triple }}")
|
||||
assert output == "9"
|
||||
Loading…
Add table
Add a link
Reference in a new issue