Impossible to make href links work properly
See original GitHub issueI’m trying to make a web-page that displays a bunch of values from MongoDB, here is my code:
class LangCol(Col): # This lets me get a webaddress into the table
def td_format(self, content):
parsed=urllib.parse.unquote(content)
split = urlsplit(parsed)
return ('<a href='+("".join(['http://',split.netloc, split.path]))+ '>'+content+'</a>')
class ItemTable(Table):
ID = Col('IDs')
type = Col("type")
Job_URL = LangCol("URL")
items = mongodb.bdb.find({"OS" : "CentOS7.3"})
items2 = mongodb.bdb.find({"OS" : "RHEL7.3"})
# Get some objects
#class Item(object):
# def __init__(self, name, description):
# self.name = name
# self.description = description
#items = [Item('Job1', 'Job1'),
# Item('Job2', 'Job2'),
# Item('Job3', 'Job3')]
app = Flask(__name__)
@app.route('/')
def index():
table = ItemTable(items)
table2 = ItemTable(items2)
return table.__html__()
The relevant code is the return statement of LangCol I’ve tried other returns, such as (the one I REALLY hoped would worked)
return ('<a href='+content+ '>'+content+'</a>')
Unfortunately, no matter what I do, I either get a URL that includes my hosted flask server (like http://127.0.0.1:5000/http%3A//10.23.182.101%3A8080/job/(CHPC) Factory - CentOS 7.3 x86_TS/57/) or, if I unquote my weburl instead, it will truncate everything after part of my link (like http://10.23.182.101:8080/job/(CHPC) )
This issue is very frustrating, because the closest thing to a solution I’ve found looks like it should, but doesn’t work correctly.
https://stackoverflow.com/questions/17056408/flask-jinja2-href-not-linking-correctly
As we can see, content displays the exact URL correctly on the page. I want this exact URL to be a clickable hyperlink to the address that it prints. Unfortunately, this seems to be impossible.
I’m an intern at a large tech company which probably makes your CPU, and I (along with my team) am very inexperienced with web technologies. Apologies if I’m doing something silly and don’t notice it.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Top GitHub Comments
@CheapB You are absolutely right.
I’ve added an example here: https://github.com/plumdog/flask_table/pull/116 that I think does what you want.
That example gives output that looks like
which becomes:
It might be worth
flask_table
growing a dedicated column class that does something like this.That is EXACTLY what I was going for. I am working on getting all my templates moved to Flask Table and this is a huge step in the right direction. Thank you very much.