Python Forum
I need litte help with linking to another website.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need litte help with linking to another website.
#1
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?
Reply
#2
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
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
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'
Reply
#4
Thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  CSS not linking with CGI script x64 8 14,860 Nov-14-2016, 07:54 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020