Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.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
在python中格式化字符串并将其传递给URL_Python_Django - Fatal编程技术网

在python中格式化字符串并将其传递给URL

在python中格式化字符串并将其传递给URL,python,django,Python,Django,如何在url中附加两个不同的字符串变量。 但这是不可接受的 def get_customer_action_by_target_group(self): payload = {"TargetGroupID": "%s" % self.TargetGroupID, "Date":"%s" % self.date, } if not self.TargetGroupID or not self.date: get

如何在url中附加两个不同的字符串变量。 但这是不可接受的

def get_customer_action_by_target_group(self):
       payload = {"TargetGroupID": "%s" % self.TargetGroupID, 
       "Date":"%s" % self.date,
                }

    if not self.TargetGroupID or not self.date:
        get_target_group_id = int(raw_input("Please provide the target Group id:"))
        get_date = (raw_input("Please provide the date as required:"))
        self.TargetGroupID = get_target_group_id
        self.date = get_date
    response = self.send_request(self.get_customer_action_by_target_group_url % self.TargetGroupID %
                                 self.date,
                                 json.dumps(payload),
                                 "GET")

    print response, response.text, response.reason

    return response
这句话:

self.get_customer_action_by_target_group_url % self.TargetGroupID % self.date

是不正确的;假设
self.get\u customer\u action\u by\u target\u group\u url
是一个格式字符串,包含
%s
正好两次,则应使用两元素元组作为
%
运算符的右侧参数:

self.get_customer_action_by_target_group_url % (self.TargetGroupID, self.date)

get\u customer\u action\u by\u target\u group\u url
是方法本身,尝试将其视为字符串是没有意义的。不,它不是方法。。它只是变量本身,url variableCool。但是我收到的是这样的->类型错误:不是所有的参数都在字符串格式化过程中转换好,
self.get\u customer\u action\u by\u target\u group\u url
?get\u customer\u action\u by\u target\u group\u url=''基本上这个变量包含一个url。所以self.get\u customer\u action\u by\u target\u group\u url。包含get_customer_action_by_target_group_url=''正如我前面所说,此字符串必须包含
%s
,在您希望插入
self.TargetGroupID
self.date
值的位置…