Mohammad Baharloo
Mohammad Baharloo

Reputation: 21

Django new line in output

I try to print the model object in a new line but my code doesn't work. Here is my code and I want to know how can I fix this problem?

def list_create_tasks(request):
    if request.method == 'GET':
        all_tasks=Task.objects.all()
        return HttpResponse('\n'.join(map(str, all_tasks)))

Upvotes: 1

Views: 192

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476574

HTML does not care about a new line. In order to write on a new line, you use the <br> tag [w3schools]:

def list_create_tasks(request):
    if request.method == 'GET':
        all_tasks=Task.objects.all()
        return HttpResponse('<br>'.join(map(str, all_tasks)))

Upvotes: 3

Related Questions