Friday, June 22, 2018

Re: How to run python script by clicking a HTML button?

Hi Subhendu,

To make this all work, you'll need to do this:

1. Create a Django app
2. Add some URL to a view (any view)
3. Inside the view, run your script.
4. Change the for on the "action" to point to the URL in point 2.

You may want to read the Django Tutorial[1] to grasp who those things are implemented and connect to each other.


On Thu, Jun 21, 2018 at 1:43 PM, SUBHENDU PANDA <subhendu.panda93@gmail.com> wrote:
Below is my HTML code...

<!DOCTYPE html>
<html>
<body>

<h2>HTML Forms</h2>

<form action=" ">
  First name:<br>
  <input type="text" name="Directory" value="C:\MyDir">
  <br>
  <br>
  <input type="submit" value="VIEW">
</form> 

<p>I want is : If you I the "Submit" button, the form-data will be sent to a page called "/myscript.py and will perform the operation".</p>

</body>
</html>






myscript.py:

import os

def  f1():
       print ("Below are the files present in your Directory { }" .format(os.listdir("C:\MyDir "))

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a4fd2aa4-b28a-465f-aaab-dc279c4647d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Julio Biason, Sofware Engineer
AZION  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101  |  Mobile: +55 51 99907 0554

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEM7gE0CuGO2g%3DUTZsn7Hc9cC%2BzUreqCMTE8HiYzrB0r0SyCMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment