zoukankan      html  css  js  c++  java
  • day 65 django 整理

    一、media 配置

      项目下的settings:

        MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

      手动配置url:

        from django.views.static import serve
        from django.conf import settings
        url(r'^media/(?P<path>.*)', serve, {'document_root': settings.MEDIA_ROOT}),

     二、inclusion_tag

      多用于返回html代码片段

      示例:

      templatetags/my_inclusion.py

    from django import template
    
    register = template.Library()
    
    
    @register.inclusion_tag('result.html')
    def show_results(n):
        n = 1 if n < 1 else int(n)
        data = ["第{}项".format(i) for i in range(1, n+1)]
        return {"data": data}
    View Code

      

      templates/snippets/result.html

    <ul>
      {% for choice in data %}
        <li>{{ choice }}</li>
      {% endfor %}
    </ul>
    View Code

      templates/index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta http-equiv="x-ua-compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>inclusion_tag test</title>
    </head>
    <body>
    
    {% load inclusion_tag_test %}
    
    {% show_results 10 %}
    </body>
    </html>
    View Code
  • 相关阅读:
    堆排序回顾
    动画函数封装
    mouseenter 和mouseover的区别
    元素滚动 scroll 系列
    元素可视区 client 系列
    元素偏移量 offset 系列
    JS执行机制
    BOM
    常用键盘事件
    常用鼠标事件
  • 原文地址:https://www.cnblogs.com/qingqinxu/p/11228558.html
Copyright © 2011-2022 走看看