当前位置: 首页 > news >正文

飞天使-template模版相关知识

遇到报错django.template.exceptions.TemplateSyntaxError: ‘staticfiles’ is not a registered tag library. Must

ROOT_URLCONF = ''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',],#添加下面内容'libraries': { # Adding this section should work around the issue.'staticfiles' : 'django.templatetags.static',},},},
]
解决办法参考链接:https://www.cnblogs.com/yizhipanghu/p/15346297.html

html 模版中新增一个图片

    <div id="title"><div><img src="{% static "imgs/stu04.jpg" %}"></div><div>学生信息</div></div>
#STATICFILES_DIRS --- 全局变量定义了存储静态文件集合
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),os.path.join(BASE_DIR, 'abc'),os.path.join(BASE_DIR, 'app01', 'static')
]

在这里插入图片描述

url 跳转-A标签(链接)

        <div><div><a href="/"><img src="{% static "yk-logo-1220.png" %}"></a></div><div id="detail">综艺首页</div></div>```####  redirect 关键字处理跳转用户没有登陆直接跳转到登陆页面from django.shortcuts import render
from django.shortcuts import redirect# Create your views here.def index(request): # 首页# url记录登录名 --- ? username=aliceusername = request.GET.get("username")# 如果获取到username值,直接显示首页,获取不到;调到登录页if username:return render(request, 'index.html')else:# 跳转到登录页return redirect("/login/")

多app下的templates 环境准备

setting 里面设置
INSTALLED_APPS = ['django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','home','tv','movie',
]

多app下模块的应用

每个app 会有一个index.html ,多个app会出现重复情况
则每个app下面可以建立一个相同app名字,比如tv ,tv/index.html ,xx ,xx/index.html

在这里插入图片描述

http://www.lryc.cn/news/229218.html

相关文章:

  • 一、Hadoop3.1.3集群搭建
  • QML16、从 C++ 定义 QML 类型
  • 【中间件篇-Redis缓存数据库06】Redis主从复制/哨兵 高并发高可用
  • LeetCode(12)时间插入、删除和获取随机元素【数组/字符串】【中等】
  • 前端面试题 计算机网络
  • windows aseprite编译指南(白嫖)
  • 生活污水处理一体化处理设备有哪些
  • JSON可视化管理工具JSON Hero
  • P6入门:项目初始化7-项目详情之代码/分类码Code
  • 跨国企业如何选择安全靠谱的跨国传输文件软件?
  • Command Injection
  • LeetCode | 20. 有效的括号
  • 英语语法 - 祈使句 | 虚拟语气
  • 记录pytorch实现自定义算子并转onnx文件输出
  • ARPG----C++学习记录04 Section8 角色类,移动
  • 拆解软件定义汽车:OS突围
  • 并发线程使用介绍(二)
  • 【Proteus仿真】【51单片机】多路温度控制系统
  • 一些可以参考的文档集合15
  • k8s的service自动发现服务:实战版
  • 项目笔记记录
  • 【leetcode】1137. 第 N 个泰波那契数
  • 【解决】conda-script.py: error: argument COMMAND: invalid choice: ‘activate‘
  • Linux 性能调优之硬件资源监控
  • Windows系统隐藏窗口启动控制台程序
  • FreeSWITCH fail2ban.lua
  • Qt HTTP下载数据
  • 8. 深度学习——NLP
  • 部署 KVM 虚拟化平台
  • Juniper PPPOE双线路冗余RPM配置