I have the following Html tag.
<p align="center" id="question">FormatHere</p>
The world "FormatHere" is replace from a string that came from my back end. I saw that By formatting the string in the back end then the format is not mantained in the front end.
Someone know how I can format a string coming from the backend that will replace the world FormatHere? With specific format I meant that for example I can go head when-ever I want
CodePudding user response:
first you need to return your string from backend as same name you use in frontend.
example:
return template("index.html", context={"string": "FormatHere"})
then:
<p align="center" id="question">{{string}}</p>
CodePudding user response:
You can take values from your Django .render()
or python .template()
like so:
<p align="center" id="question">{{ object.field }}</p>
It depends on the object you are passing, of course. You can execute basic python by using {{ }}
inside your HTML. Infact, if you have an array of JSONs, you can do a foreach
and print multiple <td>
inside a table.