Django Bootcamp🐍 - Part Two - HTML📝


In my last article, we took  a quick glance at Full-Stack Development in Python. There are two major parts -- Front-End and Back-End. We started with Front-End development with HTML. We have discussed how to download the Atom Editor and how to create a basic HTML file within this editor with the basic tags and attributes. Sometimes, HTML seems pretty basic but we have to start from scratch so it is a crucial part of any web development endeavor. Here, we will cover more two features of HTML tables and Forms.

HTML Tables

Tables in HTML consist of several tags together,
  • <thead>: Table head
               <th>: Table coloumns
  • <tr>: Table rows
                 <td>: Table cells
Every tag has an opening, and closing tags are required. <thead> is not a compulsory section for the table structure but it will give to the user a proper idea about the columns and arrangement of the rows. Let's check the below code and example with table tags. 
Example 1
In this example, we have taken three countries with name, flag, and weather details.
We have used image tags within a row and <img> tag is used with another attribute like height and width.  
  1. <!DOCTYPE html>  
  2. <html lang="en" dir="ltr">  
  3.     <head>  
  4.         <meta charset="utf-8">  
  5.             <title>This is part-2 file</title>  
  6.         </head>  
  7.         <body>  
  8.             <table border="1">  
  9.                 <thead>  
  10.                     <th>Countries Name</th>  
  11.                     <th>Countries Flag</th>  
  12.                     <th>Weather</th>  
  13.                 </thead>  
  14.                 <tr>  
  15.                     <td>India</td>  
  16.                     <td>  
  17.                         <img src="255px-Flag_of_India.svg.png" width="200" height="100" alt="">  
  18.                         </td>  
  19.                         <td>30 Degree Celcius</td>  
  20.                     </tr>  
  21.                     <tr>  
  22.                         <td>USA</td>  
  23.                         <td>  
  24.                             <img src="220px-Flag_of_the_United_States.svg.png" width="200" height="100" alt="">  
  25.                             </td>  
  26.                             <td>21 Degree Celcius</td>  
  27.                         </tr>  
  28.                         <tr>  
  29.                             <td>Germany</td>  
  30.                             <td>  
  31.                                 <img src="255px-Flag_of_Germany.svg.png" width="200" height="100" alt="" >  
  32.                                 </td>  
  33.                                 <td>24 Degree Celcius</td>  
  34.                             </tr>  
  35.                         </table>  
  36.                     </body>  
  37.                 </html>     
Try this code for the practice. 
We can also do styling with table attributes. For a more functional site, we have to do this styling with CSS. We will discuss it soon.
Let's move on with forms.

HTML Forms

The form will be a key component of Django later on, but in order to understand how to use them with Django, we need to fully understand them with just HTML.  
To make a form we will use <input> tag. Different input types are used with input tag like text, radio, checkbox, email, password, color reset, etc. 
For more details please check this link here.
Example 2 
Let's check this example having three different input types: Email, Password, and Submit 
Here is the code for the output screen as below,
  1. <!DOCTYPE html>    
  2. <html lang="en" dir="ltr">    
  3.   <head>    
  4.     <meta charset="utf-8">    
  5.     <title>HTML Forms</title>    
  6.   </head>    
  7.   <body>    
  8.     <form>    
  9.     <h1>Login Form</h1>    
  10.     <h2>Please fill the details:</h2>    
  12.     <input type="email" name="useremail" value="Enter Email">    
  13.     <input type="password" name="password" value="valid password Please">    
  14.     <input type="submit" name="Submit" value="Submit">    
  15.     </form>    
  16.   </body>    
  17. </html>    
You can see the differences between these two images. Without a valid email format it couldn't be possible to click Submit. It will generate a pop-up message. Also there is a password in non-readable mode or we can say it is encrypted type. Submit is a button most probably so it's in Button form. In this form there are email, password and submit input types executed. 
Now, we will move on with labels and actions. 
The use of the label tag will allow you to add labels in front of input in your HTML form. We will also learn how to activate actions by clicking submit.
  1. <body>    
  2.    <form action="" method="get">    
  3.       <h1>Enter text and take me to Google</h1>    
  4.          <input type="text" name="userinput" value="">    
  5.          <input type="submit" name="Submit" value="Submit">    
  6.    </form>    
  7. </body>  
