飞天使-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=alice
    username = 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
相关推荐
zxrhhm7 分钟前
Oracle 索引完整指南
数据库·oracle
程序猿乐锅1 小时前
【Tilas|第三篇】多表SQL语句
数据库·经验分享·笔记·学习·mysql
Navicat中国2 小时前
使用 Navicat 导入向导导入 Excel 数据时,系统提示导入成功,表中也能看到数据,但行数统计显示为 0,这是什么原因?
数据库·excel·导入
gmaajt2 小时前
Golang怎么做国际化多语言_Golang i18n教程【核心】
jvm·数据库·python
折哥的程序人生 · 物流技术专研2 小时前
从“卡死”到“秒过”:WMS销售数据跨库回填的极限优化之旅
数据库·机器学习·oracle
李可以量化2 小时前
DeepSeek 量化交易实战:用标准化提示词模板实现 AI 辅助交易决策
大数据·数据库·人工智能
maqr_1102 小时前
CSS如何利用Sass定义全局阴影方案_通过变量实现统一CSS风格
jvm·数据库·python
m0_613856292 小时前
uni-app怎么做类似于美团的商家评价星级 uni-app五星评分组件制作【实战】
jvm·数据库·python
Irene19913 小时前
大数据开发语境下,SQL 模式名,映射关系 - - 概念理解
大数据·数据库·sql
顾随3 小时前
(二)kettle--输入与输出
javascript·数据库·kettle