【发布时间】:2016-10-15 06:10:33
【问题描述】:
所以我有一个标准的Django 项目,其基本视图返回一个简单的 HTML 确认语句。我是否可以将视图本身中的所有 HTML 定义为一个非常长的字符串并使用 HttpResponse() 返回它我知道这有点 unorthodox,但这是我正在考虑的一个示例:
from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import render_to_response
def index(request):
html = """
<html>
<body>
This is my bare-bones html page.
</body>
</html>
"""
return HttpResponse(html)
我对应的JS 和stylesheets 将与视图存储在同一目录中。在此示例中,我的应用程序中的 py 。只是确保:我不是在问这是否有效,因为我已经知道答案是肯定的,我只是想知道这种方法是否有任何缺点/缺点,为什么不让更多人这样做?
【问题讨论】:
-
我投票结束这个问题,因为它属于codereview.stackexchange.com
标签: python html django http httpresponse