0

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

Thomas K
  • 39,200
  • 7
  • 84
  • 86
user3482218
  • 1
  • 1
  • 2

1 Answers1

3

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)
alkasm
  • 22,094
  • 5
  • 78
  • 94
minrk
  • 37,545
  • 9
  • 92
  • 87