{"id":132751,"date":"2023-03-28T19:03:57","date_gmt":"2023-03-28T19:03:57","guid":{"rendered":"https:\/\/blog.finxter.com\/?p=1250398"},"modified":"2023-03-28T19:03:57","modified_gmt":"2023-03-28T19:03:57","slug":"how-i-built-an-english-dictionary-app-with-django","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2023\/03\/28\/how-i-built-an-english-dictionary-app-with-django\/","title":{"rendered":"How I Built an English Dictionary App with Django"},"content":{"rendered":"\n<div class=\"kk-star-ratings kksr-auto kksr-align-left kksr-valign-top\" data-payload='{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;1250398&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;top&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;1&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;5\\\/5 - (1 vote)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;width&quot;:&quot;142.5&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n<div class=\"kksr-stars\">\n<div class=\"kksr-stars-inactive\">\n<div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"kksr-stars-active\" style=\"width: 142.5px;\">\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\"> 5\/5 &#8211; (1 vote) <\/div>\n<\/p><\/div>\n<p>As we all know, <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/django-developer-income-and-opportunity\/\" data-type=\"post\" data-id=\"248182\" target=\"_blank\">Django<\/a> is a Python framework used for building complex web applications. Yet, it can also be used for building simple ones. In this tutorial, I&#8217;m going to show you <img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4d6.png\" alt=\"\ud83d\udcd6\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>how I built an English dictionary app<\/strong>, a simple Django project for beginners.<\/p>\n<p>It takes time for a beginner to fully understand how Django works. But the key is consistency. If you keep building projects, you will gradually know enough to be dangerous with Django.<\/p>\n<p class=\"has-base-background-color has-background\"><strong><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f447.png\" alt=\"\ud83d\udc47\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> Scroll to the end to see the full code on GitHub!<\/strong><\/p>\n<h2>A Dictionary App? <img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4d6.png\" alt=\"\ud83d\udcd6\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/><\/h2>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1022\" height=\"681\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-408.png\" alt=\"\" class=\"wp-image-1250422\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-408.png 1022w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-408-300x200.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-408-768x512.png 768w\" sizes=\"auto, (max-width: 1022px) 100vw, 1022px\" \/><\/figure>\n<\/div>\n<p>A dictionary is an application used to get a particular word&#8217;s meaning. No matter how proficient we are in English, some words are far beyond our understanding. There are also words we may not know how to pronounce efficiently, especially those originating from a different language.<\/p>\n<p>Furthermore, we may want to know a synonym or antonym of a given word. This is where a dictionary comes in handy. With a dictionary, we get to know not only the meaning of a word but how it is pronounced, what parts of speech it belongs to, and how it is used in a sentence. Students, no doubt, appreciate the importance of having a dictionary.<\/p>\n<h2>How Will We Get The Data?<\/h2>\n<p>How will we build this dictionary app so that when users search for a particular word, they get the meaning? <\/p>\n<p>We have two options. Either we use <code>PyDictionary<\/code>, a Python module and an API that scrapes an online dictionary website or we perform the web scraping ourselves. None of these methods comes without a drawback.<\/p>\n<p class=\"has-base-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4a1.png\" alt=\"\ud83d\udca1\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>Recommended<\/strong>: <a href=\"https:\/\/blog.finxter.com\/is-web-scraping-legal\/\" data-type=\"post\" data-id=\"383048\" target=\"_blank\" rel=\"noreferrer noopener\">Is Web Scraping Legal?<\/a><\/p>\n<p>The drawback is the challenge that comes with web scraping. Many websites sometimes change their <a href=\"https:\/\/blog.finxter.com\/generating-html-documents-in-python\/\" data-type=\"post\" data-id=\"310531\" target=\"_blank\" rel=\"noreferrer noopener\">HTML<\/a> structures to prevent people or bots from accessing their content. So, if an API is not actively maintained, it can quickly become useless. This is the case with <code>PyDictionary<\/code>. Therefore, we are going to perform web scraping.<\/p>\n<p>Doing so will undoubtedly gain some valuable experience in web scraping, a very broad concept in Python programming. Still, we are at the mercy of website owners. They can change the HTML structures of their websites unexpectedly.<\/p>\n<h2>Prerequisites<\/h2>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"1022\" height=\"682\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-407.png\" alt=\"\" class=\"wp-image-1250421\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-407.png 1022w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-407-300x200.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-407-768x513.png 768w\" sizes=\"auto, (max-width: 1022px) 100vw, 1022px\" \/><\/figure>\n<\/div>\n<p>This tutorial assumes you are familiar with Python, HTML, and Bootstrap. If not, please you are required to have at least a basic knowledge before attempting this project. Basic knowledge of Django, though not required, can speed up the learning process.<\/p>\n<h2>Getting started<\/h2>\n<p>Create a new folder for this project. Then you do the following:<\/p>\n<ol>\n<li>Create a virtual environment<br \/><code>python3 -m venv .venv<\/code><\/li>\n<li>Activate the virtual environment<br \/><code>source .venv\/bin\/activate<\/code><\/li>\n<li>Install the required libraries in the virtual environment<br \/><code>pip install django tzdata requests bs4<\/code><\/li>\n<li>Create a <code>requirements.txt<\/code> file to keep a record of the module versions.<br \/><code>pip freeze &gt; requirements.txt<\/code><\/li>\n<\/ol>\n<h2>Creating Django Project and Application<\/h2>\n<p>i. Creating the project<br \/><code>django-admin startproject project .<\/code><br \/>This creates a folder called <code>project<\/code> in the current directory.<\/p>\n<p>ii. Creating the application<br \/><code>python3 manage.py startapp dictionary<\/code><br \/>The <code>manage.py<\/code> file is an executable file used to run Django commands<\/p>\n<p>iii. Applying migrations<br \/><code>python3 manage.py migrate<\/code><\/p>\n<p>iv. Checking to see if the installation was successful<br \/><code>python3 mange.py runserver<\/code><\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"607\" height=\"398\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-400.png\" alt=\"\" class=\"wp-image-1250400\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-400.png 607w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-400-300x197.png 300w\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" \/><\/figure>\n<\/div>\n<p>Once you see the above image, you are good to go.<\/p>\n<h2>Registering the App<\/h2>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"626\" height=\"939\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-406.png\" alt=\"\" class=\"wp-image-1250419\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-406.png 626w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-406-200x300.png 200w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/figure>\n<\/div>\n<ol>\n<li>In <code>settings.py<\/code> file<br \/>This step is important whenever an app is created. Navigate to the project folder. Open the <code>settings.py<\/code> file and scroll down to the <code>INSTALLED_APPS<\/code> section.<\/li>\n<\/ol>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', # custom app 'dictionary', ]<\/pre>\n<p>We have registered the app in the <code>settings.py<\/code> file. The <code>settings.py<\/code> file is used to configure the whole project.<\/p>\n<ol start=\"2\">\n<li>In the <code>urls.py<\/code> file<br \/>Open the <code>urls.py<\/code> file in the project folder and add this:<\/li>\n<\/ol>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> from django.contrib import admin from django.urls import path, include urlpatterns = [ path('admin\/', admin.site.urls), path('', include('dictionary.urls')), ]<\/pre>\n<p>We have registered the app-level URL. Let&#8217;s now create it.<\/p>\n<h2>Creating the App URL<\/h2>\n<p>This will be done inside the dictionary folder. Create a <code>urls.py<\/code> file inside the folder and add this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from django.urls import path\nfrom . import views urlpatterns = [ path('', views.homeView, name='home'), path('search', views.searchView, name='search'),\n]\n<\/pre>\n<p>&#8220;<code>from . import views<\/code>&#8221; tells Django to import the <code>views.py<\/code> file residing in the dictionary folder. <\/p>\n<p>The empty string indicates the home page URL which is <code>http:\/\/127.0.0.1:8000\/<\/code> if you are using the local server. <\/p>\n<p>This is where users will be directed when the web page is opened.<\/p>\n<p>For the <code>'search'<\/code> string, the URL will be <code>http:\/\/127.0.0.1:8000\/search<\/code>. We will be creating two functions in the <code>views.py<\/code> file as indicated.<\/p>\n<p>Notice the <code>name<\/code> argument in the <code>path()<\/code> function, this is another way to refer to the URLs in the template files without using the exact URLs.<\/p>\n<h2>Creating Views<\/h2>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"1022\" height=\"681\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-405.png\" alt=\"\" class=\"wp-image-1250417\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-405.png 1022w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-405-300x200.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-405-768x512.png 768w\" sizes=\"auto, (max-width: 1022px) 100vw, 1022px\" \/><\/figure>\n<\/div>\n<p>In this file, we are going to perform the web scraping we mentioned earlier. The first function, the <code>homeView()<\/code> is fairly simple. We just render the <code>index.html<\/code> page once the app is opened.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from django.shortcuts import render\nimport requests\nfrom bs4 import BeautifulSoup as bs # Create your views here. def homeView(request): return render(request, 'index.html')<\/pre>\n<p>But the <code>searchView()<\/code> function is a little bit complex. We want to display three things when a user searches for the meaning of a word: meaning, synonyms, and antonyms. <\/p>\n<p>So, we perform web scraping on two online dictionary websites. The first will display the meaning and the second will display the synonyms and antonyms.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def searchView(request): word = request.GET['search'] response = requests.get(f'https:\/\/dictionary.com\/browse\/{word}') response2 = requests.get(f'https:\/\/thesaurus.com\/browse\/{word}') if response: soup_1 = bs(response.text, 'html.parser') meaning = soup_1.find_all('div', {'value': '1'}) meaning_1 = meaning[0].getText() else: word = f'Sorry, we couldn\\'t find your word {word} in our records.' meaning = '' meaning_ = '' if response2: soup_2 = bs(response2.text, 'html.parser') synonyms = soup_2.find_all('a', {'class': 'css-1kg1yv8 eh475bn0'}) synonym_list = [] for i in range(len(synonyms)): synonym_list.append(synonyms[i].text.strip()) antonyms = soup_2.find_all('a', {'class': 'css-15bafsg eh475bn0'}) antonym_list = [] for i in range(len(antonyms)): antonym_list.append(antonyms[i].text.strip()) else: synonym_list = '' antonym_list = '' results = { 'word': word, 'meaning': meaning_1, 'synonyms': synonym_list, 'antonyms': antonym_list } return render(request, 'search.html', results)<\/pre>\n<p>We import the <code>requests<\/code> module which uses the <code><a href=\"https:\/\/blog.finxter.com\/python-requests-get-the-ultimate-guide\/\" data-type=\"post\" data-id=\"37837\" target=\"_blank\" rel=\"noreferrer noopener\">get()<\/a><\/code> method to scrape the contents of the two websites. <\/p>\n<p class=\"has-base-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4a1.png\" alt=\"\ud83d\udca1\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>Recommended<\/strong>: <a href=\"https:\/\/blog.finxter.com\/python-requests-library-2\/\" data-type=\"post\" data-id=\"37804\" target=\"_blank\" rel=\"noreferrer noopener\">My First Python Get Request<\/a><\/p>\n<p>The result is a cruel HTML code staring at you. <a href=\"https:\/\/blog.finxter.com\/web-scraping-with-beautifulsoup-in-python\/\" data-type=\"post\" data-id=\"17311\" target=\"_blank\" rel=\"noreferrer noopener\">BeautifulSoup<\/a>, invaluable for web scraping does its job well to pull the data out of the HTML content. This now makes it possible to search the parsed data.<\/p>\n<p>For our first search using the <code><a href=\"https:\/\/blog.finxter.com\/how-to-access-the-first-second-or-n-th-child-div-element-in-beautifulsoup\/\" data-type=\"post\" data-id=\"1230960\" target=\"_blank\" rel=\"noreferrer noopener\">find_all()<\/a><\/code> method from <code>BeautifulSoup<\/code>, we want a text wrapped in a div tag with the value 1. This is where the website owners kept the meaning of a particular word on the <em><strong>dictionary.com<\/strong><\/em> website. <\/p>\n<p>So, we use the <code>getText()<\/code> method to get the text.<\/p>\n<p>The second and third searches look similar to the first but instead of a div, we search in a tag. The words were kept in a tag to make it easy for visitors to be redirected to that particular word if they want to find the definition.<\/p>\n<p>Instead of searching for a value, we search for a CSS class. We then append the results to their respective variables. If you are new to web scraping, you may wonder how we know where those particular words reside.<\/p>\n<p>The answer is found in a browser&#8217;s developer tools, preferably <strong>Chrome Developer Tools<\/strong>. This is the reason I suggest familiarizing yourself with HTML before attempting this project.<\/p>\n<p>Finally, we render the results on the <code>search.html<\/code> page. Notice the <code>else<\/code> statements. This is run if the word is not found on the website. Let&#8217;s now create the HTML files.<\/p>\n<h2>Creating Templates<\/h2>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"1022\" height=\"826\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-404.png\" alt=\"\" class=\"wp-image-1250416\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-404.png 1022w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-404-300x242.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-404-768x621.png 768w\" sizes=\"auto, (max-width: 1022px) 100vw, 1022px\" \/><\/figure>\n<\/div>\n<p>Create a folder named <code>templates<\/code> in the current directory (not in the project or app folder). Then go to the <code>settings.py<\/code> file to let Django know of this development. In the file, import the <code>os<\/code> module. Then scroll to the TEMPLATES section and add this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates')], # add these 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, },\n]<\/pre>\n<p>Then create three files in the <code>templates<\/code> folder: <\/p>\n<ul>\n<li><code>base.html<\/code>, <\/li>\n<li><code>index.html<\/code>, and <\/li>\n<li><code>search.html<\/code>. <\/li>\n<\/ul>\n<p>The main HTML files will inherit from the <code>base.html<\/code> file. Open the <code>base.html<\/code> file and add the following:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!DOCTYPE html>\n&lt;html lang=\"en\"> &lt;head> &lt;meta charset=\"UTF-8\"> &lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"> &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"> &lt;title>Dictionary App&lt;\/title> &lt;!-- CSS only --> &lt;!-- we are getting bootstrap5 from the CDN --> &lt;link href=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.2.0-beta1\/dist\/css\/bootstrap.min.css\" rel=\"stylesheet\">\n&lt;\/head> &lt;body> &lt;div class=\"container mt-4\"> &lt;div class=\"row\"> &lt;div class=\"mt-4 p-5 bg-success text-white rounded mb-3\"> &lt;h1>Django English Dictionary&lt;\/h1> &lt;\/div> &lt;div class=\"col-md-12\"> {% block content %} &lt;!-- here we will inject the content of every page that inherits from the base page --> {% endblock %} &lt;\/div> &lt;\/div> &lt;\/div>\n&lt;\/body> &lt;\/html><\/pre>\n<p>Then, in the <code>index.html<\/code> add the following:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!-- the index page is inheriting from the base page -->\n&lt;!-- the extends tags are used for inheriting from the base page -->\n{% extends 'base.html' %} &lt;!-- the block content tags for containing content of the page -->\n{% block content %} &lt;form action=\"search\"> &lt;div class=\"input-group\"> &lt;input type=\"text\" required class=\"form-control\" name=\"search\" placeholder=\"Search your favorite word.......\"> &lt;div class=\"input-group-append\"> &lt;button class=\"btn btn-success\" type=\"submit\"> Search &lt;\/button> &lt;\/div> &lt;\/div> &lt;\/form> {% endblock %}\n<\/pre>\n<p>Recall in the <code>searchView()<\/code> function, we send a GET request to get the word input by our user from a form that bears the name <code>'search.'<\/code> Can you now see it in the form? <\/p>\n<p>There will be a problem if you use it otherwise. Finally, add the following to the <code>search.html<\/code> file.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!-- SEARCH.HTML -->\n{% extends 'base.html' %}\n{% block content %} &lt;div> &lt;h2 align=\"center\"> {{ word | title }} &lt;\/h2> &lt;br> &lt;p> &lt;b>Meaning: &lt;\/b>{{meaning}} &lt;\/p> &lt;br> &lt;p> &lt;b>Synonyms: &lt;\/b> {{ synonyms }}\n&lt;\/p>\n&lt;br>\n&lt;p> &lt;b>Antonyms: &lt;\/b> {{ antonyms }} &lt;\/p> &lt;p>&lt;a href=\"{% url 'home' %}>Home&lt;\/a>&lt;\/p> &lt;\/div>\n{% endblock %}<\/pre>\n<p>We use Django templating language to render the results of the <code>searchView()<\/code> function to the HTML. Alright, we are done. Run the server once again and you should see something similar to the images below.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"708\" height=\"398\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-401.png\" alt=\"\" class=\"wp-image-1250409\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-401.png 708w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-401-300x169.png 300w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><\/figure>\n<\/div>\n<p>That is the <code>index.html<\/code> web page. Once you search for a word, the <code>search.html<\/code> page is displayed as you can see below.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"708\" height=\"398\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-402.png\" alt=\"\" class=\"wp-image-1250411\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-402.png 708w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-402-300x169.png 300w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><\/figure>\n<\/div>\n<p>Do you see how each of the pages inherits everything in the <code>base.html<\/code> file?<\/p>\n<h2>Conclusion<\/h2>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"626\" height=\"939\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-403.png\" alt=\"\" class=\"wp-image-1250413\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-403.png 626w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/03\/image-403-200x300.png 200w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/figure>\n<\/div>\n<p>We have successfully come to the end of this project. I strongly believe you have learned a lot of things you can apply to your projects. If certain things aren\u2019t clear you may wish to read <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/how-i-created-an-url-shortener-app-using-django\/\" data-type=\"post\" data-id=\"1196939\" target=\"_blank\">other project articles<\/a>. <\/p>\n<p>The full code can be found on my GitHub page <a href=\"https:\/\/github.com\/finxter\/django_dictionary\" data-type=\"URL\" data-id=\"https:\/\/github.com\/finxter\/django_dictionary\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/finxter\/django_dictionary<\/a>. Have a wonderful day.<\/p>\n<p class=\"has-base-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4a1.png\" alt=\"\ud83d\udca1\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>Recommended<\/strong>: <a href=\"https:\/\/blog.finxter.com\/how-i-built-a-weather-app-using-three-python-frameworks\/\" data-type=\"post\" data-id=\"1250320\" target=\"_blank\" rel=\"noreferrer noopener\">How I Built a Weather App Using Three Python Frameworks<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>5\/5 &#8211; (1 vote) As we all know, Django is a Python framework used for building complex web applications. Yet, it can also be used for building simple ones. In this tutorial, I&#8217;m going to show you how I built an English dictionary app, a simple Django project for beginners. It takes time for a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[857],"tags":[73,468,528],"class_list":["post-132751","post","type-post","status-publish","format-standard","hentry","category-python-tut","tag-programming","tag-python","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/132751","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=132751"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/132751\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=132751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=132751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=132751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}