Django templates 存放html目录

1,创建templates 文件

templates 文件在manage.py 同级目录创建

templates/1/index.html

2,添加html代码

3,配置模版文件目录路径settings.py

myshop/myshop/settings.py

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')], # 获取模版目录的路径
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

ps:引入os库

4,app1应用,添加视图函数test

from django.http import HttpResponse
from django.shortcuts import render
def index(request):
    return HttpResponse("app1 的index")

def test(request):
    return render(request, '1/index.html', {}) # 这里获取的路径文件为:templates/1/index.html

5,app1应用,添加路由地址

from django.urls import path
from . import views

urlpatterns = [
    path('index', views.index, name='index'),
    path('test', views.test, name='test'), # 添加test视图函数的路由
]

6,访问页面

相关推荐

  1. html目录

    2024-06-06 16:16:05       45 阅读
  2. 【gitlab】修改默认存放存放目录

    2024-06-06 16:16:05       197 阅读
  3. 迁移Docker镜像存放目录

    2024-06-06 16:16:05       37 阅读
  4. 迁移docker存储目录

    2024-06-06 16:16:05       32 阅读
  5. Jtti:怎么查看docker文件存放目录

    2024-06-06 16:16:05       47 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-06 16:16:05       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-06 16:16:05       106 阅读
  3. 在Django里面运行非项目文件

    2024-06-06 16:16:05       87 阅读
  4. Python语言-面向对象

    2024-06-06 16:16:05       96 阅读

热门阅读

  1. Vue 2集成Ant Design步骤

    2024-06-06 16:16:05       28 阅读
  2. 134. 加油站

    2024-06-06 16:16:05       27 阅读
  3. XML读写

    2024-06-06 16:16:05       27 阅读
  4. VScode中Markdown图片尺寸大小调整

    2024-06-06 16:16:05       32 阅读
  5. vue课后习题及答案

    2024-06-06 16:16:05       30 阅读
  6. Vue+Django上传文件

    2024-06-06 16:16:05       31 阅读
  7. 596. 超过5名学生的课

    2024-06-06 16:16:05       29 阅读
  8. 【linux kernel】一文浅析linux HID核心

    2024-06-06 16:16:05       32 阅读
  9. 服务器硬件基础知识

    2024-06-06 16:16:05       27 阅读
  10. 小程序的数据驱动和vue的双向绑定有何异同

    2024-06-06 16:16:05       32 阅读