[Tutor] Webinterface for python script

Alan Gauld alan.gauld at yahoo.co.uk
Wed Jan 30 13:53:47 EST 2019


On 30/01/2019 14:06, Asad wrote:

>           I have created certain python scripts to analyze log files and
> suggest solution based on logic which I invoke on the command line . I need
> some information on how to execute these through browser . I am using :
> 
> python test.py file1 file2
> 
> How do I use the browser to upload the files file1 and file2 and it process
> the files .

It's not clear how you think this will work.
You say 'upload the files through a browser'.
Where do you want to upload them too?
Do you have a web server somewhere or can you
set one up?

If so then you need to write a web application
to select the local files from the users PC and
upload them to the server. Once you have that, you
can call your Python script on the server and
display the output as HTML back on the users browser.

To do that will probably involve changes to your
existing code to make it callable as a function and
to have the output displayable as HTML.

There are many web frameworks you can use and for
this type of project any of them will suffice.
There is a page summarising the most common here:

https://wiki.python.org/moin/WebFrameworks/

I recommend Flask and you can see a short tutorial
on its use in my tutor under the topic "Using Web App Frameworks."
There are several other, more in-depth, tutorials
if you think its for you.

For the browser specific bits you can probably find
all the code you need via Google...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list