I am trying to loop a string which is save using tinymce textfield, with a counter in front.
Example question description saved in html:
<p>What is<strong> if</strong> satement?</p>
Templat开发者_开发技巧e to loop the quesiton:
<li>{{forloop.counter}} {{ question.description|safe }}</li>
The result:
1
What is **if** satement?
What I tried to achieve:
1 What is **if** satement?
It's a little hard to be sure what the problem is here, but if I read your question correctly it's just that you have the <p></p>
tags around the question in your db. So your template is generating:
<li>1 <p>What is<strong> if</strong> satement?</p></li>
-- the <p/>
is a block-level tag, which is why you're getting the "line-break". Is that what you mean?
edit:
I'm not sure why you can't just remove it in your view, before passing it to the template (question['description'] = question['description'][3:-4]
), but if you really can't, can you add an appropriate CSS selector with .. .. p {display: inline;}
?? It's a bit of a hack, but if your hands are so tied...
Why don't you use <ol>
instead of <ul>
, then each <li>
will include the number already?
精彩评论