Click here to Skip to main content
15,885,760 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone

I want to slice a string on a flask template in python. Actually what I want to do is by using an if statement to make a link to something like "Read More" or just "..."

I tried the following in html and flask files respectively but it didn't work; any suggestions?

What I have tried:

{{ text|slice:":35" }} {% if text|length > 35 %}...{% endif %}

@app.route("/")
def index():
text= hhhhhhhhhjjjjjuuggghhjhhhhhhjjjjkkhhggdfffsashsjhdjjdk
return render_template("template.html", text=text)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900