Python Webbrowser - Create Login and registration form with HTML CSS

Published February 07, 2022

In this python example, we'll create a simple registration and login form using HTML and CSS. We will use the webbrowser Python module to open our login and registration forms in a computer web browser. Here is a description of how you can create a login and registration form using HTML, CSS, and the Python webbrowser module.

 

Step 1: As a first step, we need to install our web browser module. To do so, execute the following command in your IDE terminal.

 

pip install pycopy-webbrowser

Once the module has been installed successfully, paste the following code into the application to import it.

import webbrowser

We can now begin working on HTML and CSS

 

Step 2: Use the code below to create HTML login and registration forms

file = open("form.html", "w")

html_code = """<!DOCTYPE html>

<html>

<head>

<title>Log In & Registration form</title>

<link rel="stylesheet", href="style.css">

</head>

<body>

<form action="login_page.php" method="post">

<h3> Login Form</h3>

<div class="container">

<label for="uname"><b>Email:</b></label>

<input type="email" placeholder="Enter Email" name="email" required>

<br>

<label for="pswdd"><b>Password:</b></label>

<input type="password" placeholder="Enter password" name="passwd" required>

<br>

<label>

<input type="checkbox" name="remember"> Keep me logged in

</label>

<br>

<button type="submit">Login</button>

<br>

<span class="pswd">Forgot <a href="#">password?</a></span>

</div>

</form>

<br>

<br>

<form action="register_page.php" method="post">

<h3> Registration Form</h3>

<div class="container">

<label for="uname"><b>Email:</b></label>

<input type="email" placeholder="Enter Email" name="email" required>

<br>

<label for="pswdd"><b>Password:</b></label>

<input type="password" placeholder="Enter password" name="passwd" required>

<br>

<label for="pswdd"><b> Confirm Password:</b></label>

<input type="password" placeholder="Confirm password" name="passwd" required>

<br>

<br>

<span class="pswd">Already Registered <a href="#">Log in here?</a></span>

</div>

</form>

</body>

</html>"""

 

Step 3: Let's now make our page look more visually appealing. To do so, paste the following CSS code.

 

file1 = open("style.css", "w")

css_code = """

form {

border: 3px solid black;

}

input[type=email], input[type=password] {

width: 40%;

padding: 12px 20px;

margin: 8px 0;

display: inline-block;

border: 1px solid #ccc;

box-sizing: border-box;

}

h3{

text-align:center;

float:center;

font-weight:bold;

font-color: blue;

}

button {

background-color: red;

color: white;

padding: 14px 20px;

margin: 8px 0;

border: none;

cursor: pointer;

width: 18%;

}

button:hover {

opacity: 0.8;

}

.container {

text-align: center;

margin: 24px 0 12px 0;

}

img.logo {

width: 22%;

border-radius: 50%;

}

.container {

padding: 16px;

}

}

"""

 

Step 4: Close files and open our application in a new tab in the web browser

file.write(html_code)

file1.write(css_code)

file.close()

file1.close()

webbrowser.open_new_tab("form.html")

 

Step 5:  Run the application. Now everything works perfectly. The login and registration forms appear in the web browser.

 

Python Login Registration pages - Python webmodule

 

Conclusion: Python login registration pages with python webmodule

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

457 Views