Search code examples
pythonfunctionbottle

Including html anchor tags in the 'Yield' of the Bottle framework


Newly playing around with the Bottle framework in python.

I'm trying to include an anchor tag that links to a local folder in the 'Yield' component of the bottle framework.

I keep getting an error when I try to include anchor tags in the Yield statement

Snippet of code is below:

 from bottle import Bottle,run

 app = Bottle()

 @app.route('/conn')
 def conn():
     yield '<center> <p>Here is the <a href="file:///C:\Programs\Documents">Connection Folder </a>  </p> </center>'

The above code is not running, I get an error saying 'SyntaxError'. I expected to get a result whereby on connection the initial webpage yields to a new webpage with the statement 'Here is the connection folder' (where the string Connection Folder is a link to the local folder)

EDIT 1: I have now gotten the code to work by doing this:

 from bottle import Bottle,run

 app = Bottle()

 @app.route('/conn')
 def conn():
     yield '<center> <p>Here is the <a href="file:///C:\\Programs\\Documents">Connection Folder </a>  </p> </center>'

That is by adding double slashes

Now my question now is that the link is not opening up the required folder, is there anything I should add to the code above?


Solution

  • I finally figured out an answer to my question:

    1) The error of SyntaxError was sorted by doing either of these two: Using either double back slashes or single forward slash worked.

    2) I then encountered another challenge where the link could not access a local folder due to the security setups of Chrome.

    I worked around this by looking at this post: Open local folder from link