Python 浏览器没有';t使用“时显示换行符”\n";。Django中的join()
我在Django中的代码是: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
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“应该是什么意思。此外,最好将结果以文本形式发布,而不是图像。