我为我的网站使用django auth,它需要安装会话中间件.
Django会话中间件总是添加会话cookie,即使对于匿名用户(未经过身份验证的用户)也是如此.当他们进行身份验证时,Cookie会被另一个表示用户已登录的cookie替换.
我想禁用匿名用户cookie以进行缓存(清漆).
有没有办法禁用匿名用户cookie而不删除使用身份验证的应用程序所必需的会话中间件?
我们有2个清单
l1 = [1, 2, 3]
l2 = [a, b, c, d, e, f, g...]
Run Code Online (Sandbox Code Playgroud)
结果:
list = [1, a, 2, b, 3, c, d, e, f, g...]
Run Code Online (Sandbox Code Playgroud)
不能使用zip()因为它将结果缩短到最小list.我还需要一个list输出而不是iterable.
有没有办法在django模板中有一个随机字符串?
我希望有多个字符串随机显示如下:
{% here generate random number rnd ?%}
{% if rnd == 1 %}
{% trans "hello my name is john" %}
{% endif %}
{% if rnd == 2 %}
{% trans "hello my name is bill" %}
{% endif %}
Run Code Online (Sandbox Code Playgroud)
编辑:感谢您的回答,但我的案例需要一些更具体的内容,因为它在基本模板中(我忘了提及抱歉).因此,在抓取谷歌和一些文档之后,我依赖于上下文处理器文章做了这个工作,我发现它有点"heavey"无论如何只是为了生成一个随机数...
这是博客页面:http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/
模板标签不是技巧(或者我没有找到),因为它返回一个无法翻译的标签,因为我记得(参见blocktrans doc)
我没有找到为基本视图生成数字的方法(有没有?)如果有比上下文过程更好的方法我会很高兴有一些信息.
我正在尝试确定图像是否平方(像素化)。
我听说过使用 numpy 或 scipy 进行二维傅里叶变换,但它有点复杂。
目标是确定由于这样的不良压缩而产生的平方区域的数量(img a):

我正在尝试使用 ccxt ccxt-1.39.93、Python 3 在 Binance Futures 上平仓。
# fetch position
position = binance.fetch_balance()['info']['positions']
pos = [p for p in position if p['symbol'] == "ETHUSDT"][0]
ticker = get_binance_futures(fetch_only=True)
close_position = binance.create_order(symbol=symbol, type="TAKE_PROFIT_MARKET", side="buy", amount=pos['positionAmt'], price=ticker , params={"closePosition": True, "stopPrice": ticker})
Run Code Online (Sandbox Code Playgroud)
我想关闭当前头寸。但是得到了这个错误:
ccxt.base.errors.ExchangeError: binance {"code":-2021,"msg":"Order would immediately trigger."}
Run Code Online (Sandbox Code Playgroud)
是否有一种简单的方法可以以市场或现货价格关闭给定代码的当前头寸?
我有一堆图像,我想通过消除黑色边框来使其均匀化。通常我将Imagemagick的Trim函数与fuzz参数一起使用,但是如果图像带有一些水印,则结果不在此处。
实际上,我正在使用opencv和形态学转换进行一些测试,以尝试识别水印和图像,然后选择更大的元素,但是我对opencv真的很陌生,我很挣扎。
从左下角到右上角,水印无处不在。

我更喜欢Python代码,但欢迎使用Imagemagick等类似的应用程序。
实际上只使用opencv我得到以下结果:
import copy
import cv2
from matplotlib import pyplot as plt
IMG_IN = '/data/black_borders/island.jpg'
# keep a copy of original image
original = cv2.imread(IMG_IN)
# Read the image, convert it into grayscale, and make in binary image for threshold value of 1.
img = cv2.imread(IMG_IN,0)
# use binary threshold, all pixel that are beyond 3 are made white
_, thresh_original = cv2.threshold(img, 3, 255, cv2.THRESH_BINARY)
# Now find contours in it.
thresh = copy.copy(thresh_original)
contours, hierarchy …Run Code Online (Sandbox Code Playgroud) 从列表中获取2项2的最优雅方式是什么?
from:
my_list = ['I', 'swear', 'I', 'googled', 'first']
to:
res_list = ['I swear', 'swear I', 'I googled', 'googled first']
Run Code Online (Sandbox Code Playgroud) 我想在字符串中找到一个关键字,该关键字可以位于字符串的开头、结尾或任何位置。
我从这样的事情开始:
import re
my_keyword = "in ocean"
regex = r'[^|\,\s]?in ocean\,\s|[^|\,\s]?in ocean$'
Run Code Online (Sandbox Code Playgroud)
应该匹配:
in ocean there is big fish
in ocean
there is big fish in ocean
there is big fish in ocean but not in lakes
i like to swim in lake, in ocean too
in ocean, there is big fish
Run Code Online (Sandbox Code Playgroud)
不应该匹配:
within ocean, you can find tresure
in oceania there is sirens
tintin ocean, the tresure hunter
do not dive within ocean
Run Code Online (Sandbox Code Playgroud) 我想用一些正则表达式从时间值中提取这种数据:
1h 34mn 2s >>> [1,34,2]
1h 4mn >>> [1,4]
34mn 2s >>> [34,2]
34s >>> [34]
Run Code Online (Sandbox Code Playgroud)
我试过:
re.match(r'((.*)h)?((.*)mn)?((.*)s)?', '1h 34mn').groups()
('1h', '1', ' 34mn', ' 34', None, None)
Run Code Online (Sandbox Code Playgroud)
几乎完成但仍然不是我想要的.
编辑:
我需要在几秒钟内提取总值 1h 34mn 2s >>> 1*3600+34*60+2