2021-05-21

本文详细介绍了Django中如何隐藏JSON序列化的字段、读取和处理静态文件、引入静态文件到HTML以及模板渲染的底层原理。示例代码展示了如何使用`FileResponse`返回静态图片,以及通过`settings`配置静态文件目录。同时,文章探讨了模板标签语法,包括注释、变量输出和循环结构,并介绍了过滤器和自定义过滤器的用法。此外,还讲解了全局上下文的概念和CSRF保护的原理。
摘要由CSDN通过智能技术生成

2021.5.21

now 8:54

1、json序列化隐藏字段

2、读取静态文件

3、django引入静态文件

4、模板渲染底层原理

5、模板标签语法

6、过滤器

7、自定义过滤器

8、全局上下文

9、模板继承_CSRF原理

1、8:55--9:15   json序列化隐藏字段

2、9:20--10:14  读取静态文件

   

 class StaticView(View):
        def get(self, request, i, *args, **kwargs):
            import re
            import os
            # 获取文件名
            filename = i
    
            filedir = os.path.join(os.getcwd(),'static\\images', filename)
    
            if not os.path.exists(filedir):
                raise Http404()
            # mimetypes
            return FileResponse(open(filedir, 'rb'),content_type='image/png')


3、10:15--10:43 django引入静态文件

settings

    STATIC_URL = '/static/'
    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, 'static\images'),
        os.path.join(BASE_DIR, 'static\css'),
        os.path.join(BASE_DIR, 'static\js'),
    ]
html

    {% load static %}
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <link rel="stylesheet" href="{% static 'my.css' %}" type="text/css">
        <script type="text/javascript" src="{% static 'my.js' %}"></script>
    </head>
    <body>
        <img src="/static/1.png">
        <img src="{% static '1.png' %}">
    
        <form action="/student/" method="post">
            {% csrf_token %}
            <input type="submit" id="btn">
        </form>
    
    </body>
    </html>

4、13:40--14:24 模板渲染底层原理

   

class IndexView(View):
        def get(self, request):
            import os
            with open(os.path.join(os.getcwd(), 'templates\login.html'), 'rb') as fr:
                content = fr.read()
            t = Template(content)
            c = Context({'uname': 'lisi'})
            str = t.render(c)
            return HttpResponse(str)
    
    
    class Index1View(View):
        def get(self, requset):
            t = loader.get_template('login.html')
            str = t.render({'uname': 'wangwu'})
            return HttpResponse(str)


5、14:25--15:10 模板标签语法
    

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        {# 单行注释 #}
        {% comment %}
            多
            行
            注
            释
        {% endcomment %}
        <h3>获取views传值</h3>
            <ol>
                <li>{{ user.uname }}</li>
                <li>{{ numlist.2 }}</li>
                <li>{{ current.year }}</li>
                <li>{{ current.date }}</li>
                <li>{{ current.time }}</li>
                <li>{{ str.upper }}</li>
            </ol>
        {% for foo in numlist reversed%}
            {{ forloop.revcounter0 }}--{{ foo }}<br>
        {% endfor %}
        <br>
        <hr>
        {% for k,v in user.items %}
            {{ k }}--{{ v }}<br>
        {% endfor %}
        <br>
        <hr>
        {% for foo in list %}
    
        {% empty %}
            无记录
        {% endfor %}
    </body>
    </html>

6、15:55--·17:00    过滤器

7、20:42--20:55 自定义过滤器

8、21:00--21:55 全局上下文

9、22:00--22:30 模板继承_CSRF原理

任务完成

2021-03-26 20:54:33,596 - Model - INFO - Epoch 1 (1/200): 2021-03-26 20:57:40,380 - Model - INFO - Train Instance Accuracy: 0.571037 2021-03-26 20:58:16,623 - Model - INFO - Test Instance Accuracy: 0.718528, Class Accuracy: 0.627357 2021-03-26 20:58:16,623 - Model - INFO - Best Instance Accuracy: 0.718528, Class Accuracy: 0.627357 2021-03-26 20:58:16,623 - Model - INFO - Save model... 2021-03-26 20:58:16,623 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 2021-03-26 20:58:16,698 - Model - INFO - Epoch 2 (2/200): 2021-03-26 21:01:26,685 - Model - INFO - Train Instance Accuracy: 0.727947 2021-03-26 21:02:03,642 - Model - INFO - Test Instance Accuracy: 0.790858, Class Accuracy: 0.702316 2021-03-26 21:02:03,642 - Model - INFO - Best Instance Accuracy: 0.790858, Class Accuracy: 0.702316 2021-03-26 21:02:03,642 - Model - INFO - Save model... 2021-03-26 21:02:03,643 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 2021-03-26 21:02:03,746 - Model - INFO - Epoch 3 (3/200): 2021-03-26 21:05:15,349 - Model - INFO - Train Instance Accuracy: 0.781606 2021-03-26 21:05:51,538 - Model - INFO - Test Instance Accuracy: 0.803641, Class Accuracy: 0.738575 2021-03-26 21:05:51,538 - Model - INFO - Best Instance Accuracy: 0.803641, Class Accuracy: 0.738575 2021-03-26 21:05:51,539 - Model - INFO - Save model... 2021-03-26 21:05:51,539 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 我有类似于这样的一段txt文件,请你帮我写一段代码来可视化这些训练结果
02-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值