Skip to content

Commit 83548ad

Browse files
committed
add email verifier django app tutorial
1 parent 5a6148b commit 83548ad

File tree

23 files changed

+336
-0
lines changed

23 files changed

+336
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
229229
- [How to Build an Authentication System in Django](https://www.thepythoncode.com/article/authentication-system-in-django-python). ([code](web-programming/django-authentication))
230230
- [How to Make a Blog using Django in Python](https://www.thepythoncode.com/article/create-a-blog-using-django-in-python). ([code](https://github.com/chepkiruidorothy/simple-blog-site))
231231
- [How to Make a Todo App using Django in Python](https://www.thepythoncode.com/article/build-a-todo-app-with-django-in-python). ([code](https://github.com/chepkiruidorothy/todo-app-simple/tree/master))
232+
- [How to Build an Email Address Verifier App using Django in Python](https://www.thepythoncode.com/article/build-an-email-verifier-app-using-django-in-python). ([code](web-programming/webbased-emailverifier))
232233

233234
- ### [GUI Programming](https://www.thepythoncode.com/topic/gui-programming)
234235
- [How to Make a Text Editor using Tkinter in Python](https://www.thepythoncode.com/article/text-editor-using-tkinter-python). ([code](gui-programming/text-editor))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Build an Email Address Verifier App using Django in Python](https://www.thepythoncode.com/article/build-an-email-verifier-app-using-django-in-python)

web-programming/webbased-emailverifier/db.sqlite3

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webbased_emailverifier.settings')
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == '__main__':
22+
main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
django
2+
email-validator
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
$ python -m venv project
2+
$ .\project\Scripts\activate
3+
$ pip install -r requirements.txt
4+
$ django-admin startproject webbased_emailverifier
5+
$ cd webbased_emailverifier\
6+
$ python manage.py startapp verifier
7+
$ python manage.py runserver

web-programming/webbased-emailverifier/verifier/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class VerifierConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'verifier'

web-programming/webbased-emailverifier/verifier/migrations/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Web-based Email Verifier</title>
8+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
9+
</head>
10+
<body style="background-color:rgb(248, 244, 244)">
11+
12+
{% block content %}
13+
14+
{% endblock %}
15+
16+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
17+
18+
</body>
19+
</html>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!-- extends is for inheriting from the base.html -->
2+
{% extends 'verifier/base.html' %}
3+
4+
5+
6+
{% block content %}
7+
<div class="row justify-content-center my-5">
8+
9+
<div class="col-md-5 mt-4">
10+
11+
<div class="card">
12+
<h3 class="card-header">Email Verifier</h3>
13+
14+
<div class="card-body">
15+
16+
<form action="." method="POST">
17+
{% csrf_token %}
18+
<div class="input-group">
19+
<input type="text" required class="form-control" name="email-address" placeholder="Enter an email address to verify it">
20+
<div class="input-group-append">
21+
<button class="btn btn-primary fw-bold" type="submit">
22+
Verify
23+
</button>
24+
</div>
25+
</div>
26+
</form>
27+
28+
<hr>
29+
30+
{% if messages %}
31+
{% for message in messages %}
32+
{% if message.tags == 'success' %}
33+
<div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
34+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check-circle-fill" viewBox="0 0 16 16">
35+
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"/>
36+
</svg> {{ email }} is a valid email address!!!!!
37+
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
38+
</div>
39+
{% elif message.tags == 'warning' %}
40+
<div class="alert alert-danger alert-dismissible fade show" role="alert">
41+
{{ email }}
42+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-exclamation-triangle-fill" viewBox="0 0 16 16">
43+
<path d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"/>
44+
</svg> {{ message }}
45+
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
46+
</div>
47+
{% endif %}
48+
{% endfor %}
49+
{% endif %}
50+
51+
</div>
52+
53+
</div>
54+
55+
</div>
56+
57+
</div>
58+
</div>
59+
{% endblock %}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# from the current folder import views
2+
from . import views
3+
# importing path from django.urls
4+
from django.urls import path
5+
6+
# this is the list of the app's views
7+
# if the app has several views then it will have several paths
8+
urlpatterns = [
9+
path('', views.index, name='home'),
10+
]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from django.shortcuts import render
2+
# this displays flash messages or notifications
3+
from django.contrib import messages
4+
# importing validate_email and EmailNotValidError
5+
from email_validator import validate_email, EmailNotValidError
6+
7+
8+
# Create your views here.
9+
def index(request):
10+
# checking if the method is POST
11+
if request.method == 'POST':
12+
# getting the email from the form input
13+
email = request.POST.get('email-address')
14+
# this is the context
15+
context = {
16+
'email': email
17+
}
18+
# the try statement for verify/validating the email
19+
try:
20+
# validating the actual email address using the validate_email function
21+
email_object = validate_email(email)
22+
# creating the message and storing it
23+
messages.success(request, f'{email} is a valid email address!!')
24+
# rendering the results to the index page
25+
return render(request, 'verifier/index.html', context)
26+
# the except statement will capture EmailNotValidError error
27+
except EmailNotValidError as e:
28+
# creating the message and storing it
29+
messages.warning(request, f'{e}')
30+
# rendering the error to the index page
31+
return render(request, 'verifier/index.html', context)
32+
33+
# this will render when there is no request POST or after every POST request
34+
return render(request, 'verifier/index.html')

web-programming/webbased-emailverifier/webbased_emailverifier/__init__.py

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for webbased_emailverifier project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webbased_emailverifier.settings')
15+
16+
application = get_asgi_application()
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
"""
2+
Django settings for webbased_emailverifier project.
3+
4+
Generated by 'django-admin startproject' using Django 4.1.2.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/4.1/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
15+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16+
BASE_DIR = Path(__file__).resolve().parent.parent
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = 'django-insecure-!whsb9fn*)d)zj(o78=y8y6=7^uh09!w&(_zfdo%wq$m%27+8h'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
30+
31+
# Application definition
32+
INSTALLED_APPS = [
33+
'django.contrib.admin',
34+
'django.contrib.auth',
35+
'django.contrib.contenttypes',
36+
'django.contrib.sessions',
37+
'django.contrib.messages',
38+
'django.contrib.staticfiles',
39+
# the newly created application
40+
'verifier',
41+
]
42+
43+
MIDDLEWARE = [
44+
'django.middleware.security.SecurityMiddleware',
45+
'django.contrib.sessions.middleware.SessionMiddleware',
46+
'django.middleware.common.CommonMiddleware',
47+
'django.middleware.csrf.CsrfViewMiddleware',
48+
'django.contrib.auth.middleware.AuthenticationMiddleware',
49+
'django.contrib.messages.middleware.MessageMiddleware',
50+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
51+
]
52+
53+
ROOT_URLCONF = 'webbased_emailverifier.urls'
54+
55+
TEMPLATES = [
56+
{
57+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
58+
'DIRS': [],
59+
'APP_DIRS': True,
60+
'OPTIONS': {
61+
'context_processors': [
62+
'django.template.context_processors.debug',
63+
'django.template.context_processors.request',
64+
'django.contrib.auth.context_processors.auth',
65+
'django.contrib.messages.context_processors.messages',
66+
],
67+
},
68+
},
69+
]
70+
71+
WSGI_APPLICATION = 'webbased_emailverifier.wsgi.application'
72+
73+
74+
# Database
75+
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
76+
77+
DATABASES = {
78+
'default': {
79+
'ENGINE': 'django.db.backends.sqlite3',
80+
'NAME': BASE_DIR / 'db.sqlite3',
81+
}
82+
}
83+
84+
85+
# Password validation
86+
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
87+
88+
AUTH_PASSWORD_VALIDATORS = [
89+
{
90+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
91+
},
92+
{
93+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
94+
},
95+
{
96+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
97+
},
98+
{
99+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
100+
},
101+
]
102+
103+
104+
# Internationalization
105+
# https://docs.djangoproject.com/en/4.1/topics/i18n/
106+
107+
LANGUAGE_CODE = 'en-us'
108+
109+
TIME_ZONE = 'UTC'
110+
111+
USE_I18N = True
112+
113+
USE_TZ = True
114+
115+
116+
# Static files (CSS, JavaScript, Images)
117+
# https://docs.djangoproject.com/en/4.1/howto/static-files/
118+
119+
STATIC_URL = 'static/'
120+
121+
# Default primary key field type
122+
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
123+
124+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
from django.contrib import admin
3+
from django.urls import path, include
4+
5+
urlpatterns = [
6+
# this points to admin.site urls
7+
path('admin/', admin.site.urls),
8+
# this points to verifier urls
9+
path('', include('verifier.urls')),
10+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for webbased_emailverifier project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webbased_emailverifier.settings')
15+
16+
application = get_wsgi_application()

0 commit comments

Comments
 (0)