I am planning to build a simple web page that has an upload file option, submit button and a table to display the results.
The file i would be uploading is an XML file.
Upon submit, a python script should validate the XML file and display the discrepancies in the HTML page.
What is the best way to proceed with the front end and python integration? I have already validated the XML using python scripts but i am unable to find out a way to integrate it with HTML, upload & submit buttons.
Kindly help or let me know if you need any further details.
You'll want to use a web framework to do this. Some good options for python are Flask and Django. HTML is meant to run on the client's browser, where Python (in this situation) is meant to run off of a server. Django, Flask, and others make this quick and easy to do.
Related
I made a python chatbot which I want to implement in my HTML (+ CSS & js) website. I want to call the python file with an HTML button and the python file should return a variable (output string) which I could use to display the user on the HTML website.
I've tried Brython, but I couldn't figure out how to import packages
like nltk and tensorflow.
I've tried flask, which works great, but the python file is the main
file, who renders the HTML template. But that's not possible in my
case. The HTML file should be the main file. And the website should remain
on the same URL and, as far as I know (please correct me if I'm wrong),
flask is URL based.
I've tried translating all the python code into javascript manually,
which worked but isn't a long-term solution for me.
So: what is the best way to run a python file with packages externally or internally in a HTML website without redirection?
Thanks a lot in advance!
As you mentioned that HTML file is the main file you are loading the application using some server like nginx or apache? If yes, then why Flask is the problem? It seems that you could load data from Flask app using JS. You would still be on the same URL the JS would do everything in the background and possibly using JQuery you could render html components with data from Flask. (HTML based site loads content from Flask App using JS, the flask app is hosted somewhere else)
However as it is a chat application I would suggest something based on websockets.
The additional option could be to use webassembly for Python which is weird but theoretically possible.
I want to make a script in python that interacts with a webpage that has quite a lot of javascript in it (it's a webpage that computes a bunch of physics stuff).
I don't want my code to break if the page formatting changes and I want it to run offline so I would prefer my script to run on a local html copy of the page I got (all the JS code is accessible in the HTML source, there is no call to an external server). I wanted to use the requests library to do it, but it only works with URLs. Is there any library to do this? Note that I want to interact with the HTML (input values and look at the outputs etc..), I know that I can parse the file but that's not what I'm asking. I'm also totally new to web bots or anything related.
Right now I can open my .html version of the page offline with chrome and interact with it, so there has to be a way to automate this somehow. I'm also not against using something else than python if there is a better library for this in another language.
interesting question, best way I can think to do that is use a web framework and then just scrape the data using requests. I am familiar with flask and its simple to use but im sure there are other options as well
I was trying to build a blog website and was wondering to add a functionality that loads a new page as the user scroll down. I found some other answers to this but they all have some JSON or Javascript in them. As I Don't know any of these languages, I was wondering if there was a way I can do this just using Django Pagination And Stuff.
Thanks In Advance.
Django will only run on your server. The client won't run any python related code on their machine.
Usually, browsers display HTML/CSS and can run client-side code in JavaScript.
So since the browser does not get in contact with django itself, you must use JavaScript to do anything after the page has been loaded.
It's not much javascript you will need, so start reading this: https://www.w3schools.com/js/
Information on how to get the scrollbar in JS: How to get scrollbar position with Javascript?
You can install Django EL(Endless) Pagination and using this package to endless pagination. Using and configuration of this package is very simple.
I have written a scraper tool in Python which when executed produces a CSV file of information. I wish to embed it in a HTML, so within the page the user is able to run it and then the results are displayed on the page from the CSV file. How can I do this?
If you only need to display the information on a website, no interaction back with your python script, all you need to do is just write the results into a HTML file and .format() it appropriately.
However, since this requires the user to be able to run and view the results with interaction with your python script, you would need a web server.
You could try the two most popular python based web servers that can accomplish this: Flask and Django or you could use the less common but more lightweight Simple HTTP Server.
But, do keep in mind that an easier alternative (if possible) will be to just use a GUI such as Tkinter or PyQt or EasyGUI.
I have a program written for text simplification in python language, I need this program to be run on a browser as a plugin... If you click the plugin it should take the webpage's text as input and pass this input to my text simplification program and the output of the program should be again displayed in another web page...
Text simplification program takes input text and produces a simplified version of the text, so now I'm planning to create a plugin which uses this program and produces simplified version of text on the webpage...
It will be of great help if anyone help me out through this...
You would need to use NPAPI plugins in Chrome Extension:
http://code.google.com/chrome/extensions/npapi.html
Then you use Content Scripts to get the webpage text, you pass it to the Background Page via Messaging. Then your NPAPI plugin will call python (do it however you like since its all in C++), and from the Background Page, you send the text within the plugin.
Concerning your NPAPI plugin, you can take a look how it is done in pyplugin or gather ideas from here to create it.
Now the serious question, why can't you do this all in JavaScript?
If you want an easier way than trying to figure out plugins, make it run as a webservice somewhere (Google App Engine is good for Python, and free), then use a bookmarklet to send pages from the browser. As an added bonus, it works with any browser, not just Chrome.
More explanation:
Rather than running on your own computer, you make your program run on a computer at Google (or somewhere else), and access it over the web. See Google's introduction to App Engine. Then, if you want it in your browser, you make a "bookmarklet" - a little bit of javascript that grabs the web page you're currently on (either the code or the URL, depends on what you're trying to do), and sends it to your program over the web. You can add this to your browser's bookmark bar as a button you can click. There's some more info on this site.