How to run python script by clicking a HTML button?

3,302 views
Skip to first unread message

SUBHENDU PANDA

unread,
Jun 21, 2018, 4:15:18 PM6/21/18
to Django users
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 "))

Jani Tiainen

unread,
Jun 21, 2018, 4:45:11 PM6/21/18
to django...@googlegroups.com
Hi,

Django doesn't exactly work that way.

Please do the official tutorial from Django docs to get grasp of basics how things works and are tied together.

--
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...@googlegroups.com.
To post to this group, send email to django...@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

unread,
Jun 22, 2018, 8:47:13 AM6/22/18
to django...@googlegroups.com
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.


--
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.



--
Julio Biason, Sofware Engineer
AZION  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101  |  Mobile: +55 51 99907 0554
Reply all
Reply to author
Forward
0 new messages