Python Forum

Full Version: I need litte help with linking to another website.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi.
I need little help with linking to another website.
Now i know how to make a link in html and use return redirect in route to link.
But my problem is that i need to combine the adress with a string.
Here is an example if i just wanted to link to one singel product on that webpage i
would use this adress "https://www.elektroskandia.se/s?s=hylsor&artnr=2972252"
But because i am using the their product numbers and its more efficient to have python generate the links
I was thinking something like

string = "2972252" <-- it will be taken from the db in the future this just an example.

https://www.elektroskandia.se/s?s=hylsor&artnr=string

Do anyone have any good idea how to do it?
Usual way is to use placeholders (either .format method or f-strings).

With f-strings (3.6 <= Python):

>>> lst = ['spam', 'ham', 'eggs']
>>> for item in lst:
...     print(f'My favourite {item}')
... 
My favourite spam
My favourite ham
My favourite eggs
As mention bye @perfringo use f-string.
>>> art_nr = "2972252"
>>> url = f'https://www.elektroskandia.se/s?s=hylsor&artnr={art_nr}'
>>> url
'https://www.elektroskandia.se/s?s=hylsor&artnr=2972252'
Thank you.