Skip to content

Instantly share code, notes, and snippets.

@bluethon
Created October 15, 2016 06:35
Show Gist options
  • Save bluethon/4b14ee0c4590b3ef3a099f6e33b96285 to your computer and use it in GitHub Desktop.
Save bluethon/4b14ee0c4590b3ef3a099f6e33b96285 to your computer and use it in GitHub Desktop.
urlencode
from django.http import QueryDict
def url_with_querystring(path, query_dict):
""" URL查询参数拼接 """
qdict = QueryDict('', mutable=True)
qdict.update(query_dict)
return path + '?' + qdict.urlencode()
url_dict = {
'course': course,
'term_id': term_id,
'item': str(item),
'info': str(info_id)
}
url = url_with_querystring(reverse('order:invoice_pay_confirm'), url_dict)
from urllib.parse import urlencode
def url_with_querystring(path, query_dict):
""" URL查询参数拼接 """
return path + '?' + urlencode(query_dict)
url_dict = {
'course': course,
'term_id': term_id,
'item': str(item),
'info': str(info_id)
}
url = url_with_querystring(reverse('order:invoice_pay_confirm'), url_dict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment