Python Django Random password generator from scratch.


Django

Django is one of the most popular frameworks used to create or build web applications with python. Without further ado let's create a password generator in django with user signup, login and logout option and a result page to show that user has already logged in.

Pre-requisite

Make sure you have the latest version of python, Go with any IDE you are familiar with.

Installing Virtual Environment and Django Project

Open your terminal and run these commands to Install required Packages:
1. pip install pipenv
2. cd (folder name) - get into the folder where you want your django project to be present, then run
3. pipenv install django
4. pipenv shell
5. django-admin startproject (project name)
6. pipenv --venv - copy and paste this path with python interpreter path and add (\bin\python) to it.
7. python manage.py startapp (app name) - whenever an app is started, the app name has to be mentioned in Settings.py under Installed Apps.
8. python manage.py createsuperuser - which is to get login details for admin(username, email, password and confirm password) now Admin module can be logged in. Note: By default Django provides Admin module and its features.
9. python manage.py makemigrations
10. python manage.py migrate
11. python manage.py runserver - click the url shown in terminal use ctrl + click (now you can see the page with successfully installed in your web browser)

Project Folder

After adding some files and folders your directory looks something like this

Folder and Files to be added in your app:

1. template folder and required html files.
2. forms.py - to use default form provided by django.
3. decorators.py - to authenticate whether the user is already logged in or not.
4. urls.py - to redirect pages according to url.

Template

Firstly let me explain how a web application works. Redirecting from one page to another in a site won't change the template every time only the body of the content is going to change, similarly we are also going to use the same template for every page.



Template contains only a basic responsive main-menu and it's a simple one created using html,css and js. Instead of using Internal Css and Js you also can use external files and you also can go with bootstrap instead of using css and js in django.


Random Password Generator

A simple html form that contains a button to generate a random password, once the password is generated that will be displayed in the same page within a textbox and the generated password is copied to the user's clipboard done by using python's pandas library. This html form has to be linked with the above template.

Css

This is going to be the Cascading style sheet for all of our html files except template.



home.html



urls.py

Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))

You can see the above instruction in the auto created urls.py file. Add another URL configuration using include as mentioned above:



urls.py (app)



views.py (app)



Password comprises English Alphabets, Numbers(0 to 9), Symbols, Tamil Numbers and some Tamil letters. Once the Random Password is generated the password is copied to the user's clipboard with the help of pandas library before returning the rendered HttpResponse to the user.

If anyone wants me to continue login, signup, logout and how to access Admin panel in django options for this password generator let me know through comment section guys. Anyway thanks for reading.

Here is the link for Mark Sheet Result page using Html and Css.

Here is the link for Draw Scale using Java Paint

How to read multiple Integer input in a single line ? and Android Studio Getting Thumbnail to a Video using Glide in a Recyclerview

Image Processing in Java - Read, Write, to Black and White, to Gray, to Negative and Bit-Plane Slicing.

Write a Java code to check whether a number is prime or not with n root time complexity.

Here is the link for Google KickStart Round F 2021 Trash Bins Problem.

0 Comments