用参数重定向到Django中的另一页
return HttpResponseRedirect(reverse(viewname='the view to which it should redirect', args=(parameters to be passed)))
首先,请勿命名任何变量元组
这是一个内置功能,当您命名变量 tuple
时,您会错过该 method> method
def changer(data):
if type(data) == str:
return data.replace("-", " ")
elif type(data) == list:
return [changer(x) for x in data]
elif type(data) == tuple:
return tuple(changer(x) for x in data)
tpl = [('Hi', 'Hello-World', 'Earth'), ('Hello-World', 'Hi')]
changer(tpl)
输出:
[('Hi', 'Hello World', 'Earth'), ('Hello World', 'Hi')]
您只需要使用 max
来获取组中的最大日期, sum
获得总计:
select type, sum(value_1), sum(value_2), max(standby_date)
from t
where type = 'a'
group by type
我建议使用 pgfplots
,然后您对颜色尺度的控制最多:
\documentclass[tikz, margin=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis equal=true,
hide axis,
domain=0:180,
domain y=0:1,
view={0}{90},
shader=interp,
colormap={redblue}{
color=(red) color=(blue)
},
data cs=polar,
]
\addplot3 [surf] {x};
\end{axis}
\end{tikzpicture}
\end{document}
警告:将实现放入标题文件中是不是,请参见本答案末尾的替代解决方案。
无论如何,您的代码失败的原因是,在实例化模板时,编译器会使用给定的模板参数创建新类。例如:
template<typename T>
struct Foo
{
T bar;
void doSomething(T param) {/* do stuff using T */}
};
// somewhere in a .cpp
Foo<int> f;
阅读此行时,编译器将创建一个新类(我们称其为 fooint
),这等同于以下内容:
struct FooInt
{
int bar;
void doSomething(int param) {/* do stuff using int */}
};
因此,编译器需要访问方法的实现。 ,用模板参数实例化(在这种情况下 int
)。如果这些实现不在标题中,则将无法访问它们,因此编译器将无法实例化模板。
一个常见的解决方案是在标题文件中写入模板声明,然后在实现文件中实现类(例如.tpp),然后在标题末尾包含此实现文件。
foo.h
template <typename T>
struct Foo
{
void doSomething(T param);
};
#include "Foo.tpp"
foo.tpp
template <typename T>
void Foo<T>::doSomething(T param)
{
//implementation
}
以这种方式,实施仍然与声明分开,但编译器可以访问。
另一种解决
方案是将实现分开,并明确实例化所需的所有模板实例:
foo.h
// no implementation
template <typename T> struct Foo { ... };
foo.cpp
// implementation of Foo's methods
// explicit instantiations
template class Foo<int>;
template class Foo<float>;
// You will only be able to use Foo with int or float
如果我的解释不够清楚,您可以查看 c ++ super-faq在此主题上。
使用 itertools.chain
:
from itertools import chain
out = {k: [list(chain.from_iterable(l))]
for k,l in dic.items()}
输出:
{1: [[1, 2, 3, 4, 5, 6, 7, 5, 1, 4, 34, 3, 65, 0, 2, 2, 5, 4, 5, 7, 8, 4, 7]],
2: [[1, 5, 4, 5, 0, 1, 4, 6, 2, 2, 3, 5, 6, 6, 3, 9]],
3: [[12, 35, 42, 53, 70, 71, 74, 76, 6, 11, 16, 17, 38, 62, 66, 77]]}
您可以使用通用物来说键
是对象
和 value
的键是该密钥的类型
interface Object {
name: string
age: number
}
let obj: Object = {};
function updateObject<K extends keyof Object>(key: K, value: Object[K]) {
obj[key] = value;
}
updateObject('name', 'foo'); // Fine
updateObject('name', 1); // Error
updateObject('age', 'foo'); // Error
updateObject('age', 1); // Fine
我相信您的目标如下。
- 通过访问授权URL,例如
https://www.reddit.com/api/v1/authorize?client_client_id=client_Id&Ampponseponse_tepe_type = code = code = code = code = code = code = random_state = random_state = random_state&am代码>使用浏览器,您需要使用Google Apps脚本创建的Web应用程序检索访问令牌。
在这种情况下,以下curl命令的请求由Google Apps脚本通过检索授权代码运行。
curl -X POST https://www.reddit.com/api/v1/access_token \\
-H 'content-type: application/x-www-form-urlencoded' \\
-A 'CLIENT_NAME' \\
-u CLIENT_ID:APP_SECRET \\
-d 'grant_type=authorization_code&code=CODE&redirect_uri=REDIRECT_URL'
在这种情况下,以下Web应用程序的示例脚本如何?
示例脚本:
function doGet(e) {
const clientId = "###"; // Please set your client ID.
const secret = "###"; // Please set your secret.
const redirectUrl = "https://script.google.com/macros/s/###/exec"; // Please set your Web Apps URL that you are using it as the redirect URL.
const url = "https://www.reddit.com/api/v1/access_token";
const params = {
method: "post",
headers: { "Authorization": "Basic " + Utilities.base64Encode(`${clientId}:${secret}`) },
payload: {
"code": e.parameter.code,
"grant_type": "authorization_code",
"redirect_uri": redirectUrl
}
};
const res = UrlFetchApp.fetch(url, params);
return ContentService.createTextOutput(res.getContentText());
}
-
在脚本中设置变量后,请将修改后的脚本反映为Web应用程序。
- 在此脚本中将 修改的脚本反映为Web应用程序。 .com/api/v1/authorize?client_id=xxxxxxxxxxxx&response_type=code&redirect_uri=https%3A%2F%2Fscript.google.com%2Fmacros%2Fd%2F1Nh3AKooeG8XH4rSTvEWLTf5l3Sgo3nPgK01qiusSany43fFNaUgg2q6b%2Fusercallback&state=ADEpC8xyajUigAfm1arE-N3gjrw-OLvI08gR23Y1ouQJpLpGtZ6ZPWTcpQRa8kW79ABqkxha1B8d90tb8B4eianNmJjFgzKzjCGwdxJ8lpDUdyNF7YjNq_3ak8d6Co_arPUDuP-BnbH0qRSwuEacP2Zif4wTt- YapR8VBbrkhr0tc6aScewnQPe9sCsOccRK6dITZ2SWFP_ZNA5rd03uP -f2hrjfmeormpfflzvfys9cvgdbziopee4k_6jqieg02zk_buqsoijkuweb3obtgpcqxhsu1qcrmxoxuzjucnuf8m_mbwkhoho-69 g9rnkchm_gnqmnkmchmhwqmhhw&and-24-thp4-thp4-thp4-thp4-thp4-thp4-thp4-thp4-tp ; scope = adsRead%20历史&amp; lisation = enderent ,然后单击“箭头”按钮,授权代码已发送到您的Web应用程序,并且访问令牌和刷新令牌被检索为以下。
{“ access_token”:“ ###”,“ token_type”:“ bearer”,“ expires_in”:86400,“ refresh_token”:“ ###”,“ scope”,“ scope”:“ adsread历史”}
注意:
-
在此修改后的脚本中,它假设您的函数
batcharchiveemail()
正常工作。请小心。 -
如果您禁用V8运行时,我认为可以在没有上述修改的情况下使用脚本。但是在这种情况下,循环的过程成本将变得很高。 ref ref 在此上
-
在这种情况下,Web应用程序的设置必须为
执行为:ME
和谁可以访问该应用程序:任何人
for New IDE。请小心。
如文档中所述
options: {
plugins: {
legend: {
labels: {
font: {
size: 20
}
}
}
}
}
将每个值推入数组,然后使用 .join()
制作逗号限制的字符串。
const response = {
chartstatus: [{
abs_status: "Bekerja",
total: "12"
},
{
abs_status: "Tanpa Keterangan",
total: "5"
},
{
abs_status: "Hari Libur",
total: "1"
}
]
}
let nama_status = [];
let jumlah = [];
$.each(response.chartstatus, function(key, value) {
status = value.abs_status.toString();
nama_status.push('"' + status + '"');
jumlah.push(value.total)
});
console.log(nama_status.join(', '));
console.log(jumlah.join(', '));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
我相信 @SOM-1的答案是有益的,但没有通过信息或调试数据证实。我相信假设并不总是正确的。
我调试了这两种情况下形成的mySQL查询
-1-
metadata.objects.update(value = cast(cast(f cast('value'),output_field = integerfield()) + 1,output_field = charfield = charfield()) )
2-
metadata.objects.update(value = cast(cast('value',integerfield()),integerfield()) + 1, charfield()))
和两者都给出与预期的相同输出。
请找到将mysqld选项添加到我的cnf并调试查询的链接。 https .com/blog/2018/10/how-to-show-queries-log-in-mysql.html
I believe the answer from @som-1 was informative but not substantiated with info or debugged data. I believe assuming is not always right.
I debugged the mysql queries formed in these two cases -
1 -
Metadata.objects.update(value=Cast(Cast(F('value'), output_field=IntegerField()) + 1, output_field=CharField()))
2 -
Metadata.objects.update(value=Cast(Cast('value', IntegerField()) + 1, CharField()))
andboth give the same output as expected.
Please find the link to add mysqld options to my.cnf and debug your queries. Location of my.cnf file on macOS
enabling queries - https://tableplus.com/blog/2018/10/how-to-show-queries-log-in-mysql.html
如何使用f表达式首先将字符串施放到int,然后将1添加到其上,然后施放到字符串和更新