【问题标题】:Django 1.7 Configure App Directory TemplatesDjango 1.7 配置应用目录模板
【发布时间】:2015-12-23 06:05:40
【问题描述】:

我正在尝试在我的 Django 1.7 项目中加载特定于应用程序的模板。这是我的目录结构:

ProjectX
   - manage.py
   - ProjectX
      - settings.py
      - urls.py
   - App1
      - urls.py
      - Templates
        - App1
           - something1.html
   - App2
      - urls.py
      - Templates
        - App2
           - something2.html

现在我已经在我的 ProjectX/ProjectX/settings.py 中配置了以下内容:

  TEMPLATE_PATH = os.path.join(BASE_DIR, 'templates')

  TEMPLATE_DIRS = (
     TEMPLATE_PATH,
  )

当我这样做时:

  render_to_response("app1/somthing1.html",.....)

我转到 PATH ProjectX/Templates/App1/something1.html

而我想要 ProjectX/App1/Templates/App1/something1.html 之类的东西

知道如何在不更改 render_To_response 语句的情况下实现这一点吗?

【问题讨论】:

    标签: python django django-templates


    【解决方案1】:

    您应该删除设置中的TEMPLATE_PATH 并将TEMPLATE_DIRS 更改为

    TEMPLATE_DIRS = (
       os.path.join(PROJECT_DIR, 'templates').replace('\\', '/'),
       os.path.join(BASE_DIR, 'App1/templates').replace('\\', '/'),
       os.path.join(BASE_DIR, 'App2/templates').replace('\\', '/')
    )
    

    【讨论】:

      猜你喜欢
      • 2019-05-16
      • 2015-06-21
      • 2014-05-20
      • 1970-01-01
      • 2020-07-27
      • 2021-09-09
      • 1970-01-01
      • 2010-12-01
      • 2013-06-13
      相关资源
      最近更新 更多