question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Impossible to make href links work properly

See original GitHub issue

I’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.

screenshot from 2017-07-07 06-38-24

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:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
plumdogcommented, Nov 24, 2018

@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

<table>
  <thead><tr><th>URL</th></tr></thead>
  <tbody>
    <tr><td><a href="https://google.com">Google</a></td></tr>
    <tr><td><a href="https://yahoo.com">Yahoo</a></td></tr>
  </tbody>
</table>

which becomes:

URL
Google
Yahoo

It might be worth flask_table growing a dedicated column class that does something like this.

2reactions
CheapBcommented, Nov 24, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

My hyperlinks won't open. How do I fix this? - iSpring Solutions
First of all, make sure that the hyperlink has been created correctly: put your mouse cursor over a hyperlink and see if it...
Read more >
Common Hyperlink Problems - Suzanne S. Barnhill - Home
The link goes to the wrong place. This usually means that the display text of the hyperlink doesn't agree with the underlying link....
Read more >
Hyperlink Not Working In Word: How To Fix It In All Versions ...
Sometimes, we make mistakes while typing the hyperlinked text. We tend not to copy the link correctly too. So, it pastes incomplete hyperlink...
Read more >
Hyperlinks not working in Outlook? How to make links open ...
Right click the command subkey and select Export from the context menu. Export the registry key from the computer where hyperlinks in Outlook ......
Read more >
Internet Tips: Tips for Fixing Broken Links - GCF Global
Learn how to fix a broken link in this free lesson, which offers several tips for fixing broken links.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found