We can see the redirection of these two windows in an image, where username value is "hello" and page performs the action to the mentioned link: in the form tag. This is the example of ACTION in form.
Let's check with Label Tag.
In this example, we will give two simple labels to the text boxes. Label tag has an attribute 'for' and we will take a quick glance below. 
  1. <body>  
  2.     <form>  
  3.         <label>    
  4. Enter Text:    
  6.             <input type="text" name="" value="block1">  
  7.             </label>  
  8.             <label>    
  9. Enter Text:    
  11.                 <input type="text" name="" value="block2">  
  12.                 </label>  
  13.             </form>  
  14.         </body>    
 Now, we will see how the for attribute is used with <label> tag. 
In Label tag, for attribute has a value which always matches the other value of the <input id=""> id attribute. Also we have used placeholder attribute with input tag which will be good looking compared to value attribute.  See this in the below code snippet, 
  1. <body>    
  2.    <form>    
  3.       <!--use of for with label-->    
  4.       <label for="username">Enter User Name:</label>    
  5.       <input id="username" type="text" name="Enter name" placeholder="Enter Name">    
  7.    </form>    
  8. </body>     
That's all about the Labels and Actions using Form. 

Form Selection

Let's explore the input methods for forms:
  • Radio Button
  • Drop Down Menu
  • Text Area Inputs
There is another example which has all these methods used in different ways. 
  1. <body>  
  2.     <h1>Feedback Form</h1>  
  3.     <form method="get">  
  4.         <h2>Are you from India?</h2>  
  5.         <label for="in">Inside:</label>  
  6.         <input id="in" type="radio" name="a" value="">  
  7.             <label for="out">Outside:</label>  
  8.             <input id="out" type="radio" name="a" value="">  
  9.                 <h2>Service Stars</h2>  
  10.                 <select name="Stars">  
  11.                     <option value="Excellent">3</option>  
  12.                     <option value="Good">2</option>  
  13.                     <option value="Average">1</option>  
  14.                 </select>  
  15.                 <input type="submit" name="" value="SUBMT">  
  16.                     <h2>Any Other Feedback?</h2>  
  17.                     <textarea name="mytext" rows="8" cols="80"></textarea>  
  18.                     <input type="submit" name="" value="SUBMT">  
  19.                     </form>  
  20.                 </body>    
Inside this image, there are two values generated in the address bar after clicking the Submit Buttons.
Here, we have checked the <input> tag type with radio button, used two different tags: <select> for Drop Down Menu, <textarea> for writing some text in a box, with enough space.
This is a complete combo of this article's content. Kindly find the attached file which has its complete code.
  1. <!DOCTYPE html>  
  2. <html lang="en" dir="ltr">  
  3.     <head>  
  4.         <meta charset="utf-8">  
  5.             <title>HTML Forms</title>  
  6.         </head>  
  7.         <body>  
  8.             <h1>Course Signup Page</h1>  
  9.             <form method="get">  
  10.                 <p> Please note First Name, Last Name, Email and Password are required:</p>  
  11.                 <lable>First Name:   
  12.                 </label>  
  13.                 <input type="text" name="fn" placeholder="First Name">  
  14.                     <lable>last Name:   
  15.                     </label>  
  16.                     <input type="text" name="ln" placeholder="Last Name">  
  17.                         <p>  
  18.                             <lable>Email:   
  19.                             </label>  
  20.                             <input type="Email" name="e" placeholder="">  
  21.                                 <lable>Password:   
  22.                                 </label>  
  23.                                 <input type="password" name="ln" placeholder="Password">  
  24.                                 </p>  
  25.                                 <p>Are you over age of 18?    
  27.                                     <p>  
  28.                                         <label for="r">Yes</label>  
  29.                                         <input id="r" type="radio" name="y" value="">  
  30.                                             <label for="ra">No</label>  
  31.                                             <input id="ra"type="radio" name="y" value="">  
  32.                                             </p>  
  33.                                         </p>  
  34.                                         <p>Do you have a Credit Card or PayPal?    
  36.                                             <p>  
  37.                                                 <select name="Payment">  
  38.                                                     <option value="Credit Card"> Credit Card </option>  
  39.                                                     <option value="PayPal"> PayPal </option>  
  40.                                                 </select>  
  41.                                             </p>  
  42.                                             <input type="submit" name="" value="SIGN UP">  
  43.                                             </p>  
  44.                                         </form>  
  45.                                     </body>  
  46.                                 </html>    


HTML is completed for the web development in Django with its basic important tags and attributes. Further, we will go with CSS with basics and advanced features for web development. These tags are useful for any technology. Kindly find the attached file with the all data included.