Creating a working downloadlink in a tab

Hi,
this is my first real programming project so please be patient and apologize my stupidity.
I am writting a Plugin that reads sensor data from i2c Sensors and writes those together with some fetched printinformation (temperature, progress, coordinates) into CSV-Files in a a folder like /home/data. So far so good. I understood python this far. But now for months i am trying to understand how i make those files accessible in the HTML of my Plugin-tab.
This combination of HTML and Jinja and assets and everything is just to much for me. I am sure it cant be this hard but i can't wrap my head around it.
It would mean a lot to me if anybody could just tell me step by step how to create a download link for those files in the Plugin-tab.

Thanks in advance and sorry if this isnt detailish enough for developement, but i thought it would be to much for the "Get Help" section.

If there are multiple files then you're going to have to deal with providing a list of files. To get that list of files I would use a SimpleApiPlugin mixin implementation and then on your on_tab_change viewmodel callback make the api call to your mixin implementation to receive the file list, and then assign that file list to a knockout observable. In your jinja template there would be a data-bind foreach for looping over the assigned observableArray and display it on the page.

Sorry, i am really out of frame. When you say a list of files, do you mean a list of file-paths? If so, I'll deal with that later.
Lets say i know the filename and path and it doesn't change. How can i "upload" the file for the ninja template? i have seen a dozen tutorials on how to create a download button and they all use a file that has a url assigned to it.
its so frustrating. I can learn the absolute html basics and then if i want to learn more about html and jinja, there are so many things that i am expected to know. there is just such a huge gap between basic and creating a simple download button in octoprint.

So if you keep the name the same and are saving it into a path using self.get_plugin_data_folder() in your python side then you can actually add a route hook to that data folder where the file is kept. Then in your jinja file you just have a relative link to your plugin's folder like <a href="/plugin/<plugin identifier>/file_name.csv"/>. This is a similar approach I use in the Custom Background plugin to load the image into the temperature tab. My route hook function you can find here.

Hopefully that helps you a little.

1 Like

That helped a lot, thank you very much. I managed to make that work for know. I really appreciate it.
But now I need to understand the filename transfer... I researched a bit and as far as I understood it so far, I have to use the API to get the filenames from my python script to the js-file and then I make those names observable via knockout and use a databind in the html to actually use them? This seems so... Unnecessarily complicated. And then there is flask? Is flask what compiles my jinja-template to a html-page? If so isn't there a way to use the API to get the filenames directly into my jinja template?

What do you mean, you said the filename would be the same? If it's always the same then no need to transfer it, just heard code it in jinja template.

Flask is the equivalent of a web server, it's what allows people to load content. Jinja is what converts the templates.