• 飞天使-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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    html 模版中新增一个图片

        
    学生信息
    #STATICFILES_DIRS --- 全局变量定义了存储静态文件集合 STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static'), os.path.join(BASE_DIR, 'abc'), os.path.join(BASE_DIR, 'app01', 'static') ]
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    在这里插入图片描述

    url 跳转-A标签(链接)

            
    综艺首页
    ``` #### 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/")
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    多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',
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    多app下模块的应用

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

    在这里插入图片描述

  • 相关阅读:
    python 并发请求,转发
    KO之间互相调用
    复杂环境下多移动机器人路径规划研究(Matlab代码实现)
    【UE5 C++基础 06】角色控制基础
    混合编程之多线程
    NLP之多循环神经网络情感分析
    基于Python爬虫的股票成交量数据抓取分析系统
    入职钉钉接近半年,谈谈自身的新人landing体会
    JAVA面试题JVM篇(二)
    Golang 开源库分享:anko - 给 Go 加点“脚本魔法”
  • 原文地址:https://blog.csdn.net/startfefesfe/article/details/134383857