Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 浏览器没有';t使用“时显示换行符”\n";。Django中的join()_Python_Django - Fatal编程技术网

Python 浏览器没有';t使用“时显示换行符”\n";。Django中的join()

Python 浏览器没有';t使用“时显示换行符”\n";。Django中的join(),python,django,Python,Django,我在Django中的代码是: from django.shortcuts import render from django.http import HttpResponse from .models import Post # Create your views here. def index(request): list_posts = Post.objects.order_by('-publish')[:5] output = ',\n'.join([p.slug fo

我在Django中的代码是:

from django.shortcuts import render
from django.http import HttpResponse
from .models import Post

# Create your views here.

def index(request):
    list_posts = Post.objects.order_by('-publish')[:5]
    output = ',\n'.join([p.slug for p in list_posts])
    return HttpResponse(output)
视图运行时没有错误,但我在浏览器中看不到换行符


如果查看浏览器中的页面源,它将包含
\n
,但浏览器将这些显示为常规空格

如果希望浏览器在新行上显示每个slug,可以使用

标记

output = '<br>'.join([p.slug for p in list_posts])
output='
'.join([list_posts中p的p.slug])
请编辑您的问题,并提供更多信息,说明您试图实现的目标、您采取的步骤,特别是“运行是正确的,但不要运行”、\n“应该是什么意思。此外,最好将结果以文本形式发布,而不是图像。