homepage用到的方法

使用 {% for ... in ...%}  加 {% endfor %} 实现循环结构

举例:  {% for post in posts %}

    <p style = "font -family: 微软雅黑;font-size: 16pt;letter-spacing:1pt;"><\p>

   {% endfor %}

使用双大括号显示变量, 举例:  {{ post }}

使用正则表达式语句: url = (r'^post/(\w+)$',showpost); 语句来实现用户输入的url与views.py中的函数对应

使用from django.template.loader import get_template中的get_template()函数将模板导入views.py

使用render函数将变量导入模板文件

from datetime import datetime 中的datatime.now()获取当前时间
def homepage(request):    //代码示例
template = get_template('index.html')
posts = Post.objects.all()
now = datetime.now()
html = template.render(locals())
return HttpResponse(html)
												

template_homepage的更多相关文章

随机推荐

  1. isEmpty 判空函数 内部分别判断是 null 空数组 等

    import { oneOf, isEmpty } from '@/libs/tools' export const isEmpty = (value) => { if (value == nu ...

  2. 快速排序--15--快排--LeetCode排序数组

    排序数组 给定一个整数数组 nums,将该数组升序排列. 示例 1: 输入:[5,2,3,1] 输出:[1,2,3,5] 示例 2: 输入:[5,1,1,2,0,0] 输出:[0,0,1,1,2,5] ...

  3. webService-axis开发jar包

    开发最小jar包集: activation-1.1.jar axiom-api-1.2.13.jar axiom-dom-1.2.13.jar axiom-impl-1.2.13.jar axis2- ...

  4. Python-String字符串操作

    name='xioer-pipo' print(name.capitalize()) #第一个字符大写 print(name.expandtabs()) print(name.count('o')) ...

  5. Oracle 中文日期转换

    中文日期转换 select to_char(to_date('07-5月-17'),'yyyy-MM-dd HH24:mi:ss') from dual

  6. asp.net core系列 76 Apollo 快速安装模式下填坑和ASP.NetCore结合使用

    前言:由于公司占时没有运维,出于微服务的需要,Apollo只能先装在windows 阿里云上跑起来,由于环境及网络等问题,在安装过程中遇到很多坑,算是一个个坑填完后,最终实现. 一. java jdk ...

  7. 死磕Lambda表达式(五):Comparator复合

    给岁月以文明,而不是给文明以岁月.--<三体> 在上一篇文章(传送门)中介绍了JDK为我们提供的常用函数式接口,JDK不仅提供的这些函数式接口,其中一些接口还为我们提供了实用的默认方法,这 ...

  8. sql-lib闯关61-65

    第六十一关 和六十关基本一样,就是变成了单引号和双括号,这好像是第一次遇见双括号 爆数据库名   ?id=1'))and extractvalue(1, concat(0x5c, (select da ...

  9. 曹工说Spring Boot源码(27)-- Spring的component-scan,光是include-filter属性的各种配置方式,就够玩半天了.md

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...

  10. MySQL5.7 import表结构报错超出表空间界限

    事后测试了一下,一下方法就是垃圾,看看可以,别跟着学!!! 数据库重启后,问题依然暴露出来了,参数什么的都是扯,擦 记录一个困扰我好几天的问题.先贴上报错: space name jxtms/Cost ...