Home > Software engineering >  How to print list data in next line in Django
How to print list data in next line in Django

Time:11-04

Here i am getting some data into list through for loop and this should be printed in next line

Let us consider my views.py as

def items_log(request, pk):
    logg = []
    client = request.user.client
    items_log = JobItemsLogs.objects.filter(client=client,item_id=pk).order_by('-id')[:5]
    for x in items_log:
       log_text = 'Type of entry: {0} - date: {1}; Created by: {2}'.format(
                x.type_of_entry,x.created_at.date(),x.created_by)
       logg.append(log_text)
    ...
    ...
    ...

Now let us consider by index.html as

<div class="span4">
            <div class="well">
                <ul class="nav nav-list">
                    <li class="nav-header" >Log entries</li>

                       {% for i in logg %}
                       {{i}}
                       {% endfor %}

                </ul>
            </div>
        </div>

Here how its getting displayed is

actual image

how i wanted to display is

Type of entry: Plumbing - date: 2021-11-02; Created by: A Krishna*
Type of entry: Plumbing - date: 2021-11-02; Created by: A Krishna*
Type of entry: None - date: 2021-07-28; Created by: A Krishna*
Type of entry: None - date: 2021-07-28; Created by: A Krishna* 
Type of entry: None - date: 2021-07-28; Created by: A Krishna*

Each of these list data should be seen in new lines

CodePudding user response:

Just put {{i}} inside a p tag! :D

<p>{{i}}</p>

Or you can add <br>:

{{i}}<br>

CodePudding user response:

Add a break line character after the line -

log_text = 'Type of entry: {0} - date: {1}; Created by: {2}<br>'.format(
                x.type_of_entry,x.created_at.date(),x.created_by)
  • Related