flask之二

预热

  • 在渲染模板的时候,默认会从项目根路径下的templates目录下查找模板
  • 如果想要指定模板路径的时候,就在初始化APP的时候,这样操作即可:
app = Flask(__name__,template_folder='C:/templates') #template_folder可以指定模板位置

模板传参

  • 在使用render_template渲染模板的时候,可以传递关键字参数,以后直接在模板中使用就可以了
  • 如果参数过多的话,那么就可以将所有的参数放到一个字典中,然后再传这个参数的时候使用**将字典打散成关键字参数。

小例子:

  • my_template.py
from flask import Flask,render_template
app = Flask(__name__)
app.debug = True
@app.route('/')
def hello_world():
context = {
'username': 'wanghui',
'age':19,
'children':{
'user':'ccc',
'type':'stu',
}
}
return render_template('index.html', **context)
# return render_template('index.html',context=context)
# return render_template('index.html',username='wanghui',age=19)
if __name__ == '__main__':
app.run()
  • templates/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>my blog</title>
</head>
<body>
<h1>这是模板渲染的数据</h1>
{#<p>{{ username }}</p>#}
{#<p>{{ age }}</p>#}
{{ context.username }}
{{ context.age }}
<p>{{ username }}</p>
<p>{{ children.user }}</p>
</body>
</html>

模板中的url_for

模板中的url_for和视图函数中的url_for是类似的,也是传递视图函数的名字,也可以传递参数。使用的时候,需要在url_for两边加上一个{{ url_for('func_name'),ref='/',id='1'}}

  • templates.py
from flask import Flask,render_template,url_for
app = Flask(__name__)
app.debug = True
@app.route('/')
def hello_world():
return render_template('index.html')
@app.route('/accounts/login/<id>/')
def login(id):
return render_template('login.html')
if __name__ == '__main__':
app.run(port=8888)
  • templates/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>my blog</title>
</head>
<body>
<h1>这是从模板中渲染的</h1>
<p><a href="{{ url_for('login',ref='/',id='1') }}">登陆</a></p>
</body>
</html>
  • templates/login.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login page</title>
</head>
<body>
<h1>这是登录页面</h1>
{#{{ 用来存放变量 }}#}
{#{% 用来执行函数或者逻辑代码 %}#}
</body>
</html>

过滤器

有时候我们需要在模板中对一些变量进行处理,那么就必须要类似于python中的函数一样,可以将这个值传到函数中,然后做一些操作。在模板中过滤器相当于是一个函数,把当前的变量传入到过滤器中,然后过滤器会根据自己的功能,再返回相应的值,之后再将结果渲染到页面上。

  • 基本语法:{{ variable |过滤器的名字 }}

guo

  • abs(value):返回一个数值的绝对值。 例如:-1|abs。
  • default(value,default_value,boolean=false):如果当前变量没有值,则会使用参数中的值来代替。name|default('xiaotuo')——如果name不存在,则会使用xiaotuo来替代。boolean=False默认是在只有这个变量为undefined的时候才会使用default中的值,如果想使用python的形式判断是否为false,则可以传递boolean=true。也可以使用or来替换。
  • escape(value)或e:转义字符,会将<、>等符号转义成HTML中的符号。例如:content|escape或content|e。
  • first(value):返回一个序列的第一个元素。names|first。
  • format(value,arags,*kwargs):格式化字符串。例如以下代码:
  {{ "%s" - "%s"|format('Hello?',"Foo!") }}\
将输出:Helloo? - Foo!
  • last(value):返回一个序列的最后一个元素。示例:names|last。
  • length(value):返回一个序列或者字典的长度。示例:names|length。
  • join(value,d=u''):将一个序列用d这个参数的值拼接成字符串。
  • safe(value):如果开启了全局转义,那么safe过滤器会将变量关掉转义。示例:
content_html|safe。
int(value):将值转换为int类型。
float(value):将值转换为float类型。
lower(value):将字符串转换为小写。
upper(value):将字符串转换为小写。
replace(value,old,new): 替换将old替换为new的字符串。
truncate(value,length=255,killwords=False):截取length长度的字符串。
striptags(value):删除字符串中所有的HTML标签,如果出现多个空格,将替换成一个空格。
trim:截取字符串前面和后面的空白字符。
string(value):将变量转换成字符串。
wordcount(s):计算一个长字符串中单词的个数。
  • default过滤器详解:

如果某个变量使用方式是{{ value|default('默认值')}},如果value这个key不存在的话就使用过滤器提供的默认值;如果类似于python中判断一个值是否为False(例如:空字典,空字符串,空列表的话)那么久必须要传递另外一个参数{{ value | default('默认值',boolean=True)}};
可以使用or来替换default('默认值',boolean=True)(例如{{ siginature or '此人很懒没有留下任何说明'}})
例子:

  • defaulte_falter.py
from flask import Flask,render_template
app = Flask(__name__)
@app.route('/')
def index():
context = {
'position':-9,
'signature':'',
#'signature':'this ismy blog'
}
return render_template('index.html',**context)
if __name__ == '__main__':
app.run(debug=True)
  • templates/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MyBlog</title>
</head>
<body>
{#<p>个性签名:{{ signature|default('此人很懒没有留下任何说明!',boolean=True) }}</p>#}
<p>个性签名:{{ signature or '此人很懒没有留下任何说明!'}}</p>
</body>
</html>
  • esacape:转义过滤器
  • safe过滤器:可以关闭一公分字符串的自动转义
  • escape过滤器:对某个字符串进行转义
  • autoescape过滤器:可以对其代码框内的代码块关闭自动转义
  • first:返回序列中的第一个元素
  • last:返回序列中的最后一个元素
  • format:格式化输出
  • length:长度计算
  • int:转换成整数
  • replase:旧字符串换成新的
  • truncate:指定长度截取(结合striptags去除掉html字段之后截取纯净字符串然后按字数去做预览页填充)
  • striptags:去除标签中的html字段
  • worldcount(s):统计一个长字符串中的单词数

小例子:

  • escape.py
from flask import Flask,render_template
app = Flask(__name__)
@app.route('/')
def hello_world():
context = {
'position':-9,
'signature':'<script>alert("Hello world!")</script>',
'persons':['abc','def'],
'age':"18",
'article':'hello hello xxooo xxooo!!'
}
return render_template('index.html',**context)
if __name__ == '__main__':
app.run(debug=True,port=8080)
  • templates/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MyBlog</title>
</head>
<body>
{#{% autoescape off %}#}
{#<p>个性签名:{{ signature }}</p>#}
{#{% endautoescape %}#}
<p>{{ signature|safe }}</p>
<p>{{ persons|first }}</p>
<p>{{ persons[0] }}</p>
<p>{{ persons|last }}</p>
<p>{{ persons[-1] }}</p>
<p>{{ "我的名字是%s"|format("hello word!") }}</p>
<p>{{ "人数是 %d"|format(persons|length) }}</p>
{% if age|int == 18 %}
<p>年龄是18岁</p>
{% else %}
<p>年龄不是18岁</p>
{% endif %}
<p>{{ article|replace('hello','sssssz') }}</p>
<p>{{ article|truncate(length=5) }}</p>
<p>{{ signature|striptags }}</p>
</body>
</html>

自定义模板过滤器

  1. 在python文件中写好自己的过滤器(本质上就是一个函数)
  2. 如果要在模板中调用这个过滤器,那就需要在这个函数上加一个装饰器@app.template_filter('过滤器名称')
  3. 自动加载的话就在app下添加
app.config['TEMPLATES_AUTO_RELOAD'] = True
  • 小例子:
  • define_filter.py
from flask import Flask,render_template
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True
@app.route('/')
def hello_world():
context={
'article':'anyway hello anyway hello abccc'
}
return render_template('index.html',**context)
@app.template_filter('cut')
def cut(value):
vaule = value.replace("hello","sbsb")
return value
if __name__ == '__main__':
app.run(debug=True,port=9090)**
  • templates/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>myblog</title>
</head>
<body>
<p>{{ article|cut }}</p>
</body>
</html>

实战自定义过滤器

  • 时间处理(从现在到发帖的时间差)
  • shizhan.py
from flask import Flask,render_template
from datetime import datetime
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True
@app.route('/')
def index():
context={
'article':'aaa bbb ccc',
'create_time':datetime(2018,02,23,10,12,11)
}
return render_template('index.html',**context)
@app.template_filter('handle_time')
def handle_time(time):
'''
1.距离现在的时间多久,如果间隔在一分钟以内就表示刚刚
2.在一小时以内就显示xx分钟前
3.在24小时以内就显示xx小时前
4. 在一个月之内就显示多少天之前
5. 否则就显示具体的时间
:param time:
:return:
'''
if isinstance(time,datetime):
now = datetime.now()
timestamp = (now - time).total_seconds() #获取间隔秒数
if timestamp < 60:
return "刚刚"
elif timestamp >=60 and timestamp<= 60*60:
minutes = timestamp/60
return "%s分钟前",int(minutes)
elif timestamp >= 60*60 and timestamp <= 60*60*24:
hours = timestamp/(60*60)
return "%s小时前",int(hours)
elif timestamp >= 60*60*24 and timestamp<= 60*60*24*30:
days = timestamp/(60*60*24)
return "%s天前",int(days)
else:
return time.strftime('%Y-%m-%d %H:%M')
if __name__ == '__main__':
app.run(port=9092,debug=True)
  • templates/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MyBlog</title>
</head>
<body>
<p>发表时间:{{ create_time|handle_time }}</p>
</body>
</html>

条件判断

For循环

jinjia2中的for循环,跟python中的for循环基本是一致的,也是用for in形式;
而且可以便利所有的序列以及迭代器,但是唯一不同的是jinjia2中的for循环没有breakcontinue

  • 小例子:
  • for_ex.py
from flask import Flask,render_template
app = Flask(__name__)
@app.route('/')
def hello_world():
context = {
'users':['user01','user02','user03'],
'person':{
'username':'wanghui',
'age':21,
'country':'china',
},
'books':[
{
'name':'sk1',
'author':'saa',
'price':100,
},
{
'name': 'aaaeede1',
'author': 'se232aa',
'price': 103,
},
{
'name': 'AAAew',
'author': 'VVVeqwea',
'price': 190,
},
{
'name': 'skfdfds1',
'author': 'sdfsfsdfdaa',
'price': 30,
}
]
}
return render_template('index.html',**context)
if __name__ == '__main__':
app.run(debug=True)
  • templates/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MyBlog</title>
</head>
<body>
<ul>
{% for user in users %}
<p>{{ user }}</p>
{% endfor %}
</ul>
<table>
<thead>
<tr>
<th>用户名</th>
<th>年龄</th>
<th>国家</th>
</tr>
</thead>
<tbody>
<tr>
{% for key,value in person.items() %}
<td>{{ value }}</td>
{% endfor %}
</tr>
</tbody>
<table>
<thead>
<tr>
<th>ID</th>
<th>书名</th>
<th>作者</th>
<th>价格</th>
<th>总数</th>
</tr>
</thead>
<tbody>
{% for book in books %}
{% if loop.first %}
<tr style="background: red">
{% elif loop.last %}
<tr style="background: blue">
{% else %}
<tr>
{% endif %}
<td>{{ loop.index }}</td>
<td>{{ book.name }}</td>
<td>{{ book.author }}</td>
<td>{{ book.price }}</td>
<td>{{ loop.length }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</table>
<table border="1px">
<tbody>
{% for x in range(1,10) %}
<tr>
{% for y in range(1,x+1) if y <= x %}
<td>{{ y }}*{{ x }}={{ x*y }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>

模板中的宏跟python中的函数类似,可以传递参数,但是不能有返回值
使用宏的时候,参数可以是默认值

  • 小例子:
  • macro.py
from flask import Flask,render_template
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.config['DEBUG'] = True
@app.route('/')
def hello_world():
return render_template('index.html')
if __name__ == '__main__':
app.run(port=9999)
  • templates/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Macro</title>
</head>
<body>
{% macro input(name="",value="",type="text") %}
<input type="{{ type }}" name="{{ name }}" value="{{ value }}">
{% endmacro %}
<h1>登陆页面</h1>
<table>
<tbody>
<tr>
<td>用户名:</td>
<td>{{ input('username') }}</td>
</tr>
<tr>
<td>密码:</td>
<td>{{ input('password',type='password') }}</td>
</tr>
<tr>
<td></td>
<td>{{ input(value='提交',type='submit') }}</td>
</tr>
</tbody>
</table>
</body>
</html>

宏的导入

在真实的开发中,会将一些常用的宏单独放在一个文件中,在需要使用的时候,再从这个文件中进行导入。
import语句的用法跟python中的import类似,可以直接import...as...,也可以from...import...或者from...import...as...,假设现在有一个文件,叫做forms.html,里面有两个宏分别为input和textarea,如下:

注意事项:
a. inport宏文件 as xxx
b. from 宏文件路径 import 宏的名字 [as xxx]
c. 宏文件的路径,不要以相对路径去找,都要以templates作为绝对路径去找
d. 如果想要在导入宏的时候,就把当前末班的一些参数传递给宏所在的模板,那么就应该在导入的时候使用
with context

  • 小例子:
  • macros.py
from flask import Flask,render_template
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.config['DEBUG'] = True
@app.route('/')
def hello_world():
return render_template('index/index.html')
if __name__ == '__main__':
app.run(port=9999)
  • templates/macros/macros.html
{% macro input(name="",value="",type="text") %}
<input type="{{ type }}" name="{{ name }}" value="{{ username }}">
{% endmacro %}
  • templates/index/index.html
{#{% from "macros.html" import input as inp %}#}
{% import "macros/macros.html" as macros with context %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Macro</title>
</head>
<body>
<h1>登陆页面</h1>
<table>
<tbody>
<tr>
<td>用户名:</td>
<td>{{ macros.input('username') }}</td>
</tr>
<tr>
<td>密码:</td>
<td>{{ macros.input('password',type='password') }}</td>
</tr>
<tr>
<td></td>
<td>{{ macros.input(value='提交',type='submit') }}</td>
</tr>
</tbody>
</table>
</body>
</html>

include标签

  1. 这个标签相当于是将指定模板中的代码复制粘贴到当前的位置
  2. include标签,如果要继续使用父模板中的变量,直接用就可以了
  3. include的路径也和import一样,需要从templates为根,不要以相对路径去找。
  • 小例子:
  • include_ex.py
from flask import Flask,render_template
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD']
@app.route('/')
def hello_world():
return render_template('index.html',username='wanghui')
@app.route('/detail/')
def detail():
return render_template('course_detail.html')
if __name__ == '__main__':
app.run(debug=True)
  • templates/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MyBlog</title>
</head>
<body>
{% include "common/header.html" %}
<div class="content">中间的</div>
{% include "common/footer.html" %}
<ul>{{ username }}</ul>
</body>
</html>
  • templates/course_detail.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
{% include "common/header.html" %}
<div class="content">文章详情!</div>
{% include "common/footer.html" %}
</body>
</html>
  • templates/common/header.html
<style>
.nav ul{
overflow: hidden;
}
.nav ul li{
float: left;
margin: 0 20px;
}
</style>
<nav class="nav">
<ul>
<li>首页</li>
<li>博客详情</li>
<li>教程中心</li>
<li>关于我</li>
</ul>
</nav>
  • templates/common/footer.html
<footer>这是底部</footer>

set with语句

  • 在模板中,可以使用set来定义变量;一旦定义了这个变量。那么在后面的代码中,都可以使用这个变量。
  • with语句定义的变量,只能在with的代码块中使用。超出with代码块,则不能使用
  • with不一定要跟一个变量,也可以是一个空的with语句,以后要用的话,就在with中使用set定义的变量来使用。
<body>
{% set username='wanghui' %}
<p>用户名:{{ username }}</p>
{% with %}
{% set classroom='2018' %}
<p>班级:{{ classroom }}</p>
{% endwith %}
<p>别的班级{{ classroom }}</p>
</body>

加载静态文件

  • 加载静态文件使用的是url_for函数,第一个参数为static,第二个参数是filename='path'
  • 路径查找要以static目录作为根目录
  • 小例子:

    • static_ex.py
from flask import Flask,render_template
app = Flask(__name__)
app.config.update({
'DEBUG':True,
'TEMPLATES_AUTO_RELOAD':True,
})
@app.route('/')
def hello_world():
return render_template('index.html')
if __name__ == '__main__':
app.run()
  • static/css/index.css
body{
background: pink;
}
  • static/js/index.js
alert('hello user!')
  • static/imgs/sas.jpg
图片
  • templates/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="{{ url_for('static',filename="css/index.css") }}">
<script src="{{ url_for('static',filename="js/index.js") }}"></script>
</head>
<body>
<img src="{{ url_for('static',filename='imgs/asa.jpg') }}" alt="">
</body>
</html>

模板继承

为什么需要模板继承?

  • 可以将一些公用的代码单独抽取出来放到一个父模板中,以后子模板直接继承就给可以使用了。
  • 这样可以减少重复性的代码,并且以后代码修改起来也很方便

模板继承的语法

  • 使用extends语句来指明继承的父模板。父模板的路径也就是相对于templates文件夹下的绝对路径。例子如下{% extends 'base.html' %}

block语法

一般在父模板中只能定义一些共性公用的代码,子模板可能要根据不同的需求实现不同的代码。这时候父模板就应该提供一个接口,让子模板来实现。从而实现业务的具体功能。

  • 在父模板中
{% block body_block %}
<p>我是base下的</p>
{% endblock %}
  • 在子模板中
{% block body_block %}
<p>我是index的内容</p>
{% endblock %}

调用父模板代码block中的代码

默认情况下,字幕版实现了父模板定义的block,那么子模板中block的代码就会覆盖掉父模板中的代码,要想保留父模板中的block的话就是用{{ super() }}来实现

  • 父模板的内容:
{% block body_block %}
<p style="background: red">base.html</p>
{% endblock %}
  • 子模板中的内容:
{% extends 'base.html' %}
{% block body_block %}
{{ super() }}
<p style="background: green">我是index的内容</p>
{% endblock %}

调用另外一个block中的代码

在另外一个模板中使用其他模板中的代码,可以使用{{ self.blockname() }}即可

  • 父模板
 <title>{% block title %}
{% endblock %}</title>
<body>
{% block body_block %}
<p style="background: red">base.html</p>
{% endblock %}
</body>
  • 子模板:
{% extends 'base.html' %}
{% block title %}
MyIndex
{% endblock %}
{% block body_block %}
{{ super() }}
{{ self.title() }}
<p style="background: green">我是index的内容</p>
{% endblock %}

其他注意事项

  • 继承的代码必须放在子模板中的第一行{% extends 'base.html' %}
  • 子模板中要实现自己的代码,要放到block中,不然不生效

继承的例子:

  • inherit_ex.py
from flask import Flask,render_template
app = Flask(__name__)
app.config.update({
'DEBUG':True,
'TEMPLATES_AUTO_RELOAD':True
})
@app.route('/')
def index():
return render_template('index.html')
@app.route('/detail/')
def detail():
return render_template('course_detail.html')
if __name__ == '__main__':
app.run()
  • templates/base.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}
{% endblock %}</title>
<style>
.nav ul{
overflow: hidden;
}
.nav ul li{
float: left;
margin: 0 20px;
}
</style>
</head>
<body>
<nav class="nav">
<ul>
<li>首页</li>
<li>博客详情</li>
<li>教程中心</li>
<li>关于我</li>
</ul>
</nav>
{% block body_block %}
<p style="background: red">base.html</p>
{% endblock %}
<footer>这是底部</footer>
</body>
</html>
  • templates/index.html
{% extends 'base.html' %}
{% block title %}
MyIndex
{% endblock %}
{% block body_block %}
{{ super() }}
{{ self.title() }}
<p style="background: green">我是index的内容</p>
{% endblock %}
  • templates/course_detail.html
{% extends 'base.html' %}
{% block body_block %}
<p>this is course </p>
{% endblock %}

flask之二的更多相关文章

  1. Flask备注二(Configurations, Signals)

    Flask备注二(Configuration, Signals) Flask是一个使用python开发Web程序的框架.依赖于Werkzeug提供完整的WSGI支持,以及Jinja2提供templat ...

  2. Flask知识点二

    一  模板 1.模板的使用 Flask使用的是Jinja2模板,所以其语法和Django无差别 2.自定义模板方法 Flask中自定义模板方法的方式和Bottle相似,创建一个函数并通过参数的形式传入 ...

  3. flask基础二

    内容有:1.配置文件处理,2.路由系统,3.视图,4.请求,5.响应,6.模板渲染,7.session,8.flash,9.中间件,10特殊装饰器 一:一个简单知识点 通过路径构成的字符串1.动态导入 ...

  4. docker 部署 flask(二)编写及生成镜像。

    简介: 上一篇文章,我们简单的测试了一下服务器环境和docker基础镜像.并没有涉及我们自己编写的flask python程序. 现在,我们就要把我们自己的flask程序,放进docker镜像. 但是 ...

  5. Flask系列(二)Flask基础

    知识点回顾 1.flask依赖wsgi,实现wsgi的模块:wsgiref(django),werkzeug(flask),uwsgi(上线) 2.实例化Flask对象,里面是有参数的 app = F ...

  6. flask系列二之基础知识

    一.调试模式(debug模式) 1.设置debug模式 在app.run()中传入关键字参数debug,app.run(debug=Ture),就设置当前项目为debug模式.如下所示: # 从fla ...

  7. flask笔记(二)

    Flask中的路由 查看整个flask中的路由映射关系 app.url_map from flask import Flask app = Flask(__name__) @app.route(&qu ...

  8. 第六章 Flask数据库(二)

    Flask-SQLALchemy Flask-SQLALchemy 是一个给你的应用添加 SQLALchemy 支持的 Flask 扩展. 它需要 SQLAlchemy 0.6 或更高的版本.它致力于 ...

  9. flask 之(二) --- 视图|模版|模型

    Flask框架 打开pycharm编译器,新建一个Flask项目,选择提前建好的虚拟环境 . 项目结构: static:静态资源文件,可以直接被浏览器访问 templates:模版文件,必须在项目的p ...

随机推荐

  1. HttpModule 介绍

    引言 Http 请求处理流程 和 Http Handler 介绍 这两篇文章里,我们首先了解了Http请求在服务器端的处理流程,随后我们知道Http请求最终会由实现了IHttpHandler接口的类进 ...

  2. js变量和数据类型

  3. YOLOV3中Darknet中cfg文件说明和理解

    今天将要说明的是Darknet中的cfg文件,废话少说,直接干!(以cfg/yolov3.cfg为例,其它类似) [net]                        ★ [xxx]开始的行表示网 ...

  4. 代码执行testng的几种方式

    一.指定test class Test class FirstTest package cas.eric; import org.testng.annotations.Optional; import ...

  5. Java{0}占位符替换字符串

    Java{0}占位符替换字符串 public class Test { public static void main(String[] args) { System.out.println(Stri ...

  6. 多线程11-AutoResetEvent

        );             Console.WriteLine());             t.Start();             Console.WriteLine());    ...

  7. VSL基础

    VSL是Virtools提供的一个非常有创意的脚本语言,它以输写代码的方式(区别于Virtools现有的图形化编程界面)进行编程开发,提高了程序的可读性和工作效率. 下图的功能是:将一个3D物体拷贝出 ...

  8. 【SQL Server复制】数据库复制:修改表结构、新增表、新增存储过程 会被复制到订阅服务器?

    转自:https://www.cnblogs.com/happyday56/p/3849018.html 关键字:sql server复制 [SQL Server高可用性]数据库复制:修改表结构.新增 ...

  9. python 二维数组转一维数组

    三种方法 比如 a = [[1, 2], [3, 4], [5, 6]] 列表推导式 [i for j in a for i in j] 库函数 from itertools import chain ...

  10. js如何获取到select的option值???

    1.获得选项option的值 var obj = document.getElementByIdx_x(”testSelect”); //定位id var index = obj.selectedIn ...