I am exploring Python. I read a csv file and selected some fields of it so that I could display it on a local server in the browser. The thing is that I don’t know how to do that. I know that using JS I only need to write the script tag in the HTML document linking to the specific JS document. But how do I do it in Python? I searched for it on google and people have videos on YT of 15min average explaining how to do it. Is it that hard? Is it the time when a framework comes in?
“Hard” is relative. But understanding the context of what you want to do isvery important, and that’s before you even start learning how to execute it using Python.
JS has gotten popular because its the language of the web, it along with HTML/CSS make up the core components of what the web runs on in the browser. Your Python code will have to create/send/increate with HTML/CSS to send to the user, but can’t directly be ran in the browser like JS.
You might want to use some libraries for Python, to read the CSV, to get the data you want, and another library to send data to the client when requested, so a simple web server library with a template rendering library should suffice. Sure you can go with some heavyweight like Django, but I’d say thats overkill for what it sounds like you want to do.
You also could offset some of the required code by doing more with JS in the browser, and just return raw data, rather than the full HTML+CSS+JS combo from Python.
Lots of options, but yes it can get complicated, but such is the nature of the web.
@caiohenriquesa1 Python cannot display anything on a web page by itself. You need a web framework to be able to use with Python to be able to display data on a web page. Flask is an easy framework you can you to accomplish your goal.
Here is a good tutorial you can use to get started.
To add to the posts above, the short version is that you’re going to need to do some “back-end development” and set up a Python API. Hitting an API endpoint from your front-end (via Ajax) is basically how you’re supposed to do that.
If all you have will be one endpoint and you’re programmatically going to hit the endpoint manually, that’s a fairly simple task to do with a simple framework like Flask.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.