【发布时间】:2013-01-02 05:29:46
【问题描述】:
我还没有弄清楚如何使用纯 HTML 代码和/或 HTML + JavaScript + CSS 呈现网站。
我试图加载一个 HTML 文件,上面写着:Hello World。
我知道我也可以用 Django 做到这一点,但稍后,我想用 CSS+JavaScript+HTML 显示我的网站。
在视图文件中我运行以下代码:
# Create your views here.
from django.http import HttpResponse
from django.template import Context, loader
def index(request):
template = loader.get_template("app/index.html")
return HttpResponse(template.render)
但网站显示的唯一内容是:
【问题讨论】:
-
在生产环境中,您需要避免使用 Django 来提供静态资源。另外,看看docs.djangoproject.com/en/1.8/howto/static-files。如果您发布的代码是您在添加动态行为之前采取的中间步骤,那是一回事 - 但如果 app/index.html 确实是一个静态 html 页面,那么我认为您应该将其作为静态资产。
标签: python html django static-html