1

I am using Ipython Notebook 2

I have a file name in variable which dynamically calculates the location and file name of file located in current directory, And I want to insert that variable in my markup to download it

below is the code:

  result_file ="Revenue_per_city"+start_date+"_"+end_date+".xlsx

then my markup to download the file:

 <a href= {{result_file}}> Click here to download the result</a> 

but its not working as expected

2
  • There is a typo. Spelling of href in the code. Commented Jan 25, 2016 at 7:45
  • @JasonEstibeiro thanks for the correction but this is not the probelm :) Commented Jan 25, 2016 at 8:31

1 Answer 1

4

You can display HTML using tools from the IPython.display module:

  • HTML is an object representing HTML as text
  • display is a function that displays objects (like print, but for rich-media objects)

For example:

from IPython.display import display, HTML

# create a string template for the HTML snippet
link_t = "<a href='{href}'> Click here to download the result</a>"

result_file = "Revenue_per_city" + start_date + "_" + end_date + ".xlsx"

# create HTML object, using the string template
html = HTML(link_t.format(href=result_file))

# display the HTML object to put the link on the page:
display(html)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.