****Python Integration with HTML****
Python Integration with HTML

****Python Integration with HTML****

Website :- The I.P. address where your web page is located.

Web App :- The web page that runs code.

We have two types of web pages :-

1) Static Web page (only contains text) 2) Dynamic Web Page

/var/www/html/ ---> contains all static web pages.

Now, here we have to make a web page in which we have an input box where user provides the input.

Here we use HTML --> HyperText Markup Language

No alt text provided for this image

Here,

<input / name = "x" type = "text"> : # input tag in HTML provides us an input box where user can give input in text format. input tag has various attributes here type is an attribute , by default type is in text format. name attribute means whatever user gives input will be stored in variable name "x".

<input / name = "y" type ="password"> : # here attribute type is password which means the input would be hidden.

<input / name = "r" type = "radio"> : # here attribute type is radio means it provides radio button.

<input / name = "c" type = "checkbox" > : # here attribute type is checkbox , provides checkbox to the user.

<br> : inserts a single line break. break tag do not have an end tag.

This is the output

Now, if user provides input the input is not stored in any of the variable.

No alt text provided for this image

So to make the value to be stored we use form tag :-

No alt text provided for this image

Now, we can see as soon as I press enter the value is been stored in the variables that we have assigned :-

No alt text provided for this image

Now, form tag has an attribute named action in which we can provide any URL i.e., after clicking on submit button it goes to that particular URL.

No alt text provided for this image

As soon as I press enter it jumps to "http://192.168.43.45/cgi-bin/myfile.py" and displays the content of the URL provided.

No alt text provided for this image
No alt text provided for this image

Now, on client's browser client will provide any command that is present in my server and get output on the client's browser.

Python has a function named FieldStorage from cgi module. This function reads the input provided by user.

No alt text provided for this image

Now, by using getvalue function we can get the value of any variable we want for example:

No alt text provided for this image

Here, x, y, r, c are the attributes of input function that we mentioned above.

No alt text provided for this image
No alt text provided for this image

Now, we can modify the code in such a way that whatever user gives command as an input on clients browser the command will be stored in the server and by using python subprocess module we can provide output on the browser.

No alt text provided for this image

Now we provide input :-

No alt text provided for this image
No alt text provided for this image

So in this way we integrated python with HTML. Here, we created dynamic Web App.

Some important points :-

1) Web Server never executes HTML code. 2) Client Browser runs the HTML code. 3) Browser has HTML interpreter so, HTML is known as client-side language.

Difference Between Radio Button and CheckBox :-

> In radio button, variable value is stored i.e., on clicking to one of the button the value is stored in the "r" variable here (as mentioned above) and as we click on the next button the previous value is restored by the new value in the way as it happens in variables.

> In checkbox, list/array is stored i.e., we can stored multiple values i.e., we can select multiple boxes.

Thanks for Reading :)




Vrukshalli, very good detailed notes. I have been following your notes and very helpful. Thanks for sharing. Keep sharing !!

Like
Reply

Great.... keep going !😇👍👍

Like
Reply

To view or add a comment, sign in

More articles by Vrukshali Torawane

  • Concept of API and CGI :-

    API :- Application Programming Interface CGI :- Common Gateway Interface So our task is : There are two operating…

    4 Comments

Others also viewed

Explore content categories