****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
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.
Now, if user provides input the input is not stored in any of the variable.
So to make the value to be stored we use form tag :-
Now, we can see as soon as I press enter the value is been stored in the variables that we have assigned :-
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.
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.
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.
Now, by using getvalue function we can get the value of any variable we want for example:
Here, x, y, r, c are the attributes of input function that we mentioned above.
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.
Now we provide input :-
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 :)
Well explained👍
Good content Vrukshali Torawane
Great work
Vrukshalli, very good detailed notes. I have been following your notes and very helpful. Thanks for sharing. Keep sharing !!
Great.... keep going !😇👍👍