Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 在另一个变量中传递一个变量_Django - Fatal编程技术网

Django 在另一个变量中传递一个变量

Django 在另一个变量中传递一个变量,django,Django,可能重复: 我试图执行以下操作: # the request send a number and its ok, the variable have good informations. test = request.POST[member.user.username] # SyntaxError at ***here***, can't assign to operator group%d % test = member.us

可能重复:

我试图执行以下操作:

        # the request send a number and its ok, the variable have good informations.
        test = request.POST[member.user.username]

        # SyntaxError at ***here***, can't assign to operator
        group%d % test = member.user.username
我也尝试过:

        test = request.POST[member.user.username]
        group%d = member.user.username % test
以及:


对语法有什么想法吗

您可以使用dictionnary来执行此操作:

test = request.POST[member.user.username]
d={}
d['group'+str(test)]= member.user.username

也许有更好的方法可以做到这一点,但我只知道这一点。

您希望通过“组%d”实现什么?格式化字符串的常用语法是:
result=format%(var1,var2)
。我想要像group1,group2这样的变量……我无法使用它。。我找到了另一个避免变量的解决方案:)
test = request.POST[member.user.username]
d={}
d['group'+str(test)]= member.user.username