Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

312
Vistas
What is the pythonic way of building full urls for links?

I'm looking for a way to build urls in python3 without having to do string concatenation. I get that I can

import requests
url_endpoint = 'https://www.duckduckgo.com'
mydict = {'q': 'whee! Stanford!!!', 'something': 'else'}
resp = requests.get(url_endpoint, params=mydict)
print(resp.url) # THIS IS EXACTLY WHAT I WANT

or

from requests import Request, Session
s = Session()
req = Request('GET',  url, params={'q': 'blah'})
print(req.url)
# I didn't get this to work, but from the docs 
#   it should build the url without making the call

or

url = baseurl + "?" + urllib.urlencode(params)

I like that the request library intelligently decides to drop ? if it isn't needed, but that code actually makes a full GET request so instead of just building a full text url (which I plan to dump to an html tag). I am using django, but I didn't see anything to help with that in the core library.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Django comes with QueryDicts which basically do everything you want.

def make_url(url, args=None):
    query = QueryDict(mutable=True)
    query.update(args or {})
    return '{}{}{}'.format(url, '?' if query else '', query.urlencode())

It supports multiple values per argument just like you can encounter in a url: example.com/foo?a=1&a=2&a=3.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda