How to display the a line of text in li tag in Django template? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceHow can I do a line break (line continuation) in Python?Can I access constants in settings.py from templates in Django?How do I do a not equal in Django queryset filtering?Numeric for loop in Django templatesHow to debug in Django, the good way?How to read a file line-by-line into a list?How to check Django versionAngularJS with Django - Conflicting template tagsDjango ImageField overwrites existing path when emptyHow to set dynamic initial values to django modelform field

Sort list of array linked objects by keys and values

Can the Right Ascension and Argument of Perigee of a spacecraft's orbit keep varying by themselves with time?

Can a flute soloist sit?

Simulating Exploding Dice

What aspect of planet Earth must be changed to prevent the industrial revolution?

Loose spokes after only a few rides

Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?

Is this wall load bearing? Blueprints and photos attached

University's motivation for having tenure-track positions

How do spell lists change if the party levels up without taking a long rest?

Do working physicists consider Newtonian mechanics to be "falsified"?

US Healthcare consultation for visitors

How to read αἱμύλιος or when to aspirate

Deal with toxic manager when you can't quit

How to support a colleague who finds meetings extremely tiring?

"... to apply for a visa" or "... and applied for a visa"?

Do warforged have souls?

Using dividends to reduce short term capital gains?

How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time

Can we generate random numbers using irrational numbers like π and e?

Make it rain characters

Why can't devices on different VLANs, but on the same subnet, communicate?

Why doesn't a hydraulic lever violate conservation of energy?

Didn't get enough time to take a Coding Test - what to do now?



How to display the a line of text in li tag in Django template?



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceHow can I do a line break (line continuation) in Python?Can I access constants in settings.py from templates in Django?How do I do a not equal in Django queryset filtering?Numeric for loop in Django templatesHow to debug in Django, the good way?How to read a file line-by-line into a list?How to check Django versionAngularJS with Django - Conflicting template tagsDjango ImageField overwrites existing path when emptyHow to set dynamic initial values to django modelform field



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have text saved in my mysql records which looks like this:



Handmade item

Materials: wooden handcrafted handle, professional laser engraved rubber, brown
cardboard special gift box, authorial stamp passport


the text above is represent overview in my accessory model which is:



from django.db import models

class Accessory(models.Model):
img = models.ImageField(upload_to='accessories/', default='accessories/no.png')
name = models.CharField(max_length=50)
price = models.DecimalField(max_digits=5, decimal_places=2)
img_inside1 = models.ImageField(upload_to='accessories/', default='accessories/no.png', blank=True)
img_inside2 = models.ImageField(upload_to='accessories/', default='accessories/no.png', blank=True)
img_inside3 = models.ImageField(upload_to='accessories/', default='accessories/no.png', blank=True)
title = models.CharField(max_length=50)
overview = models.TextField(blank=True)
description = models.TextField()


I want to display each line in <li> tag



to appear like that:



 <ul>
<li><p>Handmade item</p></li>
<li><p>Materials: wooden handcrafted handle,
professional laser engraved rubber, brown cardboard
special gift box, authorial stamp passport</p>
</li>
</ul>


using linebreaks filter will not apply <ul> default style (showing bullets). thanks in advance!










share|improve this question
























  • Where is python Code?

    – Clifton Avil D'Souza
    Mar 8 at 12:07











  • here is the model related to accessory from django.db import models class Accessory(models.Model): overview = models.TextField(blank=True) description = models.TextField()

    – Aya
    Mar 8 at 12:26











  • please put this python code in question

    – Shoyeb Sheikh
    Mar 8 at 12:28











  • i have added my python code

    – Aya
    Mar 8 at 12:57

















0















I have text saved in my mysql records which looks like this:



Handmade item

Materials: wooden handcrafted handle, professional laser engraved rubber, brown
cardboard special gift box, authorial stamp passport


the text above is represent overview in my accessory model which is:



from django.db import models

class Accessory(models.Model):
img = models.ImageField(upload_to='accessories/', default='accessories/no.png')
name = models.CharField(max_length=50)
price = models.DecimalField(max_digits=5, decimal_places=2)
img_inside1 = models.ImageField(upload_to='accessories/', default='accessories/no.png', blank=True)
img_inside2 = models.ImageField(upload_to='accessories/', default='accessories/no.png', blank=True)
img_inside3 = models.ImageField(upload_to='accessories/', default='accessories/no.png', blank=True)
title = models.CharField(max_length=50)
overview = models.TextField(blank=True)
description = models.TextField()


I want to display each line in <li> tag



to appear like that:



 <ul>
<li><p>Handmade item</p></li>
<li><p>Materials: wooden handcrafted handle,
professional laser engraved rubber, brown cardboard
special gift box, authorial stamp passport</p>
</li>
</ul>


using linebreaks filter will not apply <ul> default style (showing bullets). thanks in advance!










share|improve this question
























  • Where is python Code?

    – Clifton Avil D'Souza
    Mar 8 at 12:07











  • here is the model related to accessory from django.db import models class Accessory(models.Model): overview = models.TextField(blank=True) description = models.TextField()

    – Aya
    Mar 8 at 12:26











  • please put this python code in question

    – Shoyeb Sheikh
    Mar 8 at 12:28











  • i have added my python code

    – Aya
    Mar 8 at 12:57













0












0








0








I have text saved in my mysql records which looks like this:



Handmade item

Materials: wooden handcrafted handle, professional laser engraved rubber, brown
cardboard special gift box, authorial stamp passport


the text above is represent overview in my accessory model which is:



from django.db import models

class Accessory(models.Model):
img = models.ImageField(upload_to='accessories/', default='accessories/no.png')
name = models.CharField(max_length=50)
price = models.DecimalField(max_digits=5, decimal_places=2)
img_inside1 = models.ImageField(upload_to='accessories/', default='accessories/no.png', blank=True)
img_inside2 = models.ImageField(upload_to='accessories/', default='accessories/no.png', blank=True)
img_inside3 = models.ImageField(upload_to='accessories/', default='accessories/no.png', blank=True)
title = models.CharField(max_length=50)
overview = models.TextField(blank=True)
description = models.TextField()


I want to display each line in <li> tag



to appear like that:



 <ul>
<li><p>Handmade item</p></li>
<li><p>Materials: wooden handcrafted handle,
professional laser engraved rubber, brown cardboard
special gift box, authorial stamp passport</p>
</li>
</ul>


using linebreaks filter will not apply <ul> default style (showing bullets). thanks in advance!










share|improve this question
















I have text saved in my mysql records which looks like this:



Handmade item

Materials: wooden handcrafted handle, professional laser engraved rubber, brown
cardboard special gift box, authorial stamp passport


the text above is represent overview in my accessory model which is:



from django.db import models

class Accessory(models.Model):
img = models.ImageField(upload_to='accessories/', default='accessories/no.png')
name = models.CharField(max_length=50)
price = models.DecimalField(max_digits=5, decimal_places=2)
img_inside1 = models.ImageField(upload_to='accessories/', default='accessories/no.png', blank=True)
img_inside2 = models.ImageField(upload_to='accessories/', default='accessories/no.png', blank=True)
img_inside3 = models.ImageField(upload_to='accessories/', default='accessories/no.png', blank=True)
title = models.CharField(max_length=50)
overview = models.TextField(blank=True)
description = models.TextField()


I want to display each line in <li> tag



to appear like that:



 <ul>
<li><p>Handmade item</p></li>
<li><p>Materials: wooden handcrafted handle,
professional laser engraved rubber, brown cardboard
special gift box, authorial stamp passport</p>
</li>
</ul>


using linebreaks filter will not apply <ul> default style (showing bullets). thanks in advance!







python django python-3.x django-templates






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 12:57







Aya

















asked Mar 8 at 12:02









AyaAya

178




178












  • Where is python Code?

    – Clifton Avil D'Souza
    Mar 8 at 12:07











  • here is the model related to accessory from django.db import models class Accessory(models.Model): overview = models.TextField(blank=True) description = models.TextField()

    – Aya
    Mar 8 at 12:26











  • please put this python code in question

    – Shoyeb Sheikh
    Mar 8 at 12:28











  • i have added my python code

    – Aya
    Mar 8 at 12:57

















  • Where is python Code?

    – Clifton Avil D'Souza
    Mar 8 at 12:07











  • here is the model related to accessory from django.db import models class Accessory(models.Model): overview = models.TextField(blank=True) description = models.TextField()

    – Aya
    Mar 8 at 12:26











  • please put this python code in question

    – Shoyeb Sheikh
    Mar 8 at 12:28











  • i have added my python code

    – Aya
    Mar 8 at 12:57
















