What will we learn?
- Python Private Lessons / Series 4 ( Using URL links )
![]()
Requirements:
- Notepad+
- Operating System
- Python
Difficulty Level:
- Normal Level
Let's Start the Course :
While clicking on a site, we can create some variables in the URL structure and populate those variables. This type of URL is called sending data via the "GET" method.
To access the variables on the right side of the question mark we need to add the "CGI" module in our Python file. We will use this module frequently.
import cgi
Create a new variable with the "FieldStorage ()" method in the "Cgi" module.
x = cgi.FieldStorage()
Now we can use the getFirst () method in the variable "x" to get the value of the variable in the address line.
Name = x.getfirst("name")
Surname = x.getfirst("surname")
Gender = x.getfirst("gender")
print ("""
<strong> Name : </strong> """ + name + """ <br>
<strong> Surname : </strong> """ + surname + """ <br>
<strong> Gender: </strong> """ + gender + """ <br>
""")
See all the Codes again.
#!/usr/bin/python
import cgi
# Turn on debug mode.
import cgitb
cgitb.enable()
# Print necessary headers.
print("Content-Type: text/html")
print()
x = cgi.FieldStorage ()
Name = x.getfirst("name")
Surname = x.getfirst("surname")
Gender = x.getfirst("gender")
print ("""
<strong> Name : </strong> """ + name + """ <br>
<strong> Surname : </strong> """ + surname + """ <br>
<strong> Gender: </strong> """ + gender + """ <br>
""")
If we return null, we can specify in the second parameter the value to be assigned by default.
x.getfirst ("Gender", "Unspecified")
In such a use, if there is no gender data, it will return to us as "Unspecified". In the next section you will find a more detailed example of the process.
Form Operations
The form structure is used to retrieve data from internet pages and handle them dynamically. For example, we usually use the form structure when performing operations such as member entry, member registration, membership settings, ordering from e-commerce sites, file uploading. The form structure is a feature that will surely come into conflict. Let's make a member registration form using a form structure.
In the previous section, we performed the operation of the data sent with the "get" method. Now we will process the data sent by "POST" method. First, let's prepare a form with HTML codes. Keep these codes in the form.html file.
<style>
input {
padding: 15px;
height: auto;
display: block;
margin-bottom: 10px;
width: 400px;
font-size: 14px;
background: #f9f9f9;
border: soild 1px #d9d9d9;
}
button{
padding: 10px 15px;
border: soild 1px #d9d9d9;
border-radius: 4px;
background: #67B031;
color: #fff;
</style>
<form action="send.py" method="post">
<input type="text" name="name" placeholder="Write Your Name">
<input type="text" name="surname" placeholder="Write Surname">
<input type="text" name="email" placeholder="Write Email Address">
<button type="submit">SEND</button>
</form>
We prepared the form and gave it a nice style.

As we indicated in the action parameter in the "