【问题标题】:adding a static html page to Django project将静态 html 页面添加到 Django 项目
【发布时间】:2018-04-20 20:47:04
【问题描述】:

我是 Django 和网络编码的新手。

我正在关注 Bucky tuts:Django 初学者教程 - 28 - 创建基础模板。

我想在请求时查看模板页面 (PATH/templates/music/base.html),但我不知道该怎么做。

我搜索发现我可以在 urls 中添加这样的内容来使其工作:

path('base', 'django.views.generic.simple.direct_to_template', {'music/templates/music': 'base.html'}),

但没用。

我该怎么做?

【问题讨论】:

    标签: django templates static


    【解决方案1】:

    您是否尝试过docs 中显示的这段代码?

    from django.urls import path, url
    from django.views.generic import TemplateView
    
    # django 2.0
    urlpatterns = [
        path('about/', TemplateView.as_view(template_name="about.html")),
    ]
    
    # django 1.11 and prior
    urlpatterns = [
        url(r'^about/$', TemplateView.as_view(template_name="about.html")),
    ]
    

    【讨论】:

    • 谢谢,工作(y)我在文档中迷失了一点,并没有很好地从中提取信息:) :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-14
    • 1970-01-01
    • 2015-07-09
    • 1970-01-01
    • 2010-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多