Where is python Code?

– Clifton Avil D'Souza
Mar 8 at 12:07





Where is python Code?

– Clifton Avil D'Souza
Mar 8 at 12:07













here is the model related to accessory from django.db import models class Accessory(models.Model): overview = models.TextField(blank=True) description = models.TextField()

– Aya
Mar 8 at 12:26





here is the model related to accessory from django.db import models class Accessory(models.Model): overview = models.TextField(blank=True) description = models.TextField()

– Aya
Mar 8 at 12:26













please put this python code in question

– Shoyeb Sheikh
Mar 8 at 12:28





please put this python code in question

– Shoyeb Sheikh
Mar 8 at 12:28













i have added my python code

– Aya
Mar 8 at 12:57





i have added my python code

– Aya
Mar 8 at 12:57












1 Answer
1






active

oldest

votes


















2














Quick and dirty solution: split the string on newlines and iterate over the result.



class Accessory(models.Model):
# ...
overview = models.TextField()

def overview_lines(self):
return filter(None, (line.strip() for line in self.overview.splitlines()))


and then



 <ul>
% for line in howeryounamedyourobject.overview_lines %
<li><p> line </p></li>
% endfor %
</ul>


Better solutions:



either have a proper model for materials (whit a many to many relationship) or use markup instead of plain text in your "overview" field.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55062855%2fhow-to-display-the-a-line-of-text-in-li-tag-in-django-template%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Quick and dirty solution: split the string on newlines and iterate over the result.



    class Accessory(models.Model):
    # ...
    overview = models.TextField()

    def overview_lines(self):
    return filter(None, (line.strip() for line in self.overview.splitlines()))


    and then



     <ul>
    % for line in howeryounamedyourobject.overview_lines %
    <li><p> line </p></li>
    % endfor %
    </ul>


    Better solutions:



    either have a proper model for materials (whit a many to many relationship) or use markup instead of plain text in your "overview" field.






    share|improve this answer



























      2














      Quick and dirty solution: split the string on newlines and iterate over the result.



      class Accessory(models.Model):
      # ...
      overview = models.TextField()

      def overview_lines(self):
      return filter(None, (line.strip() for line in self.overview.splitlines()))


      and then



       <ul>
      % for line in howeryounamedyourobject.overview_lines %
      <li><p> line </p></li>
      % endfor %
      </ul>


      Better solutions:



      either have a proper model for materials (whit a many to many relationship) or use markup instead of plain text in your "overview" field.






      share|improve this answer

























        2












        2








        2







        Quick and dirty solution: split the string on newlines and iterate over the result.



        class Accessory(models.Model):
        # ...
        overview = models.TextField()

        def overview_lines(self):
        return filter(None, (line.strip() for line in self.overview.splitlines()))


        and then



         <ul>
        % for line in howeryounamedyourobject.overview_lines %
        <li><p> line </p></li>
        % endfor %
        </ul>


        Better solutions:



        either have a proper model for materials (whit a many to many relationship) or use markup instead of plain text in your "overview" field.






        share|improve this answer













        Quick and dirty solution: split the string on newlines and iterate over the result.



        class Accessory(models.Model):
        # ...
        overview = models.TextField()

        def overview_lines(self):
        return filter(None, (line.strip() for line in self.overview.splitlines()))


        and then



         <ul>
        % for line in howeryounamedyourobject.overview_lines %
        <li><p> line </p></li>
        % endfor %
        </ul>


        Better solutions:



        either have a proper model for materials (whit a many to many relationship) or use markup instead of plain text in your "overview" field.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 13:14









        bruno desthuilliersbruno desthuilliers

        51.9k54465




        51.9k54465





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55062855%2fhow-to-display-the-a-line-of-text-in-li-tag-in-django-template%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            1928 у кіно

            Захаров Федір Захарович

            Ель Греко