<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Beginner Developers - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Beginner Developers - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 24 Nov 2026 09:33:48 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/beginners/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Find and Fix Common Technical SEO Issues on Your Website ]]>
                </title>
                <description>
                    <![CDATA[ Let's say you've built a website. You've invested in the design, bought a domain, and so on. But a website isn't only what you see on the screen. A lot happens behind the scenes. You have to understan ]]>
                </description>
                <link>https://www.freecodecamp.org/news/fix-common-technical-seo-issues/</link>
                <guid isPermaLink="false">6aea2f4db1deb69c0283692a</guid>
                
                    <category>
                        <![CDATA[ SEO ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Beginner Developers ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Saar Twito ]]>
                </dc:creator>
                <pubDate>Tue, 03 Nov 2026 19:00:29 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/8d158690-136a-44a2-aa34-e24be77e004c.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Let's say you've built a website. You've invested in the design, bought a domain, and so on. But a website isn't only what you see on the screen. A lot happens behind the scenes. You have to understand how the internet works, as well as how Search Engine Optimization (SEO) works.</p>
<p>Speed is a key part of it, too. A slow site can have very weak SEO, because most people won't spend much time waiting for a page to load, especially these days.</p>
<p>Site speed is a well-known topic with many problems of its own to consider, like Largest Contentful Paint (LCP), Cumulative Layout Shift (CLS), and server speed. But I'll leave those for another article.</p>
<p>This one is about the problems that stop search engines from reaching and reading your pages.</p>
<p>In my opinion, technical SEO is much harder to apply than regular SEO, which focuses on content and keywords. The technical side usually requires a developer's knowledge, and might need some changes that can feel a bit uncomfortable if you don't have a technical background.</p>
<p>A technical problem can stay unnoticed for months, because you usually don't see it. It's not a design problem. You only find it when you run specific checks, for example with <a href="https://pagespeed.web.dev/">Google PageSpeed Insights</a>.</p>
<p>In this tutorial, you'll find and fix the most common ones on a small practice site. I didn't want to take a real website and shame its owners, so I built a practice site with the problems already in it.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><a href="#heading-prerequisites">Prerequisites</a></li>
<li><a href="#heading-what-is-technical-seo">What Is Technical SEO?</a></li>
<li><a href="#heading-how-common-are-these-problems-on-real-websites">How Common Are These Problems on Real Websites?</a></li>
<li><a href="#heading-how-to-set-up-the-practice-site">How to Set Up the Practice Site</a></li>
<li><a href="#heading-how-to-check-a-pages-http-status-code">How to Check a Page's HTTP Status Code</a><ul>
<li><a href="#heading-what-is-a-soft-404">What Is a Soft 404?</a></li>
</ul>
</li>
<li><a href="#heading-how-to-find-and-fix-redirect-chains">How to Find and Fix Redirect Chains</a></li>
<li><a href="#heading-how-to-make-sure-robotstxt-isnt-blocking-important-pages">How to Make Sure robots.txt Isn't Blocking Important Pages</a></li>
<li><a href="#heading-how-to-find-an-accidental-noindex">How to Find an Accidental noindex</a><ul>
<li><a href="#heading-how-to-check-the-robots-meta-tag">How to Check the Robots Meta Tag</a></li>
<li><a href="#heading-how-to-check-the-x-robots-tag-header">How to Check the X-Robots-Tag Header</a></li>
</ul>
</li>
<li><a href="#heading-how-to-use-canonical-tags-correctly">How to Use Canonical Tags Correctly</a></li>
<li><a href="#heading-how-to-fix-missing-and-duplicate-titles-and-meta-descriptions">How to Fix Missing and Duplicate Titles and Meta Descriptions</a></li>
<li><a href="#heading-how-to-make-your-links-crawlable">How to Make Your Links Crawlable</a></li>
<li><a href="#heading-how-to-check-whether-your-content-needs-javascript-to-appear">How to Check Whether Your Content Needs JavaScript to Appear</a></li>
<li><a href="#heading-can-you-check-a-page-in-five-minutes">Can You Check a Page in Five Minutes?</a></li>
<li><a href="#heading-conclusion">Conclusion</a></li>
</ul>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>You don't need to be an experienced programmer to follow along. You'll need:</p>
<ul>
<li>A web browser, such as Chrome, Firefox, Edge or Safari. In Safari, first turn on <strong>Show features for web developers</strong> under Settings &gt; Advanced.</li>
<li>A terminal: Terminal on macOS, PowerShell on Windows, or any terminal on Linux.</li>
<li><code>curl</code>, a small program that downloads web pages. It comes with macOS, most Linux distributions, and Windows 10 (version 1803 and later) and Windows 11.</li>
<li><a href="https://nodejs.org/">Node.js</a>, to run the practice site. The code was tested with Node.js 26.8 and curl 8.7.</li>
</ul>
<p>On Windows PowerShell, type <code>curl.exe</code> instead of <code>curl</code>, because there <code>curl</code> is a shortcut to a <a href="https://learn.microsoft.com/en-us/windows/curl/">different command</a>. Replace <code>| grep -i "text"</code> with <code>| Select-String "text"</code>, and <code>/dev/null</code> with <code>NUL</code>.</p>
<h2 id="heading-what-is-technical-seo">What Is Technical SEO?</h2>
<p>Google has programs called crawlers. They search the internet all the time for new websites and new pages. When Google discovers a new address, it may crawl the page and process what's on it (the text, images, and videos).</p>
<p>If Google decides the page is worth indexing, it may add it to a very big database of web pages, called the index. Google can then consider the pages in its index for its search results, when they're relevant to what someone searches for. Google's guide to <a href="https://developers.google.com/search/docs/fundamentals/how-search-works">how Search works</a> calls these three steps crawling, indexing, and serving.</p>
<p>So crawling doesn't guarantee indexing, and indexing doesn't guarantee a place in the results. The same guide says Google doesn't guarantee any of the three stages, even for a page that follows all of its rules.</p>
<p>Fixing technical problems won't necessarily make your site rank first on Google. But it does strengthen your chances of ranking higher, because every problem you fix makes your site better.</p>
<p>Technical SEO has to come together with regular SEO, like keywords, backlinks, engagement on social media, and so on.</p>
<h2 id="heading-how-common-are-these-problems-on-real-websites">How Common Are These Problems on Real Websites?</h2>
<p>The numbers below come from audits run with the site-auditing tool I build. Each website counts once, using its first audit, and this data comes from October 25th.</p>
<p>Crawls check many pages on one site (a median of 10 pages here). Single-page audits check one page, usually the home page.</p>
<table>
<thead>
<tr>
<th>Problem</th>
<th>How often</th>
<th>Sample</th>
</tr>
</thead>
<tbody><tr>
<td>At least one page with no canonical tag</td>
<td>64.2% of sites</td>
<td>53 crawled sites, Aug 2025 to Oct 2026</td>
</tr>
<tr>
<td>Two or more pages with exactly the same title</td>
<td>61.8% of sites</td>
<td>34 crawled sites with two or more pages that loaded</td>
</tr>
<tr>
<td>At least one page with no meta description</td>
<td>49.1% of sites</td>
<td>53 crawled sites</td>
</tr>
<tr>
<td>At least one link leading to a page that returns 404</td>
<td>18.9% of sites</td>
<td>53 crawled sites</td>
</tr>
<tr>
<td>Page built mostly with JavaScript</td>
<td>17.7% of pages</td>
<td>277 single-page audits, May to Oct 2026</td>
</tr>
<tr>
<td>At least one page with no title</td>
<td>13.2% of sites</td>
<td>53 crawled sites</td>
</tr>
<tr>
<td>A link that search engines may not be able to follow</td>
<td>8.3% of pages</td>
<td>278 single-page audits</td>
</tr>
<tr>
<td>A robots.txt file with errors, or one that failed to load</td>
<td>7.9% of sites</td>
<td>252 single-page audits, Jul to Oct 2026</td>
</tr>
<tr>
<td>Page blocked by noindex or by robots.txt</td>
<td>4.8% of pages</td>
<td>251 single-page audits, Jul to Oct 2026</td>
</tr>
</tbody></table>
<p>These are all technical problems, but they don't all weigh the same. Missing canonical tags are at the top, but Google doesn't require a canonical tag, so a page without one isn't broken by itself. It matters when the same or very similar content is reachable at more than one URL, as you'll see in the canonical section.</p>
<p>Duplicate titles are something I had myself: when you write code, it's easy to miss things like that. That's why there are tools that check for these problems.</p>
<p>Let's go over each issue in the table to make sure they're all clear:</p>
<ul>
<li><strong>Missing canonical tag:</strong> a canonical tag is basically one of the many tags you put in the <code>&lt;head&gt;</code> of your HTML. When two or three pages have pretty much the same content, it tells search engines like Google which URL is the original, main version, the one you prefer to get indexed. It's not required, though: without it, Google picks the main version itself, so it matters mostly for pages that have duplicates.</li>
<li><strong>Duplicate titles:</strong> it's really easy to end up with the same title on two pages. You don't want a duplicated title because it's not helpful and can confuse Google. Each page should say what it's about.</li>
<li><strong>Missing meta description:</strong> this one is really important, because it helps search engines as well as AI tools like ChatGPT. The meta description is there to explain very briefly what the page is about and what it's for. If you go to Google and search for a website, you'll see it under the actual link to the site.</li>
<li><strong>A link to a 404 page:</strong> this basically means you have a broken link (maybe a link you probably don't use anymore) to a page that isn't there. So there's no reason for it to lead to something that doesn't exist. Use it to lead to something similar, or to something that does exist, so your links remain relevant.</li>
<li><strong>A page built mostly with JavaScript:</strong> Google can run JavaScript, so this alone doesn't keep a page out of Google. But the content appears only after the JavaScript loads and runs, which is slower for visitors and one more step that can fail, and not every crawler runs JS. That's why I prefer <a href="https://www.freecodecamp.org/news/server-side-rendering-in-next-js-for-improved-seo/">server-side rendering</a> for the content that matters most.</li>
<li><strong>A link search engines can't follow:</strong> this isn't a huge deal, and it really depends where the link goes. But say I wrote a really nice article and I want it to help me rank on Google. If search engines can't follow the link to it, then you invested all this time and energy in this article that relatively few people will likely see.</li>
<li><strong>Errors in robots.txt:</strong> robots.txt basically helps you talk to search engines. If there are errors in this file, you might stop search engines from crawling pages you do want in search results.</li>
<li><strong>A page blocked by noindex or robots.txt:</strong> these are two different things. A <code>noindex</code> rule asks search engines to keep a page out of their results, while a robots.txt rule only stops them from crawling it. You'll learn more about both, and why the difference matters, later in this tutorial.</li>
</ul>
<p>Soft 404s, redirect chains, and wrong canonical tags aren't in the table, because the audits don't record them.</p>
<h2 id="heading-how-to-set-up-the-practice-site">How to Set Up the Practice Site</h2>
<p>The practice site is a tiny website for a made-up shoe store called Acme Shoes. Every page on it has one problem built in. You don't need to understand every line of the code.</p>
<p>Create a new folder, add a file called <code>server.js</code>, and paste in this code:</p>
<pre><code class="language-javascript">// server.js: a tiny practice site with common technical SEO problems built in
const http = require('node:http');

const PORT = 8080;
const BASE = 'http://localhost:' + PORT;

// Builds a simple HTML page. Leave out a field to leave that tag out.
function page({ title, description, canonical, robots, body, script }) {
  return [
    '&lt;!doctype html&gt;',
    '&lt;html lang="en"&gt;',
    '&lt;head&gt;',
    '&lt;meta charset="utf-8"&gt;',
    title &amp;&amp; '&lt;title&gt;' + title + '&lt;/title&gt;',
    description &amp;&amp; '&lt;meta name="description" content="' + description + '"&gt;',
    canonical &amp;&amp; '&lt;link rel="canonical" href="' + BASE + canonical + '"&gt;',
    robots &amp;&amp; '&lt;meta name="robots" content="' + robots + '"&gt;',
    '&lt;/head&gt;',
    '&lt;body&gt;',
    body,
    script &amp;&amp; '&lt;script&gt;' + script + '&lt;/script&gt;',
    '&lt;/body&gt;',
    '&lt;/html&gt;',
  ]
    .filter(Boolean)
    .join('\n');
}

const routes = {
  '/': {
    html: page({
      title: 'Acme Shoes: Running Shoes for Every Runner',
      description: 'Lightweight running shoes for road and trail, with free returns.',
      canonical: '/',
      body: [
        '&lt;h1&gt;Acme Shoes&lt;/h1&gt;',
        '&lt;a href="/products/blue-runner"&gt;Blue Runner&lt;/a&gt;',
        '&lt;span onclick="location.href=\'/sale\'"&gt;Summer sale&lt;/span&gt;',
      ].join('\n'),
    }),
  },
  // Problem: a vague title and no meta description
  '/products/blue-runner': {
    html: page({
      title: 'Acme Shoes',
      canonical: '/products/blue-runner',
      body: '&lt;h1&gt;Blue Runner&lt;/h1&gt;',
    }),
  },
  // Problem: a missing product that still answers "200 OK" (a soft 404)
  '/products/red-runner': {
    html: page({
      title: 'Acme Shoes',
      body: '&lt;h1&gt;Sorry, that product could not be found.&lt;/h1&gt;',
    }),
  },
  // Problem: a redirect chain, /old-sale -&gt; /sale-2025 -&gt; /sale
  '/old-sale': { redirect: '/sale-2025' },
  '/sale-2025': { redirect: '/sale' },
  '/sale': {
    html: page({
      title: 'Summer Sale: Up to 40% Off Running Shoes | Acme Shoes',
      description: "Save up to 40% on last season's running shoes until August 31.",
      canonical: '/sale',
      body: '&lt;h1&gt;Summer sale&lt;/h1&gt;',
    }),
  },
  // Problem: a noindex header nobody can see in the page itself
  '/about': {
    headers: { 'X-Robots-Tag': 'noindex' },
    html: page({
      title: 'About Acme Shoes',
      description: 'How a two-person workshop became a running shoe brand.',
      canonical: '/about',
      body: '&lt;h1&gt;About us&lt;/h1&gt;',
    }),
  },
  // Problem: a canonical tag that points to the home page
  '/blog/choosing-trail-shoes': {
    html: page({
      title: 'How to Choose Trail Running Shoes | Acme Shoes',
      description: 'Grip, drop and fit: what to look for in a trail running shoe.',
      canonical: '/',
      body: '&lt;h1&gt;How to choose trail running shoes&lt;/h1&gt;',
    }),
  },
  // Problem: the content only exists after JavaScript runs
  '/catalog': {
    html: page({
      title: 'All Running Shoes | Acme Shoes',
      description: 'Browse every Acme running shoe.',
      canonical: '/catalog',
      body: '&lt;div id="app"&gt;Loading...&lt;/div&gt;',
      script:
        "fetch('/api/products').then((r) =&gt; r.json()).then((products) =&gt; {" +
        "document.getElementById('app').innerHTML = products.map((p) =&gt; '&lt;h2&gt;' + p + '&lt;/h2&gt;').join('');" +
        '});',
    }),
  },
  '/api/products': {
    type: 'application/json',
    html: JSON.stringify(['Blue Runner', 'Trail Grip 2', 'City Glide']),
  },
  // Problem: "Disallow: /blog" blocks every path that starts with /blog
  '/robots.txt': {
    type: 'text/plain',
    html: 'User-agent: *\nDisallow: /blog\n',
  },
};

http
  .createServer((req, res) =&gt; {
    const path = new URL(req.url, BASE).pathname;
    const route = routes[path];

    if (!route) {
      res.writeHead(404, { 'Content-Type': 'text/html; charset=utf-8' });
      return res.end(page({ title: 'Page not found', body: '&lt;h1&gt;Page not found&lt;/h1&gt;' }));
    }
    if (route.redirect) {
      res.writeHead(301, { Location: route.redirect });
      return res.end();
    }
    res.writeHead(200, {
      'Content-Type': (route.type || 'text/html') + '; charset=utf-8',
      ...route.headers,
    });
    res.end(route.html);
  })
  .listen(PORT, () =&gt; console.log('Practice site running at ' + BASE));
</code></pre>
<p>Each key in <code>routes</code> is a page address. The comments that start with <code>Problem:</code> say what's wrong with each page.</p>
<p>Start the server from the same folder:</p>
<pre><code class="language-bash">node server.js
</code></pre>
<p>You should see:</p>
<pre><code class="language-text">Practice site running at http://localhost:8080
</code></pre>
<p>Leave the server running and open a second terminal for the commands below. When you change <code>server.js</code>, stop the server with Ctrl+C and start it again.</p>
<h2 id="heading-how-to-check-a-pages-http-status-code">How to Check a Page's HTTP Status Code</h2>
<p>I remember when I started building websites, I built all kinds of small things. I'm a full stack developer, and I kept trying experiments.</p>
<p>Once I had a problem on the server side and saw in the Network tab that it returned a 500 error. Another time I removed a page on purpose, because I wanted to see if I'd get a 404 or other problems. If you just play around with the site you're building, you'll learn a lot from the results.</p>
<p>HTTP status codes are the first thing a search engine reads. They're the server's way of talking to the client, such as your browser. The codes are split into five ranges: 1xx, 2xx, 3xx, 4xx, and 5xx. A 5xx code is a server problem, for example, and a 4xx code is a client-side problem.</p>
<p>404 is the most common error. It means a page on the site wasn't found. You see 404s all the time, and the fix is typically just to maintain your site and your links.</p>
<p>The codes you'll see in this tutorial are:</p>
<ul>
<li><code>200 OK</code>: here's the page.</li>
<li><code>301 Moved Permanently</code>: the page lives at another address.</li>
<li><code>404 Not Found</code>: there's no page here.</li>
</ul>
<p>Google doesn't index URLs that return a <code>4xx</code> code, according to its documentation on <a href="https://developers.google.com/search/docs/crawling-indexing/http-network-errors">HTTP status codes</a>.</p>
<p>To see the status code of the practice site's home page, use <code>-I</code>, which shows only the headers, and <code>-s</code>, which hides curl's progress meter:</p>
<pre><code class="language-bash">curl -sI http://localhost:8080/
</code></pre>
<pre><code class="language-text">HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Date: Sun, 25 Oct 2026 17:42:53 GMT
Connection: keep-alive
Keep-Alive: timeout=5
</code></pre>
<p>Now ask for an address that isn't in <code>routes</code>, to see what a correct 404 looks like:</p>
<pre><code class="language-bash">curl -sI http://localhost:8080/products/does-not-exist
</code></pre>
<pre><code class="language-text">HTTP/1.1 404 Not Found
Content-Type: text/html; charset=utf-8
Date: Sun, 25 Oct 2026 17:42:53 GMT
Connection: keep-alive
Keep-Alive: timeout=5
</code></pre>
<p>In the browser, open the developer tools (F12, or Cmd+Option+I on a Mac), go to the <strong>Network</strong> tab, and reload. The <strong>Status</strong> column shows the code.</p>
<h3 id="heading-what-is-a-soft-404">What Is a Soft 404?</h3>
<p>Check a product the store no longer sells:</p>
<pre><code class="language-bash">curl -sI http://localhost:8080/products/red-runner
</code></pre>
<pre><code class="language-text">HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Date: Sun, 25 Oct 2026 17:42:53 GMT
Connection: keep-alive
Keep-Alive: timeout=5
</code></pre>
<p>In the browser, the same page says "Sorry, that product could not be found."</p>
<p>A soft 404 is basically a "page not found", but the server still answers <code>200</code>. It confuses Google, because the address is still there, but what's on it isn't current anymore.</p>
<p>To fix it, make missing pages return a real <code>404</code>, which is what <a href="https://support.google.com/webmasters/answer/7440203">Google recommends</a>. In the practice site, delete the <code>'/products/red-runner'</code> entry from <code>routes</code>. The server then answers <code>404</code>.</p>
<p>Broken links lead to the same dead end. In the data, 18.9% of the 53 crawled sites had at least one link to a page that returned <code>404</code>.</p>
<p>So don't leave links that lead to something that doesn't exist. Update them to lead to something similar, or to something that does exist.</p>
<p>If the page moved, add a <code>301</code> redirect from the old address to the new one. A <code>404</code> is the right answer only for a page that's really gone.</p>
<h2 id="heading-how-to-find-and-fix-redirect-chains">How to Find and Fix Redirect Chains</h2>
<p>A redirect is basically when you want to send one URL (perhaps one that no longer exists) to another URL (that does exist). You might set up a redirect if, for example, you change your domain from <code>example-x.com</code> to <code>example-y.com</code>. You'll want everyone who types <code>example-x.com</code> to be redirected to <code>example-y.com</code> automatically.</p>
<p>Redirects are fine, and they can be quite helpful when used properly. A <code>301</code> means the page moved for good. A <code>302</code> means the move is temporary. Google's documentation on <a href="https://developers.google.com/search/docs/crawling-indexing/301-redirects">redirects</a> explains how it treats each one, and its crawlers <a href="https://developers.google.com/search/docs/crawling-indexing/http-network-errors">follow up to 10 redirect hops</a>.</p>
<p>But a redirect chain happens when an old address, such as a domain you used in the past, redirects to a new one, and then that one redirects again, and again...you get the picture. A few redirects aren't a big deal, but five, six, or seven can be a real problem.</p>
<p>The first command below shows every step of the chain. The second gives you a one-line summary.</p>
<p>Add <code>-L</code> so curl follows the redirects:</p>
<pre><code class="language-bash">curl -sIL http://localhost:8080/old-sale
</code></pre>
<pre><code class="language-text">HTTP/1.1 301 Moved Permanently
Location: /sale-2025
Date: Sun, 25 Oct 2026 17:42:53 GMT
Connection: keep-alive
Keep-Alive: timeout=5

HTTP/1.1 301 Moved Permanently
Location: /sale
Date: Sun, 25 Oct 2026 17:42:53 GMT
Connection: keep-alive
Keep-Alive: timeout=5

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Date: Sun, 25 Oct 2026 17:42:53 GMT
Connection: keep-alive
Keep-Alive: timeout=5
</code></pre>
<p><code>/old-sale</code> goes to <code>/sale-2025</code>, which goes to <code>/sale</code>. For a one-line summary:</p>
<pre><code class="language-bash">curl -sL -o /dev/null -w "%{num_redirects} redirects, ended at %{url_effective}\n" http://localhost:8080/old-sale
</code></pre>
<pre><code class="language-text">2 redirects, ended at http://localhost:8080/sale
</code></pre>
<p><code>-o /dev/null</code> tells curl to write the page's HTML nowhere, so it doesn't fill your terminal and only the summary line is printed. <code>-w</code> sets what that summary line says.</p>
<p>To fix it, point the old/original address straight at the final page:</p>
<pre><code class="language-javascript">'/old-sale': { redirect: '/sale' },
</code></pre>
<p>Restart the server and run the summary again. It now says <code>1 redirects, ended at http://localhost:8080/sale</code>.</p>
<h2 id="heading-how-to-make-sure-robotstxt-isnt-blocking-important-pages">How to Make Sure robots.txt Isn't Blocking Important Pages</h2>
<p>robots.txt is the site's way of telling search engines like Google (and their crawlers) what they're allowed to explore and where they have access.</p>
<p>Look at the practice site's file:</p>
<pre><code class="language-bash">curl -s http://localhost:8080/robots.txt
</code></pre>
<pre><code class="language-text">User-agent: *
Disallow: /blog
</code></pre>
<p><code>Disallow: /blog</code> is dangerous because it stops crawlers from reading every path that starts with <code>/blog</code>. And usually, your articles are what promote your site the most.</p>
<p>Google's <a href="https://developers.google.com/search/docs/crawling-indexing/robots/robots_txt">robots.txt documentation</a> gives the same kind of example: <code>Disallow: /fish</code> also blocks <code>/fish.html</code> and <code>/fishheads</code>.</p>
<p>To fix it, make the rule match only what you meant to block, for example a folder of drafts:</p>
<pre><code class="language-text">User-agent: *
Disallow: /blog-drafts/
</code></pre>
<p>In the practice site, change the <code>html</code> line of the <code>'/robots.txt'</code> entry:</p>
<pre><code class="language-javascript">html: 'User-agent: *\nDisallow: /blog-drafts/\n',
</code></pre>
<p>robots.txt controls crawling, not indexing. Google says it's <a href="https://developers.google.com/search/docs/crawling-indexing/robots/intro">not a mechanism for keeping a page out of Google</a>. For that, you need <code>noindex</code>.</p>
<p>A URL blocked in robots.txt can even appear in search results, usually without a description, if other pages link to it. Google just never reads what's on the page.</p>
<h2 id="heading-how-to-find-an-accidental-noindex">How to Find an Accidental noindex</h2>
<p><code>noindex</code> tells Google not to index a particular page. It's harmful when it ends up on pages you do want indexed and ranked, like a product page or your home page.</p>
<p>But it can be useful on pages you don't need to rank for, or that don't add much to the site, such as log in, sign in, and sign up pages.</p>
<p><code>noindex</code> works only when the crawler can reach the page and read the rule. If robots.txt blocks the same URL, Google never sees the <code>noindex</code>, and the page can still show up in search results. So for a page you want out of Google, use <code>noindex</code> and leave the page crawlable.</p>
<p>In the data, 11 of 457 audited pages (2.4%) had a <code>noindex</code> robots meta tag. There are <a href="https://developers.google.com/search/docs/crawling-indexing/block-indexing">two ways to set it</a>, and you need to check both.</p>
<h3 id="heading-how-to-check-the-robots-meta-tag">How to Check the Robots Meta Tag</h3>
<p>The first way is a tag in the page's <code>&lt;head&gt;</code>:</p>
<pre><code class="language-html">&lt;meta name="robots" content="noindex"&gt;
</code></pre>
<p>Search the page for the word:</p>
<pre><code class="language-bash">curl -s http://localhost:8080/about | grep -i noindex
</code></pre>
<p>On the About page, this prints nothing. You can also right-click the page, choose <strong>View Page Source,</strong> and search for <code>noindex</code>.</p>
<p>Fixing a noindex is really easy. You basically remove it, and then search engines can index the page.</p>
<p>Look for it in the page's code or template, and in your CMS or SEO plugin settings. In WordPress, the setting <strong>Discourage search engines from indexing this site</strong> adds it to every page.</p>
<h3 id="heading-how-to-check-the-x-robots-tag-header">How to Check the X-Robots-Tag Header</h3>
<p>The second way is an HTTP header. Check the About page's headers:</p>
<pre><code class="language-bash">curl -sI http://localhost:8080/about
</code></pre>
<pre><code class="language-text">HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
X-Robots-Tag: noindex
Date: Sun, 25 Oct 2026 17:42:59 GMT
Connection: keep-alive
Keep-Alive: timeout=5
</code></pre>
<p>The header doesn't appear in View Page Source, only in the response headers. In the data, 5 of the 12 blocked pages had no <code>noindex</code> in their HTML: 2 had this header, and 3 were blocked from crawling by robots.txt.</p>
<p>To fix it in the practice site, delete the <code>headers</code> line from the <code>'/about'</code> entry. On a real site, check the server configuration, the hosting provider's header settings, and any SEO plugin.</p>
<h2 id="heading-how-to-use-canonical-tags-correctly">How to Use Canonical Tags Correctly</h2>
<p>If you have several pages that talk about more or less the same thing, but without enough meat to be different, you want to designate one main page. The canonical tag tells search engines which page that is.</p>
<p>The same page can also live at several addresses:</p>
<pre><code class="language-text">https://example.com/blog/choosing-trail-shoes
https://example.com/blog/choosing-trail-shoes?utm_source=newsletter
https://www.example.com/blog/choosing-trail-shoes
</code></pre>
<p>These three addresses show the same article. The first one is the main one: the address you want Google to show in search results. So all three carry the same canonical tag, pointing to that main page:</p>
<pre><code class="language-html">&lt;link rel="canonical" href="https://example.com/blog/choosing-trail-shoes"&gt;
</code></pre>
<p>When Google sees this tag on the <code>?utm_source=newsletter</code> version, it knows that page is a copy of the first address. The main address carries the same tag, pointing to itself. That's called a self-referencing canonical, and it says: I'm the main version.</p>
<p>Google treats it as a <a href="https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls">strong signal, not a command</a>. If you use canonical tags, a self-referencing one on each main page is a good practice, and Google recommends it.</p>
<p>But you don't have to use canonical tags at all. Google says specifying a canonical isn't required: without one, it picks the version it thinks is best to show users. A canonical tag is a good choice when the same or very similar content is reachable at more than one URL, like the three addresses above.</p>
<p>That's why a missing canonical tag isn't a defect by itself. In the data, 27.1% of 457 audited pages had no canonical tag. What matters is whether any of them have duplicates, like a version with tracking parameters, that need one.</p>
<p>Check the practice site's trail shoe article:</p>
<pre><code class="language-bash">curl -s http://localhost:8080/blog/choosing-trail-shoes | grep -i canonical
</code></pre>
<pre><code class="language-text">&lt;link rel="canonical" href="http://localhost:8080/"&gt;
</code></pre>
<p>The article says its main version is the home page, so Google may show the home page instead of it, or ignore the tag.</p>
<p>The article isn't a copy of anything, so it's its own main version. To fix it, point the article's canonical tag to the article itself:</p>
<pre><code class="language-javascript">canonical: '/blog/choosing-trail-shoes',
</code></pre>
<h2 id="heading-how-to-fix-missing-and-duplicate-titles-and-meta-descriptions">How to Fix Missing and Duplicate Titles and Meta Descriptions</h2>
<p>A good title or meta description is the right length, isn't overloaded, and says briefly what the page is about. It's sort of the essence of the page, like its introduction.</p>
<p>Look at the Blue Runner product page:</p>
<pre><code class="language-bash">curl -s http://localhost:8080/products/blue-runner | grep -i -E "&lt;title&gt;|name=\"description\""
</code></pre>
<pre><code class="language-text">&lt;title&gt;Acme Shoes&lt;/title&gt;
</code></pre>
<p>The title says nothing about the page, and there's no description line at all. In PowerShell, use <code>| Select-String '&lt;title&gt;|name="description"'</code> for this one.</p>
<p>Google's guides to <a href="https://developers.google.com/search/docs/appearance/title-link">titles</a> and <a href="https://developers.google.com/search/docs/appearance/snippet">snippets</a> ask for a unique, descriptive title and description on every page.</p>
<p>To fix it in the practice site, replace the <code>title</code> line of the <code>'/products/blue-runner'</code> entry with:</p>
<pre><code class="language-javascript">title: 'Blue Runner Road Running Shoe | Acme Shoes',
description: 'A lightweight road running shoe with a cushioned sole and free returns.',
</code></pre>
<h2 id="heading-how-to-make-your-links-crawlable">How to Make Your Links Crawlable</h2>
<p>Look at the practice site's home page:</p>
<pre><code class="language-bash">curl -s http://localhost:8080/
</code></pre>
<pre><code class="language-text">&lt;!doctype html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="utf-8"&gt;
&lt;title&gt;Acme Shoes: Running Shoes for Every Runner&lt;/title&gt;
&lt;meta name="description" content="Lightweight running shoes for road and trail, with free returns."&gt;
&lt;link rel="canonical" href="http://localhost:8080/"&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Acme Shoes&lt;/h1&gt;
&lt;a href="/products/blue-runner"&gt;Blue Runner&lt;/a&gt;
&lt;span onclick="location.href='/sale'"&gt;Summer sale&lt;/span&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>Everything else on this page is fine: the title, the description, the canonical tag and the Blue Runner link, which is a real <code>&lt;a&gt;</code> element with an <code>href</code>. The only problem is the "Summer sale" <code>&lt;span&gt;</code>.</p>
<p>A <code>&lt;span&gt;</code> is basically HTML that isn't semantic, meaning it has no meaning. A real link does have meaning: search engines can understand it's a link, and screen readers can understand it's a link.</p>
<p>Which links need to be crawlable? Basically, everything you want search engines to see. I mean the products you sell, your articles, your courses, and other things like that.</p>
<p>Google's <a href="https://developers.google.com/search/docs/crawling-indexing/links-crawlable">link guidelines</a> say it can only reliably crawl an <code>&lt;a&gt;</code> element with an <code>href</code>.</p>
<p>To fix it in the practice site, replace the <code>&lt;span&gt;</code> line with:</p>
<pre><code class="language-javascript">'&lt;a href="/sale"&gt;Summer sale&lt;/a&gt;',
</code></pre>
<h2 id="heading-how-to-check-whether-your-content-needs-javascript-to-appear">How to Check Whether Your Content Needs JavaScript to Appear</h2>
<p>With client-side rendering, the JavaScript has to load first, and only then can the other content load.</p>
<p>JavaScript usually builds things like product lists, prices, reviews and menus. Without it, a client-side page often shows only a loading message or an empty box.</p>
<p>Google does render JavaScript, but <a href="https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics">in a later phase</a>. The page waits in a rendering queue, which can take a few seconds or longer, and a script that fails or is blocked can leave the rendered page without its content.</p>
<p>That's why server-side rendering is still a good idea, and it's what I prefer for the content that matters. Google's JavaScript guide says the same: server-side rendering makes the site faster for users and crawlers, and not all bots can run JavaScript.</p>
<p>In the data, 17.7% of 277 audited pages were built mostly with JavaScript. That doesn't mean Google couldn't index them, only that their main content depended on JavaScript running correctly.</p>
<p>With server-side rendering, the HTML content comes straight to the browser, and only after that does the JavaScript render.</p>
<p>Google can index pages built either way. Its crawler runs JavaScript with an up-to-date version of Chrome, so server-side rendering isn't a requirement for getting into Google's index.</p>
<p>The next test checks whether the important content is visible without JavaScript. It doesn't show what Google sees, because Google runs the JavaScript, but it shows what every crawler gets before any JavaScript runs.</p>
<p>Open <code>http://localhost:8080/catalog</code> in your browser. You'll see three products. Now download it with curl, which doesn't run JavaScript:</p>
<pre><code class="language-bash">curl -s http://localhost:8080/catalog | grep -i "trail grip"
</code></pre>
<p>This prints nothing, because the product names aren't in the HTML the server sends. Inside <code>&lt;body&gt;</code>, the server only sends:</p>
<pre><code class="language-html">&lt;div id="app"&gt;Loading...&lt;/div&gt;
&lt;script&gt;fetch('/api/products').then((r) =&gt; r.json()).then((products) =&gt; {document.getElementById('app').innerHTML = products.map((p) =&gt; '&lt;h2&gt;' + p + '&lt;/h2&gt;').join('');});&lt;/script&gt;
</code></pre>
<p>Without curl, use <strong>View Page Source</strong> in your browser. On this page, you'll see "Loading..." and the script, but none of the product names, because the browser adds them only after the JavaScript runs.</p>
<p>On your own site, search the source for an important sentence from the page.</p>
<p>To see the page the way Google renders it, use Google's own tools on a live page. On your own site, the URL Inspection tool in Search Console can run a live test (<strong>Test live URL</strong>, then <strong>View tested page</strong>) and show the HTML Google rendered and a screenshot.</p>
<p>For any public page, the <a href="https://search.google.com/test/rich-results">Rich Results Test</a> shows the rendered HTML too. Google <a href="https://developers.google.com/search/docs/crawling-indexing/javascript/fix-search-javascript">recommends both</a> for finding JavaScript problems. Neither can reach <code>localhost</code>, so try them on your real site.</p>
<p>If you want the product names in the HTML from the start, render them on the server. In the practice site, add the product list above <code>routes</code>:</p>
<pre><code class="language-javascript">const products = ['Blue Runner', 'Trail Grip 2', 'City Glide'];
</code></pre>
<p>Replace the catalog's <code>body</code> and <code>script</code> lines with:</p>
<pre><code class="language-javascript">body: '&lt;div id="app"&gt;' + products.map((p) =&gt; '&lt;h2&gt;' + p + '&lt;/h2&gt;').join('') + '&lt;/div&gt;',
</code></pre>
<p>And in the <code>'/api/products'</code> entry:</p>
<pre><code class="language-javascript">html: JSON.stringify(products),
</code></pre>
<p>Restart the server and run the curl command again:</p>
<pre><code class="language-text">&lt;div id="app"&gt;&lt;h2&gt;Blue Runner&lt;/h2&gt;&lt;h2&gt;Trail Grip 2&lt;/h2&gt;&lt;h2&gt;City Glide&lt;/h2&gt;&lt;/div&gt;
</code></pre>
<p>This works because the server now writes the product names into the HTML before it sends the page. Any crawler sees them, even one that can't run JavaScript, and you can still use JavaScript for the interactive parts.</p>
<h2 id="heading-can-you-check-a-page-in-five-minutes">Can You Check a Page in Five Minutes?</h2>
<p>Honestly, it's very hard. There can be a lot of problems, and five minutes isn't enough.</p>
<p>To really know what the problems are, you need to run a full check, for example in Google PageSpeed Insights. If the site is yours, also use the <a href="https://support.google.com/webmasters/answer/9012289">URL Inspection tool</a> in Google Search Console.</p>
<p>The commands from this tutorial are a good start:</p>
<ol>
<li><code>curl -sI</code> for the status code and an <code>X-Robots-Tag</code> header.</li>
<li><code>curl -sIL</code> on an old address to count redirects.</li>
<li><code>/robots.txt</code>, line by line.</li>
<li>View Page Source for <code>noindex</code>, <code>canonical</code>, <code>&lt;title&gt;</code>, <code>description</code> and your important content.</li>
</ol>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this tutorial, you fixed eight problems on a practice site: a soft 404, a redirect chain, a robots.txt rule, a hidden <code>noindex</code> header, a wrong canonical tag, a vague title and a missing description, a link crawlers couldn't follow, and content that needed JavaScript.</p>
<p>The most important thing to remember is that you'll need to check your site all the time. Run scans, do maintenance, and make sure nothing breaks, especially when you make improvements or changes to the site.</p>
<p>If you want to go further, my tutorial on <a href="https://www.freecodecamp.org/news/nextjs-json-ld-structured-data/">adding structured data (JSON-LD) to a Next.js site</a> is a good next step.</p>
<p>If you'd like to check a live page for many of these issues in one go, my free tool <a href="https://www.greadme.com/page-audit">Greadme Page Audit</a> tests any URL with no sign-up needed.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build a Command-Line Weather App with Python ]]>
                </title>
                <description>
                    <![CDATA[ After doing a few basic Python projects, I got a bit bored of programs that just take input and print something back. I wanted to make something that actually gets data from the internet. So, I built  ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-build-a-command-line-weather-app-with-python/</link>
                <guid isPermaLink="false">6ae266148842cb1aa91f5625</guid>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Beginner Developers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ api ]]>
                    </category>
                
                    <category>
                        <![CDATA[ webdev ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sameer Qaiser ]]>
                </dc:creator>
                <pubDate>Wed, 28 Oct 2026 21:16:04 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/b79396ff-d6f7-4e08-a4e0-282b0eb881da.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>After doing a few basic Python projects, I got a bit bored of programs that just take input and print something back. I wanted to make something that actually gets data from the internet.</p>
<p>So, I built this little weather app. If APIs still feel a bit abstract to you, don't worry. Just remember that an API is basically a way for your program to ask another program for information.</p>
<p>The idea is straightforward: you type a city name in the terminal, and it shows you the current temperature and wind speed. It's nothing fancy, but it’s a nice way to get comfortable with APIs, HTTP requests, and command-line arguments.</p>
<p>By the end of this tutorial, you'll know how to make HTTP requests, parse JSON data, handle errors gracefully, and build a script you can actually use from your terminal.</p>
<h3 id="heading-what-well-cover">What We'll Cover:</h3>
<ul>
<li><a href="#heading-what-you-need-to-get-started">What You Need to Get Started</a></li>
<li><a href="#heading-how-to-turn-a-city-name-into-coordinates">How to Turn a City Name into Coordinates</a></li>
<li><a href="#heading-how-to-get-the-actual-weather-data">How to Get the Actual Weather Data</a></li>
<li><a href="#heading-how-to-run-it-from-the-terminal">How to Run it From the Terminal</a></li>
<li><a href="#heading-lets-test-it-out">Let’s Test it Out</a></li>
<li><a href="#heading-what-i-might-add-next">What I Might Add Next</a></li>
<li><a href="#heading-final-thoughts">Final Thoughts</a></li>
</ul>
<h2 id="heading-what-you-need-to-get-started">What You Need to Get Started</h2>
<p>Before we start, make sure you have:</p>
<ul>
<li>Python installed</li>
<li>A code editor (l use VS Code)</li>
<li>The <strong>requests</strong> library.</li>
</ul>
<p>If you don’t have requests yet, open your terminal and run:</p>
<pre><code class="language-python">pip install requests
</code></pre>
<h2 id="heading-how-to-turn-a-city-name-into-coordinates">How to Turn a City Name into Coordinates</h2>
<p>Weather APIs usually want latitude and longitude, not city names. So the first thing we need is a way to convert “Karachi” or “New York” into coordinates.</p>
<p>Open-Meteo has a free geocoding API that does exactly that. Here’s the function I used:</p>
<pre><code class="language-python">import requests

def get_coordinates(city_name):
    url = "https://geocoding-api.open-meteo.com/v1/search"

    params = {
        "name": city_name,
        "count": 1
    }

    response = requests.get(url, params=params, timeout=5)
    response.raise_for_status()

    data = response.json()

    if not data.get("results"):
        return None

    latitude = data["results"][0]["latitude"]
    longitude = data["results"][0]["longitude"]

    return latitude, longitude
</code></pre>
<p>It's pretty simple. We send the city name, ask for one result, and pull out the latitude and longitude. If the API doesn’t find anything, we just return None instead of crashing later.</p>
<p>One small warning: some city names exist in multiple places. This code just grabs the first match, so it might not always pick the one you meant. Just make sure you double-check before you use it in your project.</p>
<h2 id="heading-how-to-get-the-actual-weather-data">How to Get the Actual Weather Data</h2>
<p>Once we have the coordinates, we can ask for the weather:</p>
<pre><code class="language-python">def get_weather(latitude, longitude):
    url = "https://api.open-meteo.com/v1/forecast"

    params = {
        "latitude": latitude,
        "longitude": longitude,
        "current": "temperature_2m,wind_speed_10m"
    }

    response = requests.get(url, params=params, timeout=5)
    response.raise_for_status()

    data = response.json()

    return data["current"]
</code></pre>
<p>The temperature_2m and wind_speed_10m parameters ask for the temperature at 2 meters above ground and wind speed at 10 meters. By specifying current, we tell the API we only want the data for right now, rather than a multi-day forecast. The API actually returns a bunch of other data too, but we'll just extract the current section.</p>
<h2 id="heading-how-to-run-it-from-the-terminal">How to Run it From the Terminal</h2>
<p>I wanted to be able to run it like this:</p>
<p>python <a href="http://weather.py">weather.py</a> Karachi</p>
<p>So, I used the <strong>sys</strong> module:</p>
<pre><code class="language-python">import sys

def main():
    if len(sys.argv) &lt; 2:
        print("Usage: python weather.py &lt;city_name&gt;")
        return

    city = " ".join(sys.argv[1:])

    try:
        coordinates = get_coordinates(city)

        if not coordinates:
            print(f"City not found: {city}")
            return

        latitude, longitude = coordinates
        weather = get_weather(latitude, longitude)

        print(f"\nWeather in {city.title()}")
        print(f"Temperature: {weather['temperature_2m']}°C")
        print(f"Wind speed: {weather['wind_speed_10m']} km/h")

    except requests.exceptions.RequestException:
        print("Couldn't connect to the weather service. Check your internet connection and try again.")

    except (KeyError, ValueError):
        print("Something went wrong while reading the weather data.")

if __name__ == "__main__":
    main()
</code></pre>
<p>The sys module gives us access to the command-line arguments. <code>sys.argv</code> is a list of everything you type in the terminal. <code>sys.argv[0]</code> is the file name (<a href="http://weather.py">weather.py</a>), and <code>sys.argv[1]</code> is the city name. Using <code>" ".join(sys.argv[1:])</code> allows us to handle city names with spaces, like New York.</p>
<h2 id="heading-lets-test-it-out">Let’s Test it Out</h2>
<p>Save the file as <a href="http://weather.py">weather.py</a>, open a terminal in that folder, and try:</p>
<pre><code class="language-python">python weather.py Madrid
python weather.py Paris
python weather.py Washington
</code></pre>
<p>If you forget to type a city, it just tells you how to use it.</p>
<pre><code class="language-plaintext">Weather in Madrid
Temperature: 15.2°C
Wind speed: 8.4 km/h
</code></pre>
<h2 id="heading-what-i-might-add-next">What I Might Add Next</h2>
<p>Once the basic version works, there are a few easy upgrades you can make:</p>
<ul>
<li>Add humidity (relative_humidity_2m)</li>
<li>Show a short forecast instead of just current conditions</li>
<li>Let the user pick from multiple matching cities when the name is ambiguous</li>
<li>Make the output a bit prettier</li>
</ul>
<p>I usually pick one small improvement, get it working, then move on. Trying to do everything at once usually just gets messy.</p>
<h2 id="heading-final-thoughts">Final Thoughts</h2>
<p>This is a solid little project once you’re past the “print hello world” stage and want to build something that actually talks to the internet. You get real practice with functions, dictionaries, error handling, and APIs, which is stuff you’ll use all the time.</p>
<p>But here’s the important bit. Once you get it working, close this page and try building the whole thing again from scratch.</p>
<p>You’ll forget something. You’ll probably hit some weird error and waste an hour staring at it. That’s fine. That’s the part that actually teaches you something. Copy-pasting my code doesn’t really solidify anything in your brain. Figuring out why yours is broken does.</p>
<p>After you’ve got the weather app working, try the same approach with a completely different API (like movies, crypto prices, sports scores, whatever). The pattern is pretty much the same. Just get the basic version running first, then go break it.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build a Simple Data Analyzer in Python with Pandas ]]>
                </title>
                <description>
                    <![CDATA[ Data analysis might sound complicated when you first encounter it. You might imagine large databases, advanced mathematics, and complicated machine learning algorithms. But many useful data analysis t ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-build-a-simple-data-analyzer-in-python-with-pandas/</link>
                <guid isPermaLink="false">6adfcca469efba9d2d746b18</guid>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ pandas ]]>
                    </category>
                
                    <category>
                        <![CDATA[ data analysis ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Data Science ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Beginner Developers ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Eva J Patel ]]>
                </dc:creator>
                <pubDate>Mon, 26 Oct 2026 21:56:52 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/1d798058-cb3d-4459-8280-320685d7c6d4.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Data analysis might sound complicated when you first encounter it. You might imagine large databases, advanced mathematics, and complicated machine learning algorithms.</p>
<p>But many useful data analysis tasks start with something much simpler: loading a dataset, asking questions about it, and using Python to find the answers.</p>
<p>In this tutorial, you'll build a simple data analyzer using Python and pandas. You'll work with a fictional student performance dataset and learn how to load data, inspect it, calculate statistics, filter records, group information, and create a basic visualization.</p>
<p>By the end, you'll have a reusable foundation for analyzing many types of CSV datasets.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>Before following this tutorial, you should have a few basic Python skills and tools ready. You don't need advanced programming or data analysis experience, but you should be familiar with:</p>
<ul>
<li>Python variables and basic data types, such as strings and numbers.</li>
<li>Importing libraries and calling functions.</li>
<li>Working with lists and basic operations on data.</li>
</ul>
<p>If you're new to Python, consider learning these fundamentals before continuing. Here's an i<a href="https://www.freecodecamp.org/news/learn-python-interactively/">nteractive Python course to get you started</a> if you want to go deep.</p>
<p>Also, make sure you have the following installed:</p>
<ul>
<li><strong>Python:</strong> Python 3 or a compatible Python installation.</li>
<li><strong>pandas:</strong> The Python library we'll use to load, filter, group, and analyze data.</li>
<li><strong>Matplotlib:</strong> The library we'll use to create visualizations.</li>
<li><strong>A code editor or IDE:</strong> Such as VS Code, PyCharm, or a simple text editor, along with access to a terminal.</li>
</ul>
<p>You can install pandas and Matplotlib by running the following command in your terminal:</p>
<pre><code class="language-bash">pip install pandas matplotlib
</code></pre>
<p>You'll also need a folder where you can save your Python script and the <code>students.csv</code> dataset we'll create in this tutorial.</p>
<p>Once everything is ready, you can start analyzing data with Python!</p>
<h2 id="heading-what-well-cover">What We'll Cover:</h2>
<ul>
<li><a href="#heading-setting-up-your-environment">Setting Up Your Environment</a></li>
<li><a href="#heading-creating-the-dataset">Creating the Dataset</a></li>
<li><a href="#heading-loading-the-dataset-with-pandas">Loading the Dataset with Pandas</a></li>
<li><a href="#heading-exploring-the-data">Exploring the Data</a></li>
<li><a href="#heading-calculating-basic-statistics">Calculating Basic Statistics</a></li>
<li><a href="#heading-filtering-data">Filtering Data</a></li>
<li><a href="#heading-finding-specific-students">Finding Specific Students</a></li>
<li><a href="#heading-grouping-data">Grouping Data</a></li>
<li><a href="#heading-analyzing-study-time">Analyzing Study Time</a></li>
<li><a href="#heading-creating-a-visualization">Creating a Visualization</a></li>
<li><a href="#heading-building-the-complete-analyzer">Building the Complete Analyzer</a></li>
<li><a href="#heading-making-the-analyzer-more-reusable">Making the Analyzer More Reusable</a></li>
<li><a href="#heading-handling-missing-data">Handling Missing Data</a></li>
<li><a href="#heading-exporting-results">Exporting Results</a></li>
<li><a href="#heading-common-mistakes-to-avoid">Common Mistakes to Avoid</a></li>
<li><a href="#heading-where-to-go-from-here">Where to Go From Here</a></li>
<li><a href="#heading-final-thoughts">Final Thoughts</a></li>
</ul>
<h2 id="heading-setting-up-your-environment">Setting Up Your Environment</h2>
<h3 id="heading-installing-pandas">Installing pandas</h3>
<p>If you don't already have pandas installed, open your terminal and run:</p>
<pre><code class="language-python">pip install pandas matplotlib
</code></pre>
<p>We'll use pandas for data analysis and Matplotlib for a simple visualization.</p>
<p>You can verify the installation with:</p>
<pre><code class="language-python">import pandas as pd
import matplotlib.pyplot as plt

print(pd.__version__)
</code></pre>
<p>If Python prints a version number, you're ready to go.</p>
<h2 id="heading-creating-the-dataset">Creating the Dataset</h2>
<h3 id="heading-creating-a-csv-file">Creating a CSV File</h3>
<p>We'll start by creating a file called <code>students.csv</code> and adding some data.</p>
<p>The dataset we'll be working with here is fictional and contains 12 student records across grades 9 through 12. Each row represents one student, and each column describes a different attribute:</p>
<ul>
<li><code>name</code>: The student's first name.</li>
<li><code>grade</code>: The student's current grade level in school.</li>
<li><code>study_hours</code>: The number of hours the student studied.</li>
<li><code>attendance</code>: The student's attendance percentage.</li>
<li><code>score</code>: The student's test score, recorded on a 0–100 scale.</li>
</ul>
<p>For example, Ava is in grade 9, studied for 4.5 hours, has 95% attendance, and received a test score of 82. These sample records let us explore questions such as whether study time is associated with test scores and how average scores compare across grade levels.</p>
<p>Because the data is fictional and small, any patterns we observe are only illustrative, and we shouldn't treat them as evidence about students in general.</p>
<p>But our data will give us enough information to perform several useful analyses. Here it is:</p>
<pre><code class="language-csv">name,grade,study_hours,attendance,score
Ava,9,4.5,95,82
Liam,9,6.0,98,91
Sophia,10,3.5,89,76
Noah,10,7.0,99,94
Emma,11,5.5,93,88
Oliver,11,8.0,97,96
Mia,12,4.0,91,79
Ethan,12,6.5,96,90
Isabella,9,7.5,100,97
Lucas,10,2.5,85,68
Amelia,11,6.0,94,92
James,12,5.0,90,84
</code></pre>
<h2 id="heading-loading-the-dataset-with-pandas">Loading the Dataset with Pandas</h2>
<h3 id="heading-reading-the-csv-file">Reading the CSV File</h3>
<p>Start your Python program by importing pandas:</p>
<pre><code class="language-python">import pandas as pd
</code></pre>
<p>Then load the CSV file:</p>
<pre><code class="language-python">data = pd.read_csv("students.csv")
</code></pre>
<p>The <code>read_csv()</code> function reads the CSV file and converts it into a pandas DataFrame.</p>
<p>A DataFrame is a table-like data structure with rows and columns. You can think of it as a programmable spreadsheet.</p>
<p>Let's display the dataset:</p>
<pre><code class="language-python">print(data)
</code></pre>
<p>You should see the student records printed in your terminal.</p>
<h2 id="heading-exploring-the-data">Exploring the Data</h2>
<p>Before analyzing a dataset, it's useful to understand what you're working with.</p>
<h3 id="heading-viewing-the-first-rows">Viewing the First Rows</h3>
<p>The <code>head()</code> method displays the first five rows:</p>
<pre><code class="language-python">print(data.head())
</code></pre>
<p>You can also specify how many rows you want:</p>
<pre><code class="language-python">print(data.head(3))
</code></pre>
<h3 id="heading-checking-the-dataset-size">Checking the Dataset Size</h3>
<p>Use <code>shape</code> to find the number of rows and columns:</p>
<pre><code class="language-python">print(data.shape)
</code></pre>
<p>The result will be:</p>
<pre><code class="language-text">(12, 5)
</code></pre>
<p>That means our dataset contains 12 rows and 5 columns.</p>
<h3 id="heading-examining-column-names">Examining Column Names</h3>
<p>You can view the column names with:</p>
<pre><code class="language-python">print(data.columns)
</code></pre>
<p>This is useful when you need to reference columns later in your program.</p>
<h3 id="heading-checking-data-types">Checking Data Types</h3>
<p>Use <code>info()</code> to see information about each column:</p>
<pre><code class="language-python">data.info()
</code></pre>
<p>This helps you identify whether columns contain integers, decimal numbers, text, or other types of data.</p>
<h2 id="heading-calculating-basic-statistics">Calculating Basic Statistics</h2>
<p>Pandas makes it easy to calculate statistics without manually writing the mathematical formulas.</p>
<h3 id="heading-finding-the-average-score">Finding the Average Score</h3>
<p>We can calculate the average score using:</p>
<pre><code class="language-python">average_score = data["score"].mean()

print(f"Average score: {average_score:.2f}")
</code></pre>
<p>The <code>mean()</code> method calculates the arithmetic average.</p>
<p>The <code>:.2f</code> formatting tells Python to display the result with two decimal places.</p>
<h3 id="heading-finding-the-highest-and-lowest-scores">Finding the Highest and Lowest Scores</h3>
<p>Use <code>max()</code> and <code>min()</code>:</p>
<pre><code class="language-python">highest_score = data["score"].max()
lowest_score = data["score"].min()

print(f"Highest score: {highest_score}")
print(f"Lowest score: {lowest_score}")
</code></pre>
<p>You can also find the median:</p>
<pre><code class="language-python">median_score = data["score"].median()

print(f"Median score: {median_score}")
</code></pre>
<p>The median is the middle value when the scores are ordered.</p>
<h3 id="heading-generating-a-statistical-summary">Generating a Statistical Summary</h3>
<p>Pandas also provides a convenient <code>describe()</code> method:</p>
<pre><code class="language-python">print(data["score"].describe())
</code></pre>
<p>This produces statistics such as:</p>
<ul>
<li>Count</li>
<li>Mean</li>
<li>Standard deviation</li>
<li>Minimum</li>
<li>25th percentile</li>
<li>Median</li>
<li>75th percentile</li>
<li>Maximum</li>
</ul>
<p>You can generate a summary for all numerical columns:</p>
<pre><code class="language-python">print(data.describe())
</code></pre>
<p>This is often one of the first commands you'll use when exploring an unfamiliar dataset.</p>
<h2 id="heading-filtering-data">Filtering Data</h2>
<p>One of the most useful features of pandas is the ability to select rows based on conditions.</p>
<h3 id="heading-finding-students-with-high-scores">Finding Students With High Scores</h3>
<p>Suppose we want to find students who scored at least 90:</p>
<pre><code class="language-python">high_scores = data[data["score"] &gt;= 90]

print(high_scores)
</code></pre>
<p>The expression:</p>
<pre><code class="language-python">data["score"] &gt;= 90
</code></pre>
<p>creates a Boolean condition for every row. Pandas then keeps only the rows where that condition is <code>True</code>.</p>
<h3 id="heading-finding-students-who-study-more-than-five-hours">Finding Students Who Study More Than Five Hours</h3>
<p>We can perform the same operation using study time:</p>
<pre><code class="language-python">frequent_studiers = data[data["study_hours"] &gt; 5]

print(frequent_studiers)
</code></pre>
<p>You can combine multiple conditions as well.</p>
<p>For example, suppose we want students who study more than five hours and have an attendance rate above 95 percent:</p>
<pre><code class="language-python">students = data[
    (data["study_hours"] &gt; 5) &amp;
    (data["attendance"] &gt; 95)
]

print(students)
</code></pre>
<p>When combining conditions in pandas, use <code>&amp;</code> for AND and <code>|</code> for OR. Each condition should be enclosed in parentheses.</p>
<h2 id="heading-finding-specific-students">Finding Specific Students</h2>
<h3 id="heading-using-idxmax">Using <code>idxmax()</code></h3>
<p>Sometimes you don't just want the highest value. You want to know which record contains it.</p>
<p>For example:</p>
<pre><code class="language-python">top_student_index = data["score"].idxmax()
top_student = data.loc[top_student_index]

print(top_student)
</code></pre>
<p><code>idxmax()</code> returns the index of the row containing the largest value.</p>
<p>We can do the same for study hours:</p>
<pre><code class="language-python">most_studious_index = data["study_hours"].idxmax()
most_studious_student = data.loc[most_studious_index]

print(most_studious_student)
</code></pre>
<p>This lets you connect a statistic back to the original record.</p>
<h2 id="heading-grouping-data">Grouping Data</h2>
<p>Grouping becomes particularly useful when your dataset contains categories.</p>
<p>In our dataset, students belong to different grades.</p>
<h3 id="heading-average-score-by-grade">Average Score by Grade</h3>
<p>We can calculate the average score for each grade:</p>
<pre><code class="language-python">average_by_grade = data.groupby("grade")["score"].mean()

print(average_by_grade)
</code></pre>
<p>This tells us how the average score differs between grades.</p>
<p>We can make the output easier to read:</p>
<pre><code class="language-python">average_by_grade = (
    data.groupby("grade")["score"]
    .mean()
    .round(2)
)

print(average_by_grade)
</code></pre>
<h3 id="heading-multiple-statistics">Multiple Statistics</h3>
<p>You can calculate several statistics at once:</p>
<pre><code class="language-python">grade_summary = data.groupby("grade")["score"].agg(
    ["mean", "min", "max", "count"]
)

print(grade_summary)
</code></pre>
<p>This produces a summary for each grade containing the average, minimum, maximum, and number of students.</p>
<h2 id="heading-analyzing-study-time">Analyzing Study Time</h2>
<p>We can also investigate the relationship between study hours and scores.</p>
<h3 id="heading-calculating-correlation">Calculating Correlation</h3>
<p>Pandas provides a <code>corr()</code> method:</p>
<pre><code class="language-python">correlation = data["study_hours"].corr(data["score"])

print(f"Correlation: {correlation:.2f}")
</code></pre>
<p>The correlation value generally ranges from -1 to 1.</p>
<p>A value closer to 1 indicates a stronger positive linear relationship, while a value closer to -1 indicates a stronger negative linear relationship. A value near 0 indicates little linear relationship.</p>
<p>However, correlation does <strong>not</strong> prove that one variable causes another. For example, if study hours and scores are correlated in this dataset, that doesn't prove that studying more directly caused higher scores.</p>
<h2 id="heading-creating-a-visualization">Creating a Visualization</h2>
<p>Numbers are useful, but visualizations can make patterns easier to recognize.</p>
<h3 id="heading-creating-a-scatter-plot">Creating a Scatter Plot</h3>
<p>We'll create a scatter plot showing study hours and test scores:</p>
<pre><code class="language-python">import matplotlib.pyplot as plt

plt.scatter(data["study_hours"], data["score"])

plt.xlabel("Study Hours")
plt.ylabel("Test Score")
plt.title("Study Hours vs. Test Scores")

plt.show()
</code></pre>
<p>Each point represents one student.</p>
<p>The x-axis represents study hours, while the y-axis represents test scores.</p>
<p>You may notice whether the points appear to generally move upward as study time increases.</p>
<p>This is what it should look like:</p>
<img src="https://cdn.hashnode.com/uploads/covers/6a581501af6af179dc1987d5/0c26d632-eaa4-4d4e-b6c2-b0bfb2d1f240.png" alt="Matplotlib Scatterplot Output" style="display: block;" width="838" height="679" loading="lazy">

<h3 id="heading-creating-a-bar-chart">Creating a Bar Chart</h3>
<p>We can also visualize the average score for each grade:</p>
<pre><code class="language-python">average_by_grade = data.groupby("grade")["score"].mean()

average_by_grade.plot(kind="bar")

plt.xlabel("Grade")
plt.ylabel("Average Score")
plt.title("Average Score by Grade")

plt.show()
</code></pre>
<p>A bar chart makes it easier to compare the averages between groups.</p>
<p>This is what the bar chart should look like:</p>
<img src="https://cdn.hashnode.com/uploads/covers/6a581501af6af179dc1987d5/64871076-8748-415f-addf-2707543e8861.png" alt="Matplotlib Bar Chart Output" style="display: block;" width="841" height="682" loading="lazy">

<h2 id="heading-building-the-complete-analyzer">Building the Complete Analyzer</h2>
<p>Now let's combine the main ideas into one program.</p>
<pre><code class="language-python">import pandas as pd
import matplotlib.pyplot as plt

# Load the dataset
data = pd.read_csv("students.csv")

# Basic information
print("Dataset shape:")
print(data.shape)

print("\nFirst five rows:")
print(data.head())

# Score statistics
average_score = data["score"].mean()
median_score = data["score"].median()
highest_score = data["score"].max()
lowest_score = data["score"].min()

print("\nScore Statistics")
print(f"Average: {average_score:.2f}")
print(f"Median: {median_score:.2f}")
print(f"Highest: {highest_score}")
print(f"Lowest: {lowest_score}")

# Students with scores of 90 or higher
high_scores = data[data["score"] &gt;= 90]

print("\nStudents with scores of 90 or higher:")
print(high_scores[["name", "score"]])

# Average score by grade
average_by_grade = (
    data.groupby("grade")["score"]
    .mean()
    .round(2)
)

print("\nAverage Score by Grade:")
print(average_by_grade)

# Study hours and score correlation
correlation = data["study_hours"].corr(data["score"])

print(f"\nStudy Hours vs. Score Correlation: {correlation:.2f}")

# Scatter plot
plt.scatter(data["study_hours"], data["score"])

plt.xlabel("Study Hours")
plt.ylabel("Test Score")
plt.title("Study Hours vs. Test Scores")

plt.show()
</code></pre>
<p>This program now performs a small but complete data analysis workflow.</p>
<h2 id="heading-making-the-analyzer-more-reusable">Making the Analyzer More Reusable</h2>
<p>A useful next step is turning repeated operations into functions.</p>
<h3 id="heading-creating-an-analysis-function">Creating an Analysis Function</h3>
<p>Instead of writing everything directly in the main program, we can create a function:</p>
<pre><code class="language-python">def analyze_scores(data):
    average = data["score"].mean()
    median = data["score"].median()
    highest = data["score"].max()
    lowest = data["score"].min()

    print(f"Average score: {average:.2f}")
    print(f"Median score: {median:.2f}")
    print(f"Highest score: {highest}")
    print(f"Lowest score: {lowest}")
</code></pre>
<p>Then call it with:</p>
<pre><code class="language-python">analyze_scores(data)
</code></pre>
<p>This makes the code easier to reuse with another DataFrame.</p>
<h3 id="heading-creating-a-function-for-top-students">Creating a Function for Top Students</h3>
<p>We can also create a function that returns the highest-scoring students:</p>
<pre><code class="language-python">def get_top_students(data, minimum_score=90):
    return data[data["score"] &gt;= minimum_score][
        ["name", "grade", "score"]
    ]
</code></pre>
<p>Now we can change the threshold whenever we want:</p>
<pre><code class="language-python">print(get_top_students(data, 95))
</code></pre>
<p>Functions like these become especially valuable when your analyzer grows.</p>
<h2 id="heading-handling-missing-data">Handling Missing Data</h2>
<p>Real-world datasets are rarely as clean as our example. You may encounter missing values sometimes.</p>
<p>You can check for missing values with:</p>
<pre><code class="language-python">print(data.isnull().sum())
</code></pre>
<p>This tells you how many missing values exist in each column.</p>
<p>For example, you could remove rows containing missing values with:</p>
<pre><code class="language-python">clean_data = data.dropna()
</code></pre>
<p>Or, depending on the dataset and what the missing value means, you might replace missing values:</p>
<pre><code class="language-python">data["score"] = data["score"].fillna(data["score"].mean())
</code></pre>
<p>You should not automatically replace every missing value with an average. The appropriate approach depends on what the missing data represents and what you're trying to analyze.</p>
<h2 id="heading-exporting-results">Exporting Results</h2>
<p>After analyzing a dataset, you may want to save your results.</p>
<p>For example:</p>
<pre><code class="language-python">average_by_grade.to_csv("average_scores_by_grade.csv")
</code></pre>
<p>You can also save filtered records:</p>
<pre><code class="language-python">high_scores.to_csv("high_scoring_students.csv", index=False)
</code></pre>
<p>The <code>index=False</code> argument prevents pandas from adding the DataFrame's index as an extra column.</p>
<h2 id="heading-common-mistakes-to-avoid">Common Mistakes to Avoid</h2>
<h3 id="heading-forgetting-to-import-libraries">Forgetting to Import Libraries</h3>
<p>Make sure the required libraries are imported:</p>
<pre><code class="language-python">import pandas as pd
import matplotlib.pyplot as plt
</code></pre>
<p>Otherwise, Python won't know what <code>pd</code> or <code>plt</code> means.</p>
<h3 id="heading-using-the-wrong-column-name">Using the Wrong Column Name</h3>
<p>Column names must match your dataset.</p>
<p>For example, if the column is called <code>study_hours</code>, this won't work:</p>
<pre><code class="language-python">data["study time"]
</code></pre>
<p>You can always check the actual column names with:</p>
<pre><code class="language-python">print(data.columns)
</code></pre>
<h3 id="heading-confusing-correlation-with-causation">Confusing Correlation With Causation</h3>
<p>A correlation can identify a relationship between variables, but it doesn't establish that one variable caused another.</p>
<p>This distinction becomes increasingly important as you work with larger and more complicated datasets.</p>
<h3 id="heading-analyzing-before-understanding-the-data">Analyzing Before Understanding the Data</h3>
<p>It's tempting to immediately calculate statistics. But first inspect the dataset.</p>
<p>Useful starting commands include:</p>
<pre><code class="language-python">data.head()
data.shape
data.info()
data.describe()
data.isnull().sum()
</code></pre>
<p>Understanding the structure and quality of your data helps prevent incorrect conclusions.</p>
<h2 id="heading-where-to-go-from-here">Where to Go From Here</h2>
<p>The analyzer you've built is intentionally simple, but the same workflow can be applied to much larger datasets.</p>
<p>You could extend it to:</p>
<ul>
<li>Analyze sales data</li>
<li>Track website traffic</li>
<li>Study survey responses</li>
<li>Analyze marketing campaigns</li>
<li>Examine sports statistics</li>
<li>Explore financial datasets</li>
<li>Track application or customer data</li>
</ul>
<p>You could also add more advanced features such as interactive charts, command-line arguments, automated reports, or machine learning models.</p>
<p>For example, instead of hard-coding the CSV filename, you could let the user provide one:</p>
<pre><code class="language-python">filename = input("Enter the CSV filename: ")

data = pd.read_csv(filename)

print(data.head())
</code></pre>
<p>Now the same program can analyze different CSV files.</p>
<h2 id="heading-final-thoughts">Final Thoughts</h2>
<p>You don't need complicated algorithms to start working with data. With Python, pandas, and a relatively small dataset, you can already perform meaningful analysis.</p>
<p>In this tutorial, you learned how to:</p>
<ul>
<li>Load CSV data with pandas</li>
<li>Explore a DataFrame</li>
<li>Calculate statistics</li>
<li>Filter rows</li>
<li>Find specific records</li>
<li>Group data</li>
<li>Calculate correlations</li>
<li>Create visualizations</li>
<li>Handle missing values</li>
<li>Export analysis results</li>
<li>Organize analysis with functions</li>
</ul>
<p>The most important next step is to practice with different datasets. Once you're comfortable loading, exploring, cleaning, and analyzing data with pandas, you can start building much more sophisticated data-analysis projects.</p>
<p>Happy coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build a Real-Time Word Counter Tool with HTML, CSS, and JavaScript ]]>
                </title>
                <description>
                    <![CDATA[ Whether you're writing an essay, a tweet, or a blog post, keeping track of your word and character count is very important. In this tutorial, you'll build a fully functional, real-time Word Counter to ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-build-a-real-time-word-counter-tool-with-html-css-and-javascript/</link>
                <guid isPermaLink="false">6abca43ca3fbe2215db75ecf</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML5 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Beginner Developers ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Bansidhar Kadiya ]]>
                </dc:creator>
                <pubDate>Wed, 30 Sep 2026 05:55:08 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/d32feb51-3930-4bd7-be76-9a9150d069d1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Whether you're writing an essay, a tweet, or a blog post, keeping track of your word and character count is very important.</p>
<p>In this tutorial, you'll build a fully functional, real-time Word Counter tool from scratch. You'll use HTML for the structure, CSS for a clean design, and vanilla JavaScript to handle the counting logic.</p>
<p>Because this tool runs completely in the browser, it works instantly as you type and keeps your text data completely private.</p>
<p>Let's get started.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>To follow this guide easily, you should have:</p>
<ul>
<li><p>A basic understanding of HTML tags and CSS styling.</p>
</li>
<li><p>Familiarity with JavaScript concepts like functions, event listeners, and basic Regular Expressions (Regex).</p>
</li>
<li><p>A code editor (like VS Code) and a web browser.</p>
</li>
</ul>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a href="#heading-step-1-set-up-your-project">Step 1: Set Up Your Project</a></p>
</li>
<li><p><a href="#heading-step-2-build-the-html-structure">Step 2: Build the HTML Structure</a></p>
<ul>
<li><a href="#heading-understanding-the-html">Understanding the HTML:</a></li>
</ul>
</li>
<li><p><a href="#heading-step-3-style-the-tool-with-css">Step 3: Style the Tool with CSS</a></p>
<ul>
<li><a href="#heading-understanding-the-css">Understanding the CSS:</a></li>
</ul>
</li>
<li><p><a href="#heading-step-4-add-the-javascript-logic">Step 4: Add the JavaScript Logic</a></p>
<ul>
<li><a href="#heading-understanding-the-javascript">Understanding the JavaScript:</a></li>
</ul>
</li>
<li><p><a href="#heading-step-5-test-your-application">Step 5: Test Your Application</a></p>
</li>
</ul>
<h2 id="heading-step-1-set-up-your-project">Step 1: Set Up Your Project</h2>
<p>First, you need to set up your workspace. Create a new folder on your computer and name it <code>word-counter-app</code>.</p>
<p>Inside this folder, create three empty files:</p>
<ul>
<li><p><code>index.html</code></p>
</li>
<li><p><code>style.css</code></p>
</li>
<li><p><code>script.js</code></p>
</li>
</ul>
<h2 id="heading-step-2-build-the-html-structure">Step 2: Build the HTML Structure</h2>
<p>Open your <code>index.html</code> file. You need to create a layout that includes a header, a grid to display the real-time statistics, a text area for the user to type in, and buttons to copy or clear the text.</p>
<p>Add the following code into your HTML file:</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
    &lt;title&gt;Word Counter Tool&lt;/title&gt;
    &lt;link rel="stylesheet" href="style.css"&gt;
&lt;/head&gt;
&lt;body&gt;

    &lt;header class="header-section"&gt;
        &lt;h1&gt;Word Counter&lt;/h1&gt;
        &lt;p class="description"&gt;Paste or type your text below to get a real-time count of words, characters, sentences, and paragraphs.&lt;/p&gt;
    &lt;/header&gt;

    &lt;main class="tool-container"&gt;
        
        &lt;!-- Statistics Panel --&gt;
        &lt;div class="stats-grid"&gt;
            &lt;div class="stat-box"&gt;
                &lt;div class="stat-value" id="wordCount"&gt;0&lt;/div&gt;
                &lt;div class="stat-label"&gt;Words&lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="stat-box"&gt;
                &lt;div class="stat-value" id="charCount"&gt;0&lt;/div&gt;
                &lt;div class="stat-label"&gt;Characters&lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="stat-box"&gt;
                &lt;div class="stat-value" id="sentenceCount"&gt;0&lt;/div&gt;
                &lt;div class="stat-label"&gt;Sentences&lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="stat-box"&gt;
                &lt;div class="stat-value" id="paragraphCount"&gt;0&lt;/div&gt;
                &lt;div class="stat-label"&gt;Paragraphs&lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;!-- User Input Area --&gt;
        &lt;textarea id="textInput" placeholder="Start typing or paste your text here..."&gt;&lt;/textarea&gt;

        &lt;!-- Action Buttons --&gt;
        &lt;div class="controls"&gt;
            &lt;button class="btn-primary" onclick="copyText()" id="copyBtn"&gt;Copy Text&lt;/button&gt;
            &lt;button class="btn-secondary" onclick="clearText()"&gt;Clear&lt;/button&gt;
        &lt;/div&gt;

    &lt;/main&gt;

    &lt;script src="script.js"&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>Understanding the HTML:</p>
<ul>
<li><p><strong>The</strong> <code>.stats-grid</code><strong>:</strong> This holds four separate boxes to show the counts. Each number has a unique <code>id</code> (like <code>wordCount</code>) so JavaScript can find and update it easily.</p>
</li>
<li><p><strong>The</strong> <code>&lt;textarea&gt;</code><strong>:</strong> This is the main input box where users will type or paste their content.</p>
</li>
<li><p><strong>The</strong> <code>&lt;script&gt;</code> <strong>tag:</strong> This connects your HTML to the logic you will write in the next steps.</p>
</li>
</ul>
<h2 id="heading-step-3-style-the-tool-with-css">Step 3: Style the Tool with CSS</h2>
<p>Next, you'll give your tool a modern, professional look. You'll use CSS Grid to align the statistics boxes perfectly.</p>
<p>Open your <code>style.css</code> file and add this code:</p>
<pre><code class="language-css">:root {
    --primary-color: #007bff;
    --bg-color: #f8f9fa;
    --text-dark: #202124;
    --text-muted: #5f6368;
    --border-color: #dadce0;
    --panel-bg: #ffffff;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-dark);
    margin: 0;
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.header-section {
    text-align: center;
    margin-bottom: 30px;
}

h1 {
    font-size: 2.5rem;
    margin: 0 0 10px 0;
    font-weight: 800;
}

p.description {
    color: var(--text-muted);
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.6;
    font-size: 1.1rem;
}

.tool-container {
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 900px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-box {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* Text Area */
textarea {
    width: 100%;
    height: 250px;
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    line-height: 1.6;
    resize: vertical;
    box-sizing: border-box;
    font-family: inherit;
    margin-bottom: 20px;
    transition: border-color 0.2s ease;
}

textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Buttons */
.controls {
    display: flex;
    gap: 12px;
}

button {
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    border: none;
    transition: background-color 0.2s ease;
}

.btn-primary {
    background-color: var(--primary-color);
    color: #ffffff;
}

.btn-primary:hover {
    background-color: #0056b3;
}

.btn-secondary {
    background-color: transparent;
    color: var(--text-dark);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--bg-color);
}
</code></pre>
<p>Understanding the CSS:</p>
<ul>
<li><p><strong>CSS Grid:</strong> The <code>.stats-grid</code> class uses <code>grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));</code>. This makes the four stat boxes automatically stack neatly on top of each other if a user views the tool on a small mobile screen.</p>
</li>
<li><p><strong>CSS Variables:</strong> Using <code>:root</code> at the top allows you to quickly change the brand color later if you want to use something other than the default blue (<code>#007bff</code>).</p>
</li>
</ul>
<p>At this point, the visual design of your tool is complete. Here's what the final Word Counter will look like in your browser:</p>
<img src="https://cdn.hashnode.com/uploads/covers/699c7b22cf5def0f6aaf982b/dc292767-ac0f-4e87-b88c-d64fab38f370.png" alt="Word Counter Tool" style="display: block;" width="1435" height="843" loading="lazy">

<h2 id="heading-step-4-add-the-javascript-logic">Step 4: Add the JavaScript Logic</h2>
<p>Now you need to make the tool count the text. You'll use an event listener that watches every keystroke. Every time the user types, it recalculates the words, characters, sentences, and paragraphs.</p>
<p>Open your <code>script.js</code> file and paste this code:</p>
<pre><code class="language-javascript">const textInput = document.getElementById('textInput');
const wordCountDisplay = document.getElementById('wordCount');
const charCountDisplay = document.getElementById('charCount');
const sentenceCountDisplay = document.getElementById('sentenceCount');
const paragraphCountDisplay = document.getElementById('paragraphCount');
const copyBtn = document.getElementById('copyBtn');

// 1. Listen for user input in real-time
textInput.addEventListener('input', updateStatistics);

// 2. The Core Counting Logic
function updateStatistics() {
    const text = textInput.value;

    // Character Count (includes spaces)
    charCountDisplay.textContent = text.length;

    // Word Count
    const words = text.match(/\S+/g) || [];
    wordCountDisplay.textContent = words.length;

    // Sentence Count
    const sentences = text.split(/[.!?]+(?=\s|$)/).filter(sentence =&gt; sentence.trim().length &gt; 0);
    sentenceCountDisplay.textContent = sentences.length;

    // Paragraph Count
    const paragraphs = text.split(/\n+/).filter(paragraph =&gt; paragraph.trim().length &gt; 0);
    paragraphCountDisplay.textContent = paragraphs.length;
}

// 3. Copy functionality
function copyText() {
    if (!textInput.value) return;
    
    textInput.select();
    document.execCommand('copy');
    
    // Provide visual feedback
    copyBtn.textContent = 'Copied!';
    setTimeout(() =&gt; {
        copyBtn.textContent = 'Copy Text';
    }, 1500);
}

// 4. Clear functionality
function clearText() {
    textInput.value = '';
    updateStatistics(); // Reset counts to zero
}
</code></pre>
<p>Understanding the JavaScript:</p>
<ul>
<li><p><strong>The</strong> <code>input</code> <strong>Event:</strong> <code>textInput.addEventListener('input', ...)</code> is the secret to real-time updates. It triggers the counting function the exact moment a key is pressed or text is pasted.</p>
</li>
<li><p><strong>Counting Words:</strong> <code>text.match(/\S+/g)</code> is a Regular Expression that looks for unbroken strings of non-whitespace characters. This is much more accurate than just splitting the text by spaces, because it ignores extra empty spaces left by mistake.</p>
</li>
<li><p><strong>Counting Sentences:</strong> The <code>.split(/[.!?]+(?=\s|$)/)</code> logic cuts the text into pieces every time it sees a period, exclamation mark, or question mark followed by a space.</p>
</li>
</ul>
<h2 id="heading-step-5-test-your-application">Step 5: Test Your Application</h2>
<p>You're completely done coding! Now it's time to verify that your logic works correctly.</p>
<ol>
<li><p>Open your <code>word-counter-app</code> folder.</p>
</li>
<li><p>Double-click the <code>index.html</code> file to open it in your web browser.</p>
</li>
<li><p>Type a few sentences into the text area. Watch the numbers at the top update instantly.</p>
</li>
<li><p>Try adding double spaces or hitting the "Enter" key to make new paragraphs, and ensure the logic counts them accurately.</p>
</li>
<li><p>Click <strong>Copy Text</strong> to test the clipboard feature, and <strong>Clear</strong> to reset the board.</p>
</li>
</ol>
<p>By completing this project, you've built a fast, client-side utility tool using pure vanilla JavaScript. You learned how to manipulate strings, use Regular Expressions for text analysis, and create responsive UI grids.</p>
<p>If you want to see this exact codebase running in a live production environment, you can try out this <a href="https://99tools.net/word-counter/">Online Word Counter</a>. Keep building, and happy coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What's New in macOS 27 for Developers? ]]>
                </title>
                <description>
                    <![CDATA[ macOS 27 Golden Gate is here. Apple released it September 14, 2026, as a free upgrade for every Mac that can run it. I'll show you what actually changes for developers in macOS 27, how to upgrade with ]]>
                </description>
                <link>https://www.freecodecamp.org/news/whats-new-in-macos-27-for-developers/</link>
                <guid isPermaLink="false">6aa9b21e85e19ac0f866ed24</guid>
                
                    <category>
                        <![CDATA[ macOS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Beginner Developers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Developer ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Daniel Kehoe ]]>
                </dc:creator>
                <pubDate>Tue, 15 Sep 2026 21:01:18 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/0448ce08-813c-4739-99d7-88fad680006a.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>macOS 27 Golden Gate is here. Apple released it September 14, 2026, as a free upgrade for every Mac that can run it.</p>
<p>I'll show you what actually changes for developers in macOS 27, how to upgrade without waiting hours for the download, and how to check that tools for software development are installed.</p>
<p>Should you upgrade? Here's my recommendation: <strong>upgrade</strong> if your Mac uses an Apple Silicon chip, <strong>download the package installer</strong> instead of using Software Update, then take this opportunity to do any housekeeping to tidy your Mac.</p>
<p>The upgrade itself isn't a reason to hesitate, if you're prepared. The download can be the biggest delay. I'll show you the method that was faster in my testing.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<p>Here's what is covered here:</p>
<ol>
<li><p><a href="#heading-are-you-ready-for-macos-27">Are You Ready for macOS 27?</a></p>
</li>
<li><p><a href="#heading-time-needed-to-upgrade">Time Needed to Upgrade</a></p>
</li>
<li><p><a href="#heading-notable-changes-in-macos-27">Notable Changes in macOS 27</a></p>
</li>
<li><p><a href="#heading-the-new-fm-command">The New fm Command</a></p>
</li>
<li><p><a href="#heading-before-you-start">Before You Start</a></p>
</li>
<li><p><a href="#heading-how-to-upgrade-to-macos-27">How to Upgrade to macOS 27</a></p>
</li>
<li><p><a href="#heading-check-your-developer-tools-after-the-upgrade">Check Your Developer Tools After the Upgrade</a></p>
</li>
<li><p><a href="#heading-whats-next">What's Next</a></p>
</li>
</ol>
<h2 id="heading-are-you-ready-for-macos-27">Are You Ready for macOS 27?</h2>
<p>If you've got an older Intel-based Mac, you won't be able to upgrade.</p>
<p><strong>Your Mac needs Apple Silicon.</strong> macOS 27 is the first release to drop every Intel Mac, so a Mac with an Intel processor can't upgrade at all. If you're running macOS Tahoe 26 on an Intel-based Mac, you must stay on Tahoe, which Apple is expected to patch for security into 2028.</p>
<p>To check if your Mac is compatible, see <a href="https://mac.install.guide/macos/compatibility">macOS 27 compatibility</a>.</p>
<p><strong>The release is stable.</strong> Reviewers who installed the betas this summer said macOS 27 is unusually stable. Several compare it to Mac OS X Snow Leopard, the 2009 release that focused on refinement. Apple built this version around performance rather than a redesign.</p>
<p>Still, for a Mac you depend on for work, wait for the first 27.1 point release to reduce risk.</p>
<h2 id="heading-time-needed-to-upgrade">Time Needed to Upgrade</h2>
<p>Two things need time: the software download and the actual on-machine installation.</p>
<p>Your local internet connection speed may not be the bottleneck to a fast download. Apple offers a convenient Software Update in System Settings, which most people use. But it's the slowest way to get the update.</p>
<p>On a 300 Mbps connection, Software Update showed me a four-hour forecast and took even longer. Downloading Apple's package installer in a browser took about 50 minutes, perhaps because a web browser is optimized for downloading large files using multiple connections. On-machine installation takes about an hour, once you've completed the download, with several automatic restarts.</p>
<p>If you use the convenient Software Update in System Settings, let it run overnight while you sleep. Otherwise, download the package installer and then run the installation process while you go to lunch or run errands.</p>
<h2 id="heading-notable-changes-in-macos-27">Notable Changes in macOS 27</h2>
<p>What do you get with the new macOS 27?</p>
<ul>
<li><p><strong>Liquid Glass is adjustable.</strong> macOS Tahoe 26 introduced the Liquid Glass interface redesign, which triggered numerous hate posts last year. By now, most people have gotten used to it. To help, Apple has added a slider to adjust transparency from ultra-clear to fully tinted, which addresses the readability complaints about macOS Tahoe.</p>
</li>
<li><p><strong>The Passwords app can fix weak passwords.</strong> The Passwords app finds compromised passwords and updates them on supported sites for you. It's one less reason to use a third-party password manager.</p>
</li>
<li><p><strong>Safari groups tabs by topic.</strong> Also, in the Safari browser, a Notify Me feature watches a page and tells you when it changes, for ordering tickets or similar tasks.</p>
</li>
<li><p><strong>Access to other apps' data is more restricted.</strong> Apps that try to read another developer's app data containers are now denied access by default, instead of prompting for permission. You can manage access in <code>System Settings</code> &gt; <code>Privacy &amp; Security</code>. In the ongoing trade of convenience for greater security, Apple has tightened permissions.</p>
</li>
</ul>
<p>Finally, in the wait for the blossoming of Apple Intelligence, macOS 27 delivers Siri AI as a beta, in English only (and not for every country). For a more detailed feature list, see my Mac Install Guide article <a href="https://mac.install.guide/macos/macos27">macOS 27 Golden Gate</a>.</p>
<h2 id="heading-the-new-fm-command">The New fm Command</h2>
<p>macOS 27 adds a built-in command-line interface to Apple's on-device language model. A command called <code>fm</code> (for "Foundation Models") runs Apple's on-device language model from any terminal application, with no account, no API key, and no per-token cost.</p>
<p>Apple will also offer a Private Cloud Compute (PCC) option for <a href="https://support.apple.com/en-us/121115">Apple Intelligence</a>, which has usage limits and is designed for harder tasks, but I haven't seen it yet.</p>
<p>I've written more about the <code>fm</code> command in my article <a href="https://mac.install.guide/terminal/fm-command">fm Command for Apple AI</a>.</p>
<p>Before you can use it, you'll have to accept Apple's terms with <code>sudo fm license</code>, which needs an administrator password. macOS downloads the on-device model separately after the macOS update. You can check whether the model is ready:</p>
<pre><code class="language-bash">$ fm available
System model available
</code></pre>
<p>If you see <code>modelNotReady</code>, leave the Mac on power and Wi-Fi and check again later.</p>
<p>The <code>fm</code> command is a tool that accesses the on-device language model, which isn't a frontier model like Anthropic's Claude, OpenAI's ChatGPT, or Google's Gemini. <a href="https://developer.apple.com/documentation/foundationmodels/generating-content-and-performing-tasks-with-foundation-models">Apple's own documentation</a> says to avoid writing code, doing math, and logical reasoning with this model.</p>
<p>I asked it five questions a stuck beginner might actually type, and none of its answers was fully correct. When I asked how to use a nonexistent <code>brew update-all</code> command, it invented instructions instead of correcting my question.</p>
<p>You can play around to see if it could be useful for scripting or applications, as the best use of the <code>fm</code> command is to trial the Foundation Models framework when building applications.</p>
<h2 id="heading-before-you-start">Before You Start</h2>
<p>Again, Apple Silicon is a requirement. After that, there are a few things to consider:</p>
<p>The first is <strong>disk space.</strong> Apple's installer is large, so allow about 60 GB free.</p>
<p>The next is <strong>power.</strong> Connect your Mac before you begin. A software upgrade needs at least 20 percent battery to start.</p>
<p>Finally, consider a <strong>backup.</strong> If your work lives in GitHub or other cloud services, and the Mac holds nothing irreplaceable, you don't need to worry about backups. Otherwise, make a Time Machine backup to an external drive, or use a cloud backup service like Backblaze or IDrive.</p>
<h2 id="heading-how-to-upgrade-to-macos-27">How to Upgrade to macOS 27</h2>
<p>Two choices deliver exactly the same macOS, but the download and installation steps differ.</p>
<p>Downloading Apple's full installer package in a browser can be substantially faster than using Software Update. If Software Update seems slow, don't assume you've got slow internet. <a href="https://mac.install.guide/terminal/open">Open a terminal application</a> and measure it:</p>
<pre><code class="language-bash">$ networkQuality -v
...
==== SUMMARY ====
Uplink capacity: 313.557 Mbps
Downlink capacity: 131.295 Mbps
</code></pre>
<p>The test takes about fifteen seconds. <code>Downlink capacity</code> is the number that matters. If it's healthy (above 100 Mbps) and Software Update is crawling on a fast connection, try downloading the package directly.</p>
<h3 id="heading-download-the-full-installer-instead">Download the Full Installer Instead</h3>
<p>Apple publishes a package installer, <code>InstallAssistant.pkg</code>, on its own download server. A web browser downloads it at full speed and resumes on its own if it stops.</p>
<p>Apple doesn't link that file from its support pages, so get the link from <a href="https://mac.install.guide/macos/download">Download macOS</a>, which I've updated for the current release. Check your browser's downloads list and confirm the address starts with <code>swcdn.apple.com</code>, which is Apple's own domain.</p>
<p>You can also let Apple's own command fetch it with a terminal command, but it's not as fast as the browser download:</p>
<pre><code class="language-bash">$ softwareupdate --fetch-full-installer --full-installer-version 27.0
</code></pre>
<p>The command places the installer app in your Applications folder. Launch the app to begin the upgrade, skipping the package verification step below.</p>
<h3 id="heading-verify-the-package-came-from-apple">Verify the Package Came From Apple</h3>
<p>If you've downloaded the package installer, confirm the file is Apple's genuine installer before you run it:</p>
<pre><code class="language-bash">$ pkgutil --check-signature ~/Downloads/InstallAssistant.pkg
Status: signed Apple Software
</code></pre>
<p>Look for a certificate chain that ends with <code>Apple Root CA</code>. If you see anything else, delete the file. The check runs locally, so it protects you wherever the link came from.</p>
<h3 id="heading-run-the-installer">Run the Installer</h3>
<p>After the download, double-click <code>InstallAssistant.pkg</code> and follow the onscreen instructions. This installs an application named <code>Install macOS Golden Gate</code> in your Applications folder. It doesn't yet upgrade macOS.</p>
<p>Open that application and follow the steps:</p>
<ol>
<li><p>Click "Continue" and agree to the license.</p>
</li>
<li><p>Select your startup disk.</p>
</li>
<li><p>Enter your password to begin.</p>
</li>
<li><p>Wait about an hour. Your Mac restarts several times, which is normal.</p>
</li>
</ol>
<h3 id="heading-or-use-software-update">Or Use Software Update</h3>
<p>If you'd rather not download anything yourself, the standard path works fine and needs no link:</p>
<ol>
<li><p>Open <code>System Settings</code> and click <code>General</code>, then <code>Software Update</code>.</p>
</li>
<li><p>Click "Upgrade Now" when macOS 27 appears.</p>
</li>
<li><p>Enter your password and wait for the download.</p>
</li>
</ol>
<p>The macOS 27 version is identical. The only difference is time.</p>
<h2 id="heading-check-your-developer-tools-after-the-upgrade">Check Your Developer Tools After the Upgrade</h2>
<p>First confirm you're on macOS 27:</p>
<pre><code class="language-bash">$ sw_vers
ProductName:		macOS
ProductVersion:		27.0
BuildVersion:		26A428
</code></pre>
<p>I've built a free downloadable application named "Set Up Your Mac for the Command Line" that you can use to get your Mac ready for software development. It checks what you have and installs Xcode Command Line Tools and Homebrew if they're missing. It fixes the shell configuration problem that causes a <code>command not found</code> error and verifies your Mac is set up to use the command line to develop software.</p>
<p><a href="https://mac.install.guide/set-up-your-mac/command-line">Here are all the details about the app</a> before you download. Click <a href="https://downloads.install.guide/suym-cli/Set-Up-Your-Mac-for-the-Command-Line.dmg?utm_source=freecodecamp-macos-27-developers&amp;utm_medium=article&amp;utm_campaign=suym-cli_setup&amp;utm_term=freecodecamp">Set Up Your Mac for the Command Line</a> to download it from my Mac Install Guide website.</p>
<p>You can perform your own check, of course, for the tools that are basic to software development:</p>
<pre><code class="language-bash">$ xcode-select -p
/Library/Developer/CommandLineTools
$ brew --version
Homebrew 6.0.15
$ git --version
git version 2.50.1 (Apple Git-155)
</code></pre>
<p>You're checking that each command responds. Your version numbers may differ. If you have the full Xcode application installed for developing macOS and iOS applications, <code>xcode-select -p</code> will point inside <code>Xcode.app</code>.</p>
<p>If <code>xcode-select -p</code> reports no developer tools, you may need to <a href="https://mac.install.guide/commandlinetools/4">reinstall Xcode Command Line Tools with <code>xcode-select --install</code></a>.</p>
<p>If <code>brew --version</code> reports <code>command not found</code>, Homebrew may be installed but your shell isn't finding it. See <a href="https://mac.install.guide/homebrew/zsh-command-not-found-brew">command not found: brew</a> for how to add it to your PATH.</p>
<p>Git version control will be ready if Xcode Command Line Tools is installed.</p>
<h2 id="heading-whats-next">What's Next</h2>
<p>You now have macOS 27 running on your Mac. You've verified that Xcode Command Line Tools, Homebrew, and Git version control all came through the upgrade.</p>
<p>If you want to <a href="https://mac.install.guide/macos/reinstall">reinstall macOS</a> on an empty disk for a clean install, or build a <a href="https://mac.install.guide/macos/bootable-usb">macOS bootable USB drive</a> for portable installs, the article <a href="https://mac.install.guide/macos/upgrade">Upgrade macOS</a> goes into more detail.</p>
<p>With macOS 27 installed and your tools verified, you're up to date and ready for any other Mac tutorial you'll find on freeCodeCamp.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build a Basic Discord Storytelling, Chat, and Mental Wellness Bot with Python ]]>
                </title>
                <description>
                    <![CDATA[ Discord bots can look surprisingly complicated when you see them in action. A bot can respond to messages, tell stories, remember parts of conversations, and stay online around the clock. When I first ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-build-a-basic-discord-bot-with-python/</link>
                <guid isPermaLink="false">6a7f44fc58366ecdaf016624</guid>
                
                    <category>
                        <![CDATA[ software development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ bot ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python 3 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Beginner Developers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ techblog ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Eva J Patel ]]>
                </dc:creator>
                <pubDate>Fri, 14 Aug 2026 16:40:28 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/6a444c51-d332-4915-aa1f-326b57b17472.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Discord bots can look surprisingly complicated when you see them in action. A bot can respond to messages, tell stories, remember parts of conversations, and stay online around the clock.</p>
<p>When I first started looking into how they worked, I assumed there had to be a huge amount of complicated code behind all of it.</p>
<p>But the basic idea is actually pretty simple.</p>
<p>At its core, a Discord bot is just a Python program that connects to Discord, waits for something to happen, and then decides how to respond. Once you understand that basic idea, you can start adding features one at a time and turn a simple bot into something much more interesting.</p>
<p>In this tutorial, we'll start with a very small bot and gradually build it into something more capable. Along the way, you'll learn about Discord commands, events, asynchronous Python, user state, environment variables, and basic deployment.</p>
<p>One quick disclaimer before we start: the mental-wellness feature that we'll be integrating in this bot in this project is <strong>not therapy</strong>, and the bot is not a therapist or medical professional. It should only provide general supportive suggestions and encourage users to reach out to a trusted person when appropriate.</p>
<p>With that out of the way, let's get coding!</p>
<h3 id="heading-what-well-cover">What We'll Cover:</h3>
<ul>
<li><p><a href="#heading-what-were-building">What We're Building</a></p>
</li>
<li><p><a href="#heading-what-you-need">What You Need</a></p>
</li>
<li><p><a href="#heading-create-the-discord-bot">Create the Discord Bot</a></p>
</li>
<li><p><a href="#heading-give-the-bot-permission-to-read-messages">Give the Bot Permission to Read Messages</a></p>
</li>
<li><p><a href="#heading-create-the-project">Create the Project</a></p>
</li>
<li><p><a href="#heading-create-a-virtual-environment">Create a Virtual Environment</a></p>
</li>
<li><p><a href="#heading-install-discordpy">Install discord.py</a></p>
</li>
<li><p><a href="#heading-create-your-first-bot">Create Your First Bot</a></p>
<ul>
<li><p><a href="#heading-importing-our-libraries">Importing Our Libraries</a></p>
</li>
<li><p><a href="#heading-loading-the-token">Loading the Token</a></p>
</li>
<li><p><a href="#heading-understanding-intents">Understanding Intents</a></p>
</li>
<li><p><a href="#heading-what-is-ctx">What Isctx?</a></p>
</li>
<li><p><a href="#heading-why-does-everything-say-async-and-await">Why Does Everything Sayasyncandawait?</a></p>
</li>
<li><p><a href="#heading-run-the-bot">Run the Bot</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-build-the-storytelling-system">Build the Storytelling System</a></p>
<ul>
<li><p><a href="#heading-lets-make-the-story-remember-the-user">Let's Make the Story Remember the User</a></p>
</li>
<li><p><a href="#heading-add-a-story-choice">Add a Story Choice</a></p>
</li>
<li><p><a href="#heading-add-a-casual-chat-command">Add a Casual Chat Command</a></p>
</li>
<li><p><a href="#heading-add-a-mental-wellness-support-feature">Add a Mental-Wellness Support Feature</a></p>
</li>
<li><p><a href="#heading-add-a-help-command">Add a Help Command</a></p>
</li>
<li><p><a href="#heading-improve-error-handling">Improve Error Handling</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-put-everything-together">Put Everything Together</a></p>
</li>
<li><p><a href="#heading-our-bot-doesnt-actually-remember-anything">Our Bot Doesn't Actually Remember Anything</a></p>
<ul>
<li><p><a href="#heading-create-the-database">Create the Database</a></p>
</li>
<li><p><a href="#heading-save-a-users-story">Save a User's Story</a></p>
</li>
<li><p><a href="#heading-get-the-story-back">Get the Story Back</a></p>
</li>
<li><p><a href="#heading-put-it-into-a-command">Put It Into a Command</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-adding-real-ai-chat">Adding Real AI Chat</a></p>
<ul>
<li><p><a href="#heading-install-the-hugging-face-library">Install the Hugging Face Library</a></p>
</li>
<li><p><a href="#heading-create-the-hugging-face-client">Create the Hugging Face Client</a></p>
</li>
<li><p><a href="#heading-connect-the-ai-model-to-the-bot">Connect the AI Model to the Bot</a></p>
</li>
<li><p><a href="#heading-handle-ai-errors">Handle AI Errors</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-how-do-we-keep-the-bot-online">How Do We Keep the Bot Online?</a></p>
<ul>
<li><p><a href="#heading-option-1-run-it-on-your-computer">Option 1: Run It on Your Computer</a></p>
</li>
<li><p><a href="#heading-option-2-host-it-on-a-server">Option 2: Host It on a Server</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-what-forever-actually-means">What "Forever" Actually Means</a></p>
</li>
<li><p><a href="#heading-dont-try-to-keep-it-awake-with-random-tricks">Don't Try to "Keep It Awake" With Random Tricks</a></p>
</li>
<li><p><a href="#heading-additional-features-and-where-to-go-next">Additional Features and Where to Go Next</a></p>
</li>
<li><p><a href="#heading-test-everything-locally-first">Test Everything Locally First</a></p>
</li>
<li><p><a href="#heading-deploying-the-bot">Deploying the Bot</a></p>
<ul>
<li><a href="#heading-the-start-command">The Start Command</a></li>
</ul>
</li>
<li><p><a href="#heading-remember-keep-your-secrets-secret">Remember: Keep Your Secrets Secret</a></p>
</li>
<li><p><a href="#heading-what-you-learned">What You Learned</a></p>
</li>
<li><p><a href="#heading-final-thoughts">Final Thoughts</a></p>
</li>
</ul>
<h2 id="heading-what-were-building">What We're Building</h2>
<p>Our finished bot will have several commands:</p>
<pre><code class="language-text">!hello
!story
!chat hello!
!support I'm having a stressful day
!help
</code></pre>
<p>For example:</p>
<pre><code class="language-text">User:
!story

Bot:
You wake up inside an abandoned library.

There are three doors in front of you:

1. A red wooden door
2. A metal door covered in strange symbols
3. A staircase leading underground

Which one do you choose?
</code></pre>
<p>The user can then continue the story.</p>
<p>For chat:</p>
<pre><code class="language-text">User:
!chat What's a good way to learn Python?

Bot:
Try building small projects instead of only reading tutorials.
A Discord bot is actually a pretty fun project to start with.
</code></pre>
<p>And for mental-wellness support:</p>
<pre><code class="language-text">User:
!support I'm really stressed about school.

Bot:
That sounds like a lot to deal with. You could try breaking
the work into one small task at a time and taking a short
break between tasks.

I'm a bot, not a therapist, so if you need personal support,
consider talking with someone you trust.
</code></pre>
<p>The goal isn't to make a magical robot therapist. It's to build a useful bot while learning how Discord APIs, Python functions, events, asynchronous programming, and basic conversational logic fit together.</p>
<h2 id="heading-what-you-need">What You Need</h2>
<p>You only need a few things:</p>
<ul>
<li><p>Python (version 3.8+ is recommended)</p>
</li>
<li><p>A Discord account</p>
</li>
<li><p>A Discord server where you have permission to add a bot</p>
</li>
<li><p>A code editor (I personally prefer VS Code or PyCharm)</p>
</li>
<li><p>The <code>discord.py</code> library</p>
</li>
</ul>
<p>We'll also use Python's built-in <code>os</code> module for reading environment variables.</p>
<p>If you don't already have Python installed, install a current supported version of Python from the official Python website.</p>
<p>Then check that Python works:</p>
<pre><code class="language-bash">python --version
</code></pre>
<p>You should see something similar to:</p>
<pre><code class="language-text">Python 3.x.x
</code></pre>
<h2 id="heading-create-the-discord-bot">Create the Discord Bot</h2>
<p>Before Python can control Discord, we need to create a Discord application.</p>
<p>Go to the Discord Developer Portal: <a href="https://discord.com/developers/applications">https://discord.com/developers/applications</a></p>
<img src="https://cdn.hashnode.com/uploads/covers/6a581501af6af179dc1987d5/64a5aac8-fb53-42d0-9b91-fb6453b3eb1d.png" alt="Picture of the discord developer application page" style="display: block;" width="2398" height="1396" loading="lazy">

<p>This is what the page will look like, you might need to login with your discord email/username and password before you start.</p>
<p>Click on the "New Application" button on the top right and give your bot a name. For this tutorial, let's call ours <code>StoryBot</code>.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6a581501af6af179dc1987d5/84bd2f32-941c-4de2-8e6b-30ab22cc5ba1.png" alt="Picture of what it looks like when you click on the &quot;New Application&quot; button" style="display: block;" width="2397" height="1303" loading="lazy">

<p>The application is basically the home for your bot.</p>
<p>Discord's developer platform provides the tools needed to create and configure applications and bots.</p>
<p>Once you've created the application, open its <strong>Bot</strong> section and create the bot user. You can add your own icon picture and your own banner if you want to.</p>
<p>You will then go to the <strong>Token</strong> section and click on "Reset Token" to generate your token. Treat that token like a password. Do <strong>NOT</strong> put it directly into your Python source code.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6a581501af6af179dc1987d5/7537d64e-706c-43b9-a574-746294703f6d.png" alt="Picture of what the Token part in the Bots section looks like" style="display: block;" width="1894" height="189" loading="lazy">

<p>Never do this:</p>
<pre><code class="language-python">bot.run("my-secret-token")
</code></pre>
<p>And definitely don't upload a token to GitHub or commit it to source control. Instead, we'll store it in an environment variable, which we'll talk about later.</p>
<h2 id="heading-give-the-bot-permission-to-read-messages">Give the Bot Permission to Read Messages</h2>
<p>Our bot needs to see the messages that contain commands.</p>
<p>Discord uses something called <strong>Gateway Intents</strong> to control which types of events a bot receives. The <code>discord.py</code> documentation explains that intents must be enabled both in your code and, for privileged intents, in the Discord Developer Portal.</p>
<p>In the Developer Portal, find:</p>
<pre><code class="language-text">Bot
→ Privileged Gateway Intents
</code></pre>
<p>Enable:</p>
<pre><code class="language-text">Message Content Intent
</code></pre>
<p>It should look somewhat like this:</p>
<img src="https://cdn.hashnode.com/uploads/covers/6a581501af6af179dc1987d5/0273691f-8723-41d3-8cfc-d59656dfb6e2.png" alt="What should the &quot;Message Content Intent&quot; section look like" style="display: block;" width="1933" height="501" loading="lazy">

<p>We'll also enable it in Python, which we will talk about later in this article.</p>
<h2 id="heading-create-the-project">Create the Project</h2>
<p>Create a folder:</p>
<pre><code class="language-text">discord-story-bot/
</code></pre>
<p>Inside it, we'll eventually have:</p>
<pre><code class="language-text">discord-story-bot/
│
├── bot.py
├── requirements.txt
└── .env
</code></pre>
<p>The three important files are:</p>
<ul>
<li><p><code>bot.py</code>: our Python program</p>
</li>
<li><p><code>requirements.txt</code>: text file that contains the name of the packages our bot needs</p>
</li>
<li><p><code>.env</code>: our secret token during local development</p>
</li>
</ul>
<h2 id="heading-create-a-virtual-environment">Create a Virtual Environment</h2>
<p>Open your terminal inside the project folder.</p>
<p>Run:</p>
<pre><code class="language-bash">python -m venv venv
</code></pre>
<p>Then activate it.</p>
<p>On Windows:</p>
<pre><code class="language-bash">venv\Scripts\activate
</code></pre>
<p>On macOS/Linux:</p>
<pre><code class="language-bash">source venv/bin/activate
</code></pre>
<p>A virtual environment gives this project its own little Python bubble.</p>
<p>That means packages installed for this bot won't randomly interfere with packages used by another project.</p>
<h2 id="heading-install-discordpy">Install discord.py</h2>
<p>Now install the Discord library:</p>
<pre><code class="language-bash">pip install -U discord.py
</code></pre>
<p>The official <code>discord.py</code> documentation uses this installation approach for setting up the library.</p>
<p>We'll also install <code>python-dotenv</code>, which makes reading our local <code>.env</code> file easier:</p>
<pre><code class="language-bash">pip install python-dotenv
</code></pre>
<p>Then save the dependencies:</p>
<pre><code class="language-bash">pip freeze &gt; requirements.txt
</code></pre>
<p>Your <code>requirements.txt</code> should contain the packages needed by the project.</p>
<h2 id="heading-create-your-first-bot">Create Your First Bot</h2>
<p>Let's start small.</p>
<p>Open <code>bot.py</code>:</p>
<pre><code class="language-python">import os

import discord
from discord.ext import commands
from dotenv import load_dotenv


load_dotenv()

TOKEN = os.getenv("DISCORD_TOKEN")

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(
    command_prefix="!",
    intents=intents
)


@bot.event
async def on_ready():
    print(f"Logged in as {bot.user}")


@bot.command()
async def hello(ctx):
    await ctx.send("Hello! I'm online.")


bot.run(TOKEN)
</code></pre>
<p>That is already a functional Discord bot.</p>
<p>Let's break it apart piece by piece.</p>
<h3 id="heading-importing-our-libraries">Importing Our Libraries</h3>
<p>First:</p>
<pre><code class="language-python">import os
</code></pre>
<p><code>os</code> lets Python communicate with parts of the operating system.</p>
<p>We'll use it to read environment variables.</p>
<p>Next:</p>
<pre><code class="language-python">import discord
</code></pre>
<p>This imports <code>discord.py</code>.</p>
<p>Then:</p>
<pre><code class="language-python">from discord.ext import commands
</code></pre>
<p>The <code>commands</code> extension makes creating commands much easier.</p>
<p>Instead of manually checking every message for something like <code>!hello</code>, we can write:</p>
<pre><code class="language-python">@bot.command()
async def hello(ctx):
    await ctx.send("Hello!")
</code></pre>
<p>The <code>discord.py</code> command system is built around Python functions decorated as commands.</p>
<p>Finally:</p>
<pre><code class="language-python">from dotenv import load_dotenv
</code></pre>
<p>This lets us load values from our <code>.env</code> file.</p>
<h3 id="heading-loading-the-token">Loading the Token</h3>
<p>Our bot needs a token to connect our Python program to Discord. Think of the token as a password that allows our program to authenticate as the bot.</p>
<p>We don't want to put this secret directly into our Python code. Instead, we'll store it in an environment variable.</p>
<p>First, install <code>python-dotenv</code>:</p>
<pre><code class="language-bash">pip install python-dotenv
</code></pre>
<p>This package lets Python read values from a <code>.env</code> file.</p>
<p>Now create a new file called <code>.env</code> in the same folder as <code>bot.py</code>.</p>
<p>Inside <code>.env</code>, add:</p>
<pre><code class="language-text">DISCORD_TOKEN=YOUR_BOT_TOKEN_HERE
</code></pre>
<p>Replace <code>YOUR_BOT_TOKEN_HERE</code> with the token you copied from the Discord Developer Portal.</p>
<p>Your file should look something like this:</p>
<pre><code class="language-text">DISCORD_TOKEN=your_actual_token_here
</code></pre>
<p>Don't share this token with anyone or upload your <code>.env</code> file to GitHub. Your bot token should be treated like a password.</p>
<p>To make sure Git doesn't accidentally include the <code>.env</code> file in a repository, create a file called <code>.gitignore</code> in your project folder and add:</p>
<pre><code class="language-text">.env
venv/
__pycache__/
</code></pre>
<p>Now let's load the token in Python.</p>
<p>At the top of <code>bot.py</code>, add:</p>
<pre><code class="language-python">import os
from dotenv import load_dotenv
</code></pre>
<p>Then add:</p>
<pre><code class="language-python">load_dotenv()
</code></pre>
<p>This tells Python to look for the <code>.env</code> file and load the variables inside it.</p>
<p>Now we can get our Discord token:</p>
<pre><code class="language-python">TOKEN = os.getenv("DISCORD_TOKEN")
</code></pre>
<p><code>os.getenv()</code> looks for the environment variable named <code>"DISCORD_TOKEN"</code> and gives us its value.</p>
<p>We can also check that the token was actually found:</p>
<pre><code class="language-python">if not TOKEN:
    raise RuntimeError("DISCORD_TOKEN is not set.")
</code></pre>
<p>If Python can't find the token, the program stops and gives us a clear error message instead of failing later in a confusing way.</p>
<h3 id="heading-understanding-intents">Understanding Intents</h3>
<p>Remember how we talked about enabling message content readability in python? We are going to do that now.</p>
<p>Add:</p>
<pre><code class="language-python">intents = discord.Intents.default()
intents.message_content = True
</code></pre>
<p>The first line creates a set of Discord's default intents.</p>
<p>The second line tells Discord that our bot needs access to message content.</p>
<p>Now we need to give these intents to our bot when we create it:</p>
<pre><code class="language-python">bot = commands.Bot(
    command_prefix="!",
    intents=intents
)
</code></pre>
<p>The <code>command_prefix="!"</code> means our bot will recognize commands that begin with <code>!</code>.</p>
<p>For example:</p>
<pre><code class="language-text">!hello
</code></pre>
<p>The <code>intents=intents</code> part gives our bot the permissions we configured above.</p>
<p>There are two steps here because Discord needs to know that our bot is allowed to receive message content, while our Python program also needs to tell Discord that it wants to receive it.</p>
<p>Our basic setup should now look like this:</p>
<pre><code class="language-python">import os
import discord

from dotenv import load_dotenv
from discord.ext import commands

load_dotenv()

TOKEN = os.getenv("DISCORD_TOKEN")

if not TOKEN:
    raise RuntimeError("DISCORD_TOKEN is not set.")

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(
    command_prefix="!",
    intents=intents
)
</code></pre>
<p>Now our bot has its token safely loaded and <code>discord.py</code> knows which intents to request when it connects to Discord.</p>
<h3 id="heading-what-is-ctx">What Is <code>ctx</code>?</h3>
<p>This part can look weird when you're learning Discord bots:</p>
<pre><code class="language-python">async def hello(ctx):
</code></pre>
<p>What is <code>ctx</code>? <code>ctx</code> stands for <strong>context</strong>. It contains information about the command that was used.</p>
<p>For example, it can tell us:</p>
<ul>
<li><p>Who ran the command</p>
</li>
<li><p>Which server it came from</p>
</li>
<li><p>Which channel it came from</p>
</li>
<li><p>What message triggered it</p>
</li>
</ul>
<p>Then:</p>
<pre><code class="language-python">await ctx.send("Hello!")
</code></pre>
<p>means:</p>
<blockquote>
<p>"Send this message back to the place where the command was used."</p>
</blockquote>
<h3 id="heading-why-does-everything-say-async-and-await">Why Does Everything Say <code>async</code> and <code>await</code>?</h3>
<p>You might notice:</p>
<pre><code class="language-python">async def hello(ctx):
</code></pre>
<p>and:</p>
<pre><code class="language-python">await ctx.send(...)
</code></pre>
<p>Discord bots spend a lot of time waiting.</p>
<p>They wait for:</p>
<ul>
<li><p>Messages</p>
</li>
<li><p>Discord responses</p>
</li>
<li><p>API requests</p>
</li>
<li><p>Timers</p>
</li>
<li><p>Other events</p>
</li>
</ul>
<p>Python's asynchronous programming features allow the bot to wait for these operations without freezing everything else.</p>
<p>You don't need to become an async-programming expert before building your first bot.</p>
<p>For now, think of <code>await</code> as:</p>
<blockquote>
<p>"Pause this task until this operation finishes, while letting the bot handle other things."</p>
</blockquote>
<h3 id="heading-run-the-bot">Run the Bot</h3>
<p>Start it with:</p>
<pre><code class="language-bash">python bot.py
</code></pre>
<p>If everything works, your terminal should print something similar to:</p>
<pre><code class="language-text">Logged in as StoryBot
</code></pre>
<p>Now go to your Discord server and type <code>!hello</code>. Your bot should respond.</p>
<p>Congratulations! You've officially made a Discord bot.</p>
<p>Now let's make it interesting.</p>
<h2 id="heading-build-the-storytelling-system">Build the Storytelling System</h2>
<p>First, we're going to create an interactive storytelling command.</p>
<p>At the top of <code>bot.py</code>, add:</p>
<pre><code class="language-python">import random
</code></pre>
<p>Then create some story ingredients:</p>
<pre><code class="language-python">story_locations = [
    "an abandoned library",
    "a mysterious island",
    "a futuristic city",
    "a hidden underground laboratory",
    "a forest that never appears on maps"
]

story_items = [
    "a glowing key",
    "an ancient notebook",
    "a strange compass",
    "a locked metal box",
    "a mysterious photograph"
]

story_events = [
    "You hear footsteps behind you.",
    "The lights suddenly turn off.",
    "A hidden door opens nearby.",
    "Your phone starts displaying a message from an unknown sender.",
    "You notice that the room has changed."
]
</code></pre>
<p>Now create the command:</p>
<pre><code class="language-python">@bot.command()
async def story(ctx):
    location = random.choice(story_locations)
    item = random.choice(story_items)
    event = random.choice(story_events)

    story_text = (
        f"You wake up in {location}.\n\n"
        f"Next to you is {item}.\n\n"
        f"{event}\n\n"
        "What do you do?"
    )

    await ctx.send(story_text)
</code></pre>
<p>Now <code>!story</code> might produce:</p>
<pre><code class="language-text">You wake up in a futuristic city.

Next to you is an ancient notebook.

A hidden door opens nearby.

What do you do?
</code></pre>
<p>Run it again and you might get something completely different.</p>
<p>That's because of:</p>
<pre><code class="language-python">random.choice(...)
</code></pre>
<p>Python randomly picks one item from each list.</p>
<p>It's a simple technique, but suddenly your bot can generate hundreds of different combinations.</p>
<h3 id="heading-lets-make-the-story-remember-the-user">Let's Make the Story Remember the User</h3>
<p>Random stories are fun, but interactive stories are much better when the bot remembers what happened.</p>
<p>We can create a dictionary:</p>
<pre><code class="language-python">user_stories = {}
</code></pre>
<p>The dictionary will store story information for each user.</p>
<p>For example:</p>
<pre><code class="language-text">user ID → current story
</code></pre>
<p>Now let's modify the story command:</p>
<pre><code class="language-python">@bot.command()
async def story(ctx):
    user_id = ctx.author.id

    location = random.choice(story_locations)
    item = random.choice(story_items)
    event = random.choice(story_events)

    user_stories[user_id] = {
        "location": location,
        "item": item,
        "event": event
    }

    await ctx.send(
        f"You wake up in {location}.\n\n"
        f"Next to you is {item}.\n\n"
        f"{event}\n\n"
        "What do you do?"
    )
</code></pre>
<p>Now each user can have their own active story.</p>
<h3 id="heading-add-a-story-choice">Add a Story Choice</h3>
<p>Let's give users choices.</p>
<pre><code class="language-python">@bot.command()
async def choose(ctx, choice: str):
    user_id = ctx.author.id

    if user_id not in user_stories:
        await ctx.send("You don't have an active story. Try `!story` first.")
        return

    choice = choice.lower()

    if choice == "left":
        response = (
            "You head left and discover a room filled with old maps. "
            "One of them has your name written on it."
        )

    elif choice == "right":
        response = (
            "You head right and find a staircase leading toward "
            "a strange blue light."
        )

    else:
        response = "Try choosing `left` or `right`."

    await ctx.send(response)
</code></pre>
<p>Now users can type:</p>
<pre><code class="language-text">!choose left
</code></pre>
<p>or:</p>
<pre><code class="language-text">!choose right
</code></pre>
<p>Notice this:</p>
<pre><code class="language-python">async def choose(ctx, choice: str):
</code></pre>
<p>The <code>choice</code> parameter receives the text after the command.</p>
<p>So:</p>
<pre><code class="language-text">!choose left
</code></pre>
<p>becomes approximately:</p>
<pre><code class="language-python">choice = "left"
</code></pre>
<p>This is one of the reasons command frameworks are so convenient. A <strong>command framework</strong> is a set of tools that makes it easier to create and manage commands in a program. In our case, <code>discord.py</code> provides the command framework that lets us turn Python functions into Discord commands using decorators like <code>@bot.command()</code>.</p>
<p>Instead of manually checking every message to figure out whether someone typed <code>!choose</code>, <code>discord.py</code> handles that work for us. It recognizes the command, takes the user's arguments, and passes them to our function.</p>
<p>So when someone types:</p>
<pre><code class="language-text">!choose left
</code></pre>
<p><code>discord.py</code> knows that choose is the command, <code>"left"</code> is the argument, and that it should call our <code>choose()</code> function with that information.</p>
<h3 id="heading-add-a-casual-chat-command">Add a Casual Chat Command</h3>
<p>Now let's make the bot capable of basic conversation.</p>
<p>We could connect it to a large language model API, but you don't actually need AI to learn how a chat command works. We'll start with a simple keyword-based response system.</p>
<p>First, we'll create a dictionary containing some keywords and possible responses:</p>
<pre><code class="language-python">chat_responses = {
    "hello": [
        "Hey! What's up?",
        "Hello! How's your day going?",
        "Hi! What are you working on?"
    ],
    "python": [
        "Python is a great language for beginners because its syntax is pretty readable.",
        "If you're learning Python, try building something instead of only watching tutorials."
    ],
    "discord": [
        "Discord bots are a fun way to practice Python because you get instant feedback.",
        "Once you understand commands and events, you can build some surprisingly complex bots."
    ]
}

Think of `chat_responses` as a small collection of things our bot knows how to talk about. Each key, such as `"python"` or `"discord"`, represents a keyword the bot can look for. The value associated with each key is a list of possible responses.

We use a list instead of a single response so the bot doesn't give exactly the same answer every time. Later, we'll randomly choose one of these responses.

Now let's create the actual `!chat` command:

```python
@bot.command()
async def chat(ctx, *, message: str):
    text = message.lower()

    for keyword, responses in chat_responses.items():
        if keyword in text:
            await ctx.send(random.choice(responses))
            return

    await ctx.send(
        "I'm still learning how to respond to that. "
        "Try talking to me about Python or Discord!"
    )
</code></pre>
<p>There are a few things happening here, so let's break it down.</p>
<p>First, this part:</p>
<pre><code class="language-python">@bot.command()
async def chat(ctx, *, message: str):
</code></pre>
<p>turns the <code>chat()</code> function into a Discord command. The <code>*</code> is important because it tells <code>discord.py</code> to treat everything after the command as one argument.</p>
<p>For example, if someone types:</p>
<pre><code class="language-text">!chat I want to learn Python
</code></pre>
<p>the entire phrase after <code>!chat</code> becomes the value of <code>message</code>:</p>
<pre><code class="language-python">message = "I want to learn Python"
</code></pre>
<p>Next, we have:</p>
<pre><code class="language-python">text = message.lower()
</code></pre>
<p>This converts the message to lowercase. That means <code>Python</code>, <code>python</code>, and <code>PYTHON</code> will all become <code>python</code>. Without this, our keyword check could miss a match simply because the user capitalized a word differently.</p>
<p>Now we get to the loop:</p>
<pre><code class="language-python">for keyword, responses in chat_responses.items():
</code></pre>
<p><code>.items()</code> lets us go through both the keyword and its corresponding list of responses. During each loop, <code>keyword</code> contains something like <code>"python"</code>, while <code>responses</code> contains the list of responses associated with it.</p>
<p>Then we check:</p>
<pre><code class="language-python">if keyword in text:
</code></pre>
<p>This asks whether the current keyword appears anywhere in the user's message.</p>
<p>If the user writes:</p>
<pre><code class="language-text">!chat I want to learn Python
</code></pre>
<p>the lowercase version becomes:</p>
<pre><code class="language-text">i want to learn python
</code></pre>
<p>Since <code>"python"</code> appears inside that text, the condition is true.</p>
<p>The bot can then choose a random response:</p>
<pre><code class="language-python">await ctx.send(random.choice(responses))
</code></pre>
<p><code>random.choice()</code> picks one item from the response list, while <code>ctx.send()</code> sends that response back to the Discord channel.</p>
<p>Finally, we have:</p>
<pre><code class="language-python">return
</code></pre>
<p>This stops the function after a matching keyword is found. Without it, the loop would continue checking the other keywords even after the bot had already responded.</p>
<p>But what happens if none of the keywords match?</p>
<p>That's what this part handles:</p>
<pre><code class="language-python">await ctx.send(
    "I'm still learning how to respond to that. "
    "Try talking to me about Python or Discord!"
)
</code></pre>
<p>If the loop finishes without finding a keyword, the bot sends this fallback message instead.</p>
<p>For example:</p>
<pre><code class="language-text">!chat I like pizza
</code></pre>
<p>doesn't contain <code>"hello"</code>, <code>"python"</code>, or <code>"discord"</code>, so the bot doesn't have a specific response to use.</p>
<p>This gives us a simple way for the bot to have conversations without needing an AI model.</p>
<h3 id="heading-add-a-mental-wellness-support-feature">Add a Mental-Wellness Support Feature</h3>
<p>Now for the feature that needs a little more care.</p>
<p>Instead of calling this a "therapy command" internally, we'll call it:</p>
<pre><code class="language-text">!support
</code></pre>
<p>Quick additional disclaimer before we start...this is just a fun wellness script, not a real therapist!</p>
<p>Create:</p>
<pre><code class="language-python">support_responses = {
    "stress": [
        "That sounds like a lot to handle. Try breaking the situation into one small task at a time.",
        "When everything feels overwhelming, it can help to pause and focus on what needs attention right now."
    ],

    "school": [
        "School can pile up quickly. Consider choosing one assignment to work on first instead of trying to solve everything at once.",
        "If school stress is getting difficult to manage, talking with a trusted person can make things feel less like something you have to handle alone."
    ],

    "sad": [
        "I'm sorry you're having a difficult moment. Taking a short break, doing something calming, or talking with someone you trust may help.",
        "You don't have to solve everything immediately. Give yourself some time and consider reaching out to someone you trust."
    ]
}
</code></pre>
<p>Now create the command:</p>
<pre><code class="language-python">@bot.command()
async def support(ctx, *, message: str):
    text = message.lower()

    for keyword, responses in support_responses.items():
        if keyword in text:
            response = random.choice(responses)

            await ctx.send(
                f"{response}\n\n"
                "I'm a bot, not a therapist or medical professional. "
                "If you need personal support, consider talking with "
                "someone you trust."
            )
            return

    await ctx.send(
        "It sounds like something is bothering you. "
        "I can offer general wellness suggestions, but I'm not a therapist. "
        "If you need personal support, consider reaching out to someone you trust."
    )
</code></pre>
<p>Now someone can type:</p>
<pre><code class="language-text">!support I'm stressed about school
</code></pre>
<p>The bot sees the word:</p>
<pre><code class="language-text">school
</code></pre>
<p>and chooses one of the school-related responses.</p>
<p>This is deliberately simple.</p>
<p>For a real public bot, you'd want much more careful safety handling, testing, moderation, privacy protection, and escalation logic before allowing users to rely on it for sensitive situations.</p>
<h3 id="heading-add-a-help-command">Add a Help Command</h3>
<p>A good bot should explain itself.</p>
<pre><code class="language-python">@bot.command()
async def commands_help(ctx):
    await ctx.send(
        "**Available commands:**\n"
        "`!hello` - Say hello\n"
        "`!story` - Start a new story\n"
        "`!choose left` - Choose the left path\n"
        "`!choose right` - Choose the right path\n"
        "`!chat &lt;message&gt;` - Have a casual conversation\n"
        "`!support &lt;message&gt;` - Get general wellness support"
    )
</code></pre>
<p>There's one small issue.</p>
<p>Discord's default help command is already called <code>help</code>.</p>
<p>So instead of:</p>
<pre><code class="language-python">async def help(ctx):
</code></pre>
<p>we've named ours:</p>
<pre><code class="language-python">commands_help
</code></pre>
<p>If you want the command itself to be called <code>!help</code>, you can write:</p>
<pre><code class="language-python">@bot.command(name="help")
async def commands_help(ctx):
    ...
</code></pre>
<p>That tells Discord:</p>
<blockquote>
<p>Use <code>!help</code> for this function even though the Python function has another name.</p>
</blockquote>
<h3 id="heading-improve-error-handling">Improve Error Handling</h3>
<p>Bots shouldn't crash just because someone enters an invalid command.</p>
<p>Add:</p>
<pre><code class="language-python">@bot.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.MissingRequiredArgument):
        await ctx.send(
            "You're missing something. Try `!help` to see how the command works."
        )

    elif isinstance(error, commands.CommandNotFound):
        return

    else:
        print(f"Error: {error}")
</code></pre>
<p>Now if someone types:</p>
<pre><code class="language-text">!chat
</code></pre>
<p>without giving the bot a message, it can respond with a useful explanation instead of dumping a confusing error into the conversation.</p>
<h2 id="heading-put-everything-together">Put Everything Together</h2>
<p>At this point, your <code>bot.py</code> can look like this:</p>
<pre><code class="language-python">import os
import random

import discord
from discord.ext import commands
from dotenv import load_dotenv


load_dotenv()

TOKEN = os.getenv("DISCORD_TOKEN")

if not TOKEN:
    raise RuntimeError("DISCORD_TOKEN is not set.")


intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(
    command_prefix="!",
    intents=intents
)


story_locations = [
    "an abandoned library",
    "a mysterious island",
    "a futuristic city",
    "a hidden underground laboratory",
    "a forest that never appears on maps"
]

story_items = [
    "a glowing key",
    "an ancient notebook",
    "a strange compass",
    "a locked metal box",
    "a mysterious photograph"
]

story_events = [
    "You hear footsteps behind you.",
    "The lights suddenly turn off.",
    "A hidden door opens nearby.",
    "Your phone starts displaying a message from an unknown sender.",
    "You notice that the room has changed."
]


user_stories = {}


chat_responses = {
    "hello": [
        "Hey! What's up?",
        "Hello! How's your day going?",
        "Hi! What are you working on?"
    ],

    "python": [
        "Python is a great language for beginners because its syntax is pretty readable.",
        "If you're learning Python, try building something instead of only watching tutorials."
    ],

    "discord": [
        "Discord bots are a fun way to practice Python because you get instant feedback.",
        "Once you understand commands and events, you can build some surprisingly complex bots."
    ]
}


support_responses = {
    "stress": [
        "That sounds like a lot to handle. Try breaking the situation into one small task at a time.",
        "When everything feels overwhelming, it can help to pause and focus on what needs attention right now."
    ],

    "school": [
        "School can pile up quickly. Consider choosing one assignment to work on first instead of trying to solve everything at once.",
        "If school stress is getting difficult to manage, talking with a trusted person can make things feel less like something you have to handle alone."
    ],

    "sad": [
        "I'm sorry you're having a difficult moment. Taking a short break, doing something calming, or talking with someone you trust may help.",
        "You don't have to solve everything immediately. Give yourself some time and consider reaching out to someone you trust."
    ]
}


@bot.event
async def on_ready():
    print(f"Logged in as {bot.user}")


@bot.command()
async def hello(ctx):
    await ctx.send("Hello! I'm online.")


@bot.command()
async def story(ctx):
    user_id = ctx.author.id

    location = random.choice(story_locations)
    item = random.choice(story_items)
    event = random.choice(story_events)

    user_stories[user_id] = {
        "location": location,
        "item": item,
        "event": event
    }

    await ctx.send(
        f"You wake up in {location}.\n\n"
        f"Next to you is {item}.\n\n"
        f"{event}\n\n"
        "What do you do?"
    )


@bot.command()
async def choose(ctx, choice: str):
    user_id = ctx.author.id

    if user_id not in user_stories:
        await ctx.send(
            "You don't have an active story. Try `!story` first."
        )
        return

    choice = choice.lower()

    if choice == "left":
        response = (
            "You head left and discover a room filled with old maps. "
            "One of them has your name written on it."
        )

    elif choice == "right":
        response = (
            "You head right and find a staircase leading toward "
            "a strange blue light."
        )

    else:
        response = "Try choosing `left` or `right`."

    await ctx.send(response)


@bot.command()
async def chat(ctx, *, message: str):
    text = message.lower()

    for keyword, responses in chat_responses.items():
        if keyword in text:
            await ctx.send(random.choice(responses))
            return

    await ctx.send(
        "I'm still learning how to respond to that. "
        "Try talking to me about Python or Discord!"
    )


@bot.command()
async def support(ctx, *, message: str):
    text = message.lower()

    for keyword, responses in support_responses.items():
        if keyword in text:
            response = random.choice(responses)

            await ctx.send(
                f"{response}\n\n"
                "I'm a bot, not a therapist or medical professional. "
                "If you need personal support, consider talking with "
                "someone you trust."
            )
            return

    await ctx.send(
        "It sounds like something is bothering you. "
        "I can offer general wellness suggestions, but I'm not a therapist. "
        "If you need personal support, consider reaching out to someone you trust."
    )


@bot.command(name="help")
async def commands_help(ctx):
    await ctx.send(
        "**Available commands:**\n"
        "`!hello` - Say hello\n"
        "`!story` - Start a new story\n"
        "`!choose left` - Choose the left path\n"
        "`!choose right` - Choose the right path\n"
        "`!chat &lt;message&gt;` - Have a casual conversation\n"
        "`!support &lt;message&gt;` - Get general wellness support"
    )


@bot.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.MissingRequiredArgument):
        await ctx.send(
            "You're missing something. Try `!help` to see how the command works."
        )

    elif isinstance(error, commands.CommandNotFound):
        return

    else:
        print(f"Error: {error}")


bot.run(TOKEN)
</code></pre>
<p>This is enough to create a surprisingly capable beginner Discord project.</p>
<p>But there's an important limitation.</p>
<h2 id="heading-our-bot-doesnt-actually-remember-anything">Our Bot Doesn't Actually Remember Anything</h2>
<p>There's one small problem with our bot so far: it doesn't actually remember anything after it shuts down.</p>
<p>Right now, we're storing our story information in a Python dictionary:</p>
<pre><code class="language-python">user_stories = {}
</code></pre>
<p>This works while the bot is running. But if you stop the program and start it again, the dictionary starts empty.</p>
<p>To fix this, we need somewhere to permanently store our data. That's where a <strong>database</strong> comes in.</p>
<p>For this project, we'll use <strong>SQLite</strong>. SQLite is a lightweight database that stores information in a file on your computer. Python already includes SQLite through the built-in <code>sqlite3</code> module, so we don't need to install anything extra.</p>
<h3 id="heading-create-the-database">Create the Database</h3>
<p>First, add this import near the top of <code>bot.py</code>:</p>
<pre><code class="language-python">import sqlite3
</code></pre>
<p>Then create a connection to a database file:</p>
<pre><code class="language-python">db = sqlite3.connect("bot.db")
cursor = db.cursor()
</code></pre>
<p>The first line creates a database file called <code>bot.db</code> if one doesn't already exist. If the file already exists, SQLite simply opens it.</p>
<p>The second line creates a <strong>cursor</strong>. You can think of the cursor as the part of our Python program that lets us send instructions to the database.</p>
<p>Now we need to create a table where we can store our users' story information:</p>
<pre><code class="language-python">cursor.execute("""
    CREATE TABLE IF NOT EXISTS user_stories (
        user_id INTEGER PRIMARY KEY,
        location TEXT,
        item TEXT,
        event TEXT
    )
""")

db.commit()
</code></pre>
<p>Let's break this down.</p>
<p><code>cursor.execute()</code> tells SQLite to run the SQL command inside the parentheses.</p>
<p>The SQL command starts with:</p>
<pre><code class="language-sql">CREATE TABLE IF NOT EXISTS user_stories
</code></pre>
<p>This tells SQLite to create a table called <code>user_stories</code>, but only if that table doesn't already exist.</p>
<p>Inside the parentheses, we define the information that each row can contain:</p>
<pre><code class="language-sql">user_id INTEGER PRIMARY KEY,
location TEXT,
item TEXT,
event TEXT
</code></pre>
<p><code>user_id</code> stores the Discord user's ID. We use it as the <code>PRIMARY KEY</code>, which means each user gets their own unique row.</p>
<p><code>location</code>, <code>item</code>, and <code>event</code> are all pieces of information about the user's current story.</p>
<p>Finally:</p>
<pre><code class="language-python">db.commit()
</code></pre>
<p>saves the changes to the database.</p>
<p>At this point, your project folder should contain a new file called:</p>
<pre><code class="language-text">bot.db
</code></pre>
<p>You don't need to open or edit this file manually. SQLite will manage it for us.</p>
<h3 id="heading-save-a-users-story">Save a User's Story</h3>
<p>Now let's actually put information into our database.</p>
<p>Suppose we have these variables:</p>
<pre><code class="language-python">user_id = ctx.author.id
location = "an abandoned castle"
item = "a mysterious key"
event = "a locked door"
</code></pre>
<p>We can save them using:</p>
<pre><code class="language-python">cursor.execute(
    """
    INSERT OR REPLACE INTO user_stories
    (user_id, location, item, event)
    VALUES (?, ?, ?, ?)
    """,
    (user_id, location, item, event)
)

db.commit()
</code></pre>
<p>The SQL statement tells SQLite to insert the information into the <code>user_stories</code> table.</p>
<p>The <code>?</code> symbols are placeholders for the actual values. The values are provided separately here:</p>
<pre><code class="language-python">(user_id, location, item, event)
</code></pre>
<p>This is safer than manually inserting values directly into the SQL string.</p>
<p><code>INSERT OR REPLACE</code> also means that if this user already has a saved story, their old story information can be replaced with the new information.</p>
<h3 id="heading-get-the-story-back">Get the Story Back</h3>
<p>Saving information is only half of the job. We also need to be able to retrieve it.</p>
<p>We can search the database for a user's story like this:</p>
<pre><code class="language-python">cursor.execute(
    """
    SELECT location, item, event
    FROM user_stories
    WHERE user_id = ?
    """,
    (user_id,)
)

story = cursor.fetchone()
</code></pre>
<p>This time, we're using <code>SELECT</code> to ask SQLite for information.</p>
<p>The <code>WHERE</code> part is important:</p>
<pre><code class="language-sql">WHERE user_id = ?
</code></pre>
<p>It tells SQLite to find the row belonging to this specific Discord user.</p>
<p>Then:</p>
<pre><code class="language-python">story = cursor.fetchone()
</code></pre>
<p>gets the first matching result.</p>
<p>If the user has a saved story, <code>story</code> will contain their information. If they don't, <code>story</code> will be <code>None</code>.</p>
<p>We can check for that:</p>
<pre><code class="language-python">if story:
    location, item, event = story

    await ctx.send(
        f"You're currently in {location}. "
        f"You have {item}, and you're facing {event}."
    )
else:
    await ctx.send("I don't have a saved story for you yet!")
</code></pre>
<p>Now the bot can retrieve information that was saved earlier, even after the Python program has been restarted.</p>
<h3 id="heading-put-it-into-a-command">Put It Into a Command</h3>
<p>We can turn this into a simple command that lets users check their saved story:</p>
<pre><code class="language-python">@bot.command()
async def status(ctx):
    user_id = ctx.author.id

    cursor.execute(
        """
        SELECT location, item, event
        FROM user_stories
        WHERE user_id = ?
        """,
        (user_id,)
    )

    story = cursor.fetchone()

    if story:
        location, item, event = story

        await ctx.send(
            f"You're currently in {location}. "
            f"You have {item}, and you're facing {event}."
        )
    else:
        await ctx.send(
            "You don't have a saved story yet. "
            "Start one with `!story`!"
        )
</code></pre>
<p>Now a user can type:</p>
<pre><code class="language-text">!status
</code></pre>
<p>and the bot can look up their story from the database.</p>
<p>This is a big improvement over our original dictionary. A dictionary only remembers information while the Python program is running. SQLite lets us save that information so it can still be there when the bot starts again.</p>
<p>For a larger bot, you could eventually store things like user preferences, story progress, inventory, conversation history, or other data. But for now, this simple database is enough to give our bot some real memory.</p>
<h2 id="heading-adding-real-ai-chat">Adding Real AI Chat</h2>
<p>Before we connect our bot to an AI model, let's quickly talk about <strong>Hugging Face</strong>.</p>
<p>If you've never used it before, Hugging Face is a platform where developers can find, share, and use machine learning models and datasets. Think of it as a huge community and library for AI tools.</p>
<p>Hugging Face also provides tools that let Python programs communicate with these models without having to build and train an AI model from scratch.</p>
<p>For our bot, we'll use Hugging Face's <strong>Inference Providers</strong> to send a user's message to a supported language model and receive its response.</p>
<p>We won't be training an AI model ourselves. Instead, we'll use an existing model and connect it to our Discord bot through Python.</p>
<p>Now that we know what Hugging Face is, let's connect it to our bot.</p>
<h3 id="heading-install-the-hugging-face-library">Install the Hugging Face Library</h3>
<p>First, install <code>huggingface_hub</code>:</p>
<pre><code class="language-bash">pip install -U huggingface_hub
</code></pre>
<p>We already installed <code>python-dotenv</code>, so we can use the same <code>.env</code> file from earlier to keep our Hugging Face token out of the source code.</p>
<p>Add your Hugging Face token to <code>.env</code>:</p>
<pre><code class="language-text">DISCORD_TOKEN=YOUR_BOT_TOKEN_HERE
HF_TOKEN=YOUR_HUGGING_FACE_TOKEN_HERE
</code></pre>
<p>Replace <code>YOUR_HUGGING_FACE_TOKEN_HERE</code> with your actual Hugging Face access token.</p>
<p>Just like your Discord bot token, <strong>don't share this token or upload it to GitHub</strong>.</p>
<h3 id="heading-create-the-hugging-face-client">Create the Hugging Face Client</h3>
<p>Now add this import near the top of <code>bot.py</code>:</p>
<pre><code class="language-python">from huggingface_hub import InferenceClient
</code></pre>
<p>Then load the token:</p>
<pre><code class="language-python">HF_TOKEN = os.getenv("HF_TOKEN")

if not HF_TOKEN:
    raise RuntimeError("HF_TOKEN is not set.")
</code></pre>
<p>The first line gets the token from our environment variables. The <code>if</code> statement checks whether the token actually exists. If it doesn't, Python stops and gives us a useful error instead of letting the program fail later in a confusing way.</p>
<p>Now create the Hugging Face client:</p>
<pre><code class="language-python">client = InferenceClient(
    api_key=HF_TOKEN
)
</code></pre>
<p>The <code>InferenceClient</code> is what our Python program will use to communicate with Hugging Face's inference service.</p>
<h3 id="heading-connect-the-ai-model-to-the-bot">Connect the AI Model to the Bot</h3>
<p>Now we can replace our previous keyword-based <code>!chat</code> command with one that sends the user's message to a language model.</p>
<pre><code class="language-python">@bot.command()
async def chat(ctx, *, message: str):
    try:
        response = client.chat_completion(
            model="YOUR_SUPPORTED_MODEL_ID",
            messages=[
                {
                    "role": "system",
                    "content": (
                        "You are a friendly Discord bot. "
                        "Keep responses helpful, concise, and conversational."
                    )
                },
                {
                    "role": "user",
                    "content": message
                }
            ],
            max_tokens=200
        )

        answer = response.choices[0].message.content

        await ctx.send(answer)

    except Exception as error:
        print(f"AI error: {error}")
        await ctx.send(
            "I couldn't generate a response right now. "
            "Please try again later."
        )
</code></pre>
<p>There's quite a bit happening here, so let's walk through it.</p>
<p>We start with the same command structure we've already used:</p>
<pre><code class="language-python">@bot.command()
async def chat(ctx, *, message: str):
</code></pre>
<p>This creates our <code>!chat</code> command and stores everything the user types after it in <code>message</code>.</p>
<p>For example:</p>
<pre><code class="language-text">!chat What is Python?
</code></pre>
<p>gives us:</p>
<pre><code class="language-python">message = "What is Python?"
</code></pre>
<p>Next, we use:</p>
<pre><code class="language-python">try:
</code></pre>
<p>This tells Python that we're about to run code that could potentially fail. Since we're communicating with an external service, things like an unavailable model, an invalid token, or a temporary connection problem can happen.</p>
<p>Now we call:</p>
<pre><code class="language-python">response = client.chat_completion(
</code></pre>
<p>This sends a chat-completion request to the model through Hugging Face. The <code>messages</code> parameter contains the conversation we want the model to respond to.</p>
<p>The first message has the role <code>"system"</code>:</p>
<pre><code class="language-python">{
    "role": "system",
    "content": (
        "You are a friendly Discord bot. "
        "Keep responses helpful, concise, and conversational."
    )
}
</code></pre>
<p>The system message gives the model instructions about how it should respond.</p>
<p>Then we provide the user's actual message:</p>
<pre><code class="language-python">{
    "role": "user",
    "content": message
}
</code></pre>
<p>If the user typed:</p>
<pre><code class="language-text">!chat What is Python?
</code></pre>
<p>then <code>message</code> contains:</p>
<pre><code class="language-text">What is Python?
</code></pre>
<p>So the model receives that as the user's input.</p>
<p>We also have:</p>
<pre><code class="language-python">max_tokens=200
</code></pre>
<p>This limits how much text the model can generate for one response. Keeping responses relatively short works well for Discord because huge blocks of text aren't always very pleasant to read in a chat channel.</p>
<p>You also need to replace:</p>
<pre><code class="language-python">model="YOUR_SUPPORTED_MODEL_ID"
</code></pre>
<p>with the ID of a model currently available through the Hugging Face Inference Providers you are using. Hugging Face's documentation shows that <code>InferenceClient</code> can use a model ID hosted on the Hugging Face Hub for chat completion.</p>
<p>Once the request is complete, we need to get the actual text from the response:</p>
<pre><code class="language-python">answer = response.choices[0].message.content
</code></pre>
<p>The response contains information about the model's output. <code>choices[0]</code> gets the first generated response, and <code>.message.content</code> gives us the actual text.</p>
<p>Then we send it to Discord:</p>
<pre><code class="language-python">await ctx.send(answer)
</code></pre>
<p>So the whole process looks like this:</p>
<pre><code class="language-text">User types !chat
        ↓
Discord sends the command to our bot
        ↓
Python gets the user's message
        ↓
Hugging Face receives the message
        ↓
The AI model generates a response
        ↓
Python gets the generated text
        ↓
The bot sends it back to Discord
</code></pre>
<h3 id="heading-handle-ai-errors">Handle AI Errors</h3>
<p>The last part of our command is:</p>
<pre><code class="language-python">except Exception as error:
    print(f"AI error: {error}")
    await ctx.send(
        "I couldn't generate a response right now. "
        "Please try again later."
    )
</code></pre>
<p>If something goes wrong inside the <code>try</code> block, Python jumps to the <code>except</code> block instead of crashing the entire bot.</p>
<p>The error is printed in the terminal so you can investigate what happened:</p>
<pre><code class="language-python">print(f"AI error: {error}")
</code></pre>
<p>Meanwhile, the Discord user gets a simple message:</p>
<pre><code class="language-text">I couldn't generate a response right now. Please try again later.
</code></pre>
<p>This is much better than letting an API error take down the whole bot.</p>
<p>At this point, you have a real AI-powered <code>!chat</code> command. You can type something like:</p>
<pre><code class="language-text">!chat Tell me an interesting fact about space.
</code></pre>
<p>and the model can generate a response instead of choosing from a small list of pre-written messages.</p>
<p>One thing to remember is that this bot is sending user messages to an external AI service. Don't automatically send private or sensitive conversations to an AI provider. If you make this bot available to other people, be clear about what information it processes and avoid storing or sending more data than the bot actually needs.</p>
<p>You can also combine this AI system with the SQLite database from earlier. For example, you could save a limited amount of conversation history and send relevant previous messages along with a new message. That would allow the bot to keep some context between messages instead of treating every message as a completely new conversation.</p>
<h2 id="heading-how-do-we-keep-the-bot-online">How Do We Keep the Bot Online?</h2>
<p>Here's where the phrase "online forever" needs a little clarification.</p>
<p>There are two different situations.</p>
<h3 id="heading-option-1-run-it-on-your-computer">Option 1: Run It on Your Computer</h3>
<p>When you run:</p>
<pre><code class="language-bash">python bot.py
</code></pre>
<p>the bot stays online while that program is running.</p>
<p>Close the terminal?</p>
<p>Bot goes offline.</p>
<p>Turn off the computer?</p>
<p>Bot goes offline.</p>
<p>Lose internet?</p>
<p>Bot goes offline.</p>
<p>This is perfect for development but it's not a 24/7 production setup.</p>
<h3 id="heading-option-2-host-it-on-a-server">Option 2: Host It on a Server</h3>
<p>For a bot that should stay online while your computer is off, you need a computer somewhere that stays available.</p>
<p>That computer can be a cloud server.</p>
<p>You upload your project, install the dependencies, add your environment variables, and start:</p>
<pre><code class="language-bash">python bot.py
</code></pre>
<p>Now the cloud machine runs the program instead of your laptop.</p>
<p>Services designed for continuously running workloads can be used for this kind of application. For example, Render currently provides a <strong>Background Worker</strong> service type for continuously running processes that don't need to receive incoming web traffic.</p>
<p>But you should check the provider's current pricing and service limitations before deploying. Free hosting tiers aren't necessarily designed for an always-on Discord bot, and a "free forever" 24/7 setup isn't something you should assume a hosting platform will provide.</p>
<h2 id="heading-what-forever-actually-means">What "Forever" Actually Means</h2>
<p>There isn't really a magical:</p>
<pre><code class="language-text">ONLINE_FOREVER = True
</code></pre>
<p>setting.</p>
<p>A bot can stay online continuously only as long as the computer or server running it continues operating.</p>
<p>Even a professionally hosted bot can go offline because of:</p>
<ul>
<li><p>Server maintenance</p>
</li>
<li><p>Deployments</p>
</li>
<li><p>Bugs</p>
</li>
<li><p>Network problems</p>
</li>
<li><p>Provider outages</p>
</li>
<li><p>Invalid credentials</p>
</li>
<li><p>API changes</p>
</li>
<li><p>Billing or account issues</p>
</li>
</ul>
<p>So the realistic goal is to keep the bot running automatically and restart it when something goes wrong.</p>
<p>That is what production hosting is designed to help with.</p>
<p>If your provider supports automatic restarts, enable them.</p>
<p>You can also make your Python code fail clearly when an important environment variable is missing:</p>
<pre><code class="language-python">if not TOKEN:
    raise RuntimeError("DISCORD_TOKEN is not set.")
</code></pre>
<p>A clear error is much easier to debug than a mysterious bot that simply doesn't appear online.</p>
<h2 id="heading-dont-try-to-keep-it-awake-with-random-tricks">Don't Try to "Keep It Awake" With Random Tricks</h2>
<p>You may find tutorials suggesting that you deploy a web server and repeatedly ping it from another service to prevent a free hosting instance from sleeping.</p>
<p>Be careful with that approach.</p>
<p>Hosting providers change their free-tier rules, and attempting to work around those limits can violate their terms.</p>
<p>If you need an actually persistent bot, use a hosting option that explicitly supports the workload.</p>
<p>For example, a background worker is designed for continuously running processes. That's much cleaner than trying to convince a web service that your Discord bot is secretly a website.</p>
<h2 id="heading-additional-features-and-where-to-go-next"><strong>Additional Featur</strong>es and Where to Go Next</h2>
<p>Now that you have a working Discord bot, there are plenty of directions you can take the project next.</p>
<p>You could turn the storytelling system into a more complete game by adding an inventory, multiple chapters, puzzles, or different endings. You could also replace text-based commands with Discord slash commands and buttons to make the bot easier to interact with.</p>
<p>If you're interested in AI, you could expand the chat system by giving the bot different personalities, adding carefully limited conversation context, or using AI to generate parts of the stories.</p>
<p>You could also add moderation features, daily story prompts, or other commands that fit the kind of Discord community you're building.</p>
<p>These are ideas for extending the project rather than features we'll build step by step in this tutorial. The important thing is that you now have the foundation to experiment with them yourself.</p>
<p>Start with one small feature, figure out how it works, and build from there. You don't need to turn the bot into a massive project all at once.</p>
<p>The more you experiment with the code, the more you'll start seeing how Python, Discord, databases, and AI can work together in a real application.</p>
<h2 id="heading-test-everything-locally-first">Test Everything Locally First</h2>
<p>Before deploying, test:</p>
<pre><code class="language-text">!hello
!story
!choose left
!choose right
!chat hello
!chat I want to learn Python
!support I'm stressed
!help
</code></pre>
<p>Then test weird inputs:</p>
<pre><code class="language-text">!choose banana
!chat
!support
!unknowncommand
</code></pre>
<p>You want to discover bugs while you're sitting in front of your computer, not three days later when someone tells you:</p>
<blockquote>
<p>"Your bot has been broken since Tuesday."</p>
</blockquote>
<h2 id="heading-deploying-the-bot">Deploying the Bot</h2>
<p>First, make sure your project contains:</p>
<pre><code class="language-text">discord-story-bot/
│
├── bot.py
├── requirements.txt
├── .gitignore
└── .python-version
</code></pre>
<p>A <code>.python-version</code> file can contain something like:</p>
<pre><code class="language-text">3.13
</code></pre>
<p>Using a version file makes your deployment environment more predictable. Render currently supports specifying a Python version through <code>.python-version</code> or an environment variable.</p>
<p>Your <code>requirements.txt</code> should contain your dependencies.</p>
<p>For example:</p>
<pre><code class="language-text">discord.py
python-dotenv
</code></pre>
<p>For deployment, you generally don't need the local <code>.env</code> file.</p>
<p>Instead, add:</p>
<pre><code class="language-text">DISCORD_TOKEN
</code></pre>
<p>as an environment variable in your hosting provider's dashboard.</p>
<p>That way the secret isn't stored inside your repository.</p>
<h3 id="heading-the-start-command">The Start Command</h3>
<p>Your deployment service needs to know what to run.</p>
<p>For this project, the start command is:</p>
<pre><code class="language-bash">python bot.py
</code></pre>
<p>The important thing is that the process doesn't immediately exit.</p>
<p>A Discord bot stays alive because <code>bot.run(TOKEN)</code> starts the Discord connection and keeps the program running.</p>
<p>If your hosting service supports background workers, that's a natural fit for a bot like this because the bot doesn't need to serve normal HTTP requests. Render specifically describes background workers as continuously running services that don't receive incoming network traffic.</p>
<h2 id="heading-remember-keep-your-secrets-secret">Remember: Keep Your Secrets Secret</h2>
<p>This is worth repeating because it causes a lot of beginner projects to get compromised.</p>
<p>Never commit this:</p>
<pre><code class="language-python">bot.run("YOUR_REAL_TOKEN")
</code></pre>
<p>Never upload:</p>
<pre><code class="language-text">.env
</code></pre>
<p>Never paste your actual token into a public GitHub issue.</p>
<p>If a token accidentally becomes public, treat it as compromised and regenerate it.</p>
<p>Environment variables are your friend.</p>
<h2 id="heading-what-you-learned">What You Learned</h2>
<p>You've now built a Discord bot that demonstrates several real programming concepts.</p>
<p>You learned how to:</p>
<ul>
<li><p>Create a Discord application</p>
</li>
<li><p>Connect Python to Discord</p>
</li>
<li><p>Use <code>discord.py</code></p>
</li>
<li><p>Configure Gateway Intents</p>
</li>
<li><p>Create commands</p>
</li>
<li><p>Use asynchronous functions</p>
</li>
<li><p>Read command arguments</p>
</li>
<li><p>Generate random stories</p>
</li>
<li><p>Store temporary user state</p>
</li>
<li><p>Create a basic chat system</p>
</li>
<li><p>Create a mental-wellness support feature</p>
</li>
<li><p>Handle command errors</p>
</li>
<li><p>Keep secrets out of source code</p>
</li>
<li><p>Prepare a project for deployment</p>
</li>
<li><p>Think about persistent hosting</p>
</li>
</ul>
<p>And underneath all those features, the architecture is still surprisingly simple:</p>
<pre><code class="language-text">User sends command
        ↓
Discord receives message
        ↓
discord.py receives event
        ↓
Python function runs
        ↓
Bot generates response
        ↓
Discord displays response
</code></pre>
<p>You don't need thousands of lines of code to get started.</p>
<p>You need a clear idea, a few Python concepts, and the willingness to keep debugging when something inevitably breaks.</p>
<h2 id="heading-final-thoughts">Final Thoughts</h2>
<p>The coolest part of this project isn't really the Discord bot. It's what the project teaches you.</p>
<p>And once you understand the pieces, you can reuse the same ideas in countless projects.</p>
<p>A Discord bot can become a game, which could become a web application, which could also become a larger software project.</p>
<p>And suddenly you're not just learning Python syntax anymore. You're learning how software actually gets built, one command at a time.</p>
<p>Happy coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Why Many Beginner Self-Taught Developers Struggle (And What to Do About It) ]]>
                </title>
                <description>
                    <![CDATA[ Self‑taught developers often begin with the same “starter pack”: a laptop, internet access, and sheer determination. What they lack, however, is structured guidance, a defined curriculum, or any form  ]]>
                </description>
                <link>https://www.freecodecamp.org/news/why-many-beginner-self-taught-developers-struggle-and-what-to-do-about-it/</link>
                <guid isPermaLink="false">69e66a12c9501dd0101793f9</guid>
                
                    <category>
                        <![CDATA[ Learning Journey ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Self-taught  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Beginner Developers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ learning ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Great John ]]>
                </dc:creator>
                <pubDate>Mon, 20 Apr 2026 18:01:54 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/76b41ea4-5375-4393-ad06-a0e53b53d23a.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Self‑taught developers often begin with the same “starter pack”: a laptop, internet access, and sheer determination. What they lack, however, is structured guidance, a defined curriculum, or any form of pedagogical support.</p>
<p>This absence of direction makes the journey significantly harder. Faced with an overwhelming abundance of online resources, many beginners become confused about where to start and often attempt to learn everything at once.</p>
<p>This is where the struggle with knowledge retention begins.</p>
<p>Not because they lack intelligence or effort, but because they're learning in a way that contradicts how the human brain actually works.</p>
<p>They dive into tutorials and courses without understanding the mechanism of the brain – that is, how the brain processes, stores, and retrieves information. As a result, much of what they learn simply doesn’t stick.</p>
<h3 id="heading-how-the-brain-processes-information">How the Brain Processes Information</h3>
<p>So what's the connection between the brain and learning how to code, you might ponder?</p>
<p>The connection is direct and unavoidable.</p>
<p>Coding isn't learned through willpower or motivation — though both matter — or by spending countless hours watching tutorials.</p>
<p>It's learned through the brain’s ability to process, store, and retrieve information.</p>
<p>Every variable, function, data structure, or debugging pattern must pass through the brain’s cognitive systems before it becomes usable knowledge.</p>
<p>If your learning process doesn't align with how the brain naturally acquires and organises information, your retention will collapse, no matter how determined you are.</p>
<p>Now imagine you’re trying to fill a bucket with water. You keep pouring and pouring, but the bucket has tiny holes at the bottom. No matter how much effort you put in, the water keeps leaking out. You might blame yourself for not pouring fast enough, or you might try switching to a bigger jug, but the real problem isn’t your effort — it’s the bucket.</p>
<p>The water is the information you’re trying to learn.</p>
<p>The bucket is your brain’s memory system.</p>
<p>The holes in the bucket are the natural forgetting mechanisms of the brain: cognitive overload, limited working memory, and other constraints that make retention difficult.</p>
<p>If you don’t understand these mechanisms, you can pour in as much information as you want, but most of it will leak out.</p>
<p>Not because you’re incapable, but because you’re learning in a way that contradicts how the brain actually retains knowledge.</p>
<h3 id="heading-the-role-of-academic-learning-theories">The Role of Academic Learning Theories</h3>
<p>Since learning ultimately takes place in the brain, an important question is: How does the human brain acquire, organize, and apply knowledge and why does the typical self‑taught learning process clash with these principles?</p>
<p>This is where academic learning theories become indispensable. These frameworks explain how the brain actually acquires, retains, and applies complex information and they offer a scientific roadmap for learning more effectively. Without understanding these principles, self‑taught developers unintentionally work against the brain’s natural architecture.</p>
<p>The purpose of this article is to unpack these essential learning theories and apply them directly to the beginner self‑taught developer’s journey.</p>
<p>By understanding how the brain processes information, beginners can structure their learning more intentionally, retain knowledge more reliably, and move toward becoming competent developers with far greater confidence and clarity.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a href="#heading-cognitive-load-theory-clt">Cognitive Load Theory (CLT)</a></p>
<ul>
<li><p><a href="#heading-working-memory">Working Memory</a></p>
</li>
<li><p><a href="#heading-millers-law">Miller's Law</a></p>
</li>
<li><p><a href="#heading-chunking">Chunking</a></p>
</li>
<li><p><a href="#heading-long-term-memory">Long-term memory</a></p>
</li>
<li><p><a href="#heading-schema">Schema</a></p>
</li>
<li><p><a href="#heading-intrinsic-load-the-natural-difficulty-of-the-task">Intrinsic Load: The Natural Difficulty of the Task</a></p>
</li>
<li><p><a href="#heading-extraneous-load-the-mental-noise">Extraneous Load: The Mental Noise</a></p>
</li>
<li><p><a href="#heading-germane-load-the-construction-work">Germane Load: The Construction Work</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-ebbinghaus-forgetting-curve">Ebbinghaus Forgetting Curve.</a></p>
</li>
<li><p><a href="#heading-how-the-theory-of-spaced-repetition-works">How the Theory of Spaced Repetition Works</a></p>
</li>
<li><p><a href="#heading-theory-of-deliberate-practice">Theory of Deliberate Practice</a></p>
</li>
<li><p><a href="#heading-what-is-blooms-taxonomy">What is Bloom's Taxonomy?</a></p>
<ul>
<li><a href="#heading-focused-mode-vs-diffuse-mode">Focused Mode vs Diffuse Mode</a></li>
</ul>
</li>
<li><p><a href="#heading-conclusion">Conclusion</a></p>
</li>
<li><p><a href="#heading-references">References</a></p>
</li>
</ul>
<h2 id="heading-cognitive-load-theory-clt">Cognitive Load Theory (CLT)</h2>
<p>Learning a new concept often requires mental effort by the brain to process newly acquired information. This effort exerted by the brain is known as cognitive load, a term coined by Australian educational psychologist John Sweller in 1988 during his study on how the brain acquires and retains information (Sweller, 1988).</p>
<p>Since then, his work has been expanded upon by other researchers. Notably, Dylan Wiliam famously tweeted in 2017 that Cognitive Load Theory (CLT) is "the single most important thing for teachers to know" (Dylan William, 2017).</p>
<p>You might wonder again: What does this have to do with me? As a beginner self‑taught developer, the answer is simple: you're both the teacher and the student.</p>
<p>So this is the most important theory you should know. In this self-tutoring journey, you're tasked with designing your own curriculum, choosing your own resources, pace your own learning, and evaluating your own progress.</p>
<p>Without understanding how cognitive load affects your ability to absorb and retain information, you may unintentionally overload your brain and sabotage your own learning.</p>
<p>Before we get into the nitty-gritty of CLT, there are important concepts masterminded by David Geary that you'll need to grasp to sufficiently understand this concept : “that which can be learnt” (biologically primary knowledge), “that which can be taught”(biologically secondary knowledge) (Geary, 2007, 2008).</p>
<p>According Geary (2007, 2008), "biologically primary knowledge" consists of "instinctual" skills that the brain is evolved to pick up naturally without formal schooling.</p>
<p>Examples include learning a first language, recognizing faces, or basic social navigation.</p>
<p>"Biologically secondary knowledge", on the other hand, consists of cultural and technical skills, like reading and writing, that are necessary for society but don't come naturally to the brain.</p>
<p>This is because we aren't "wired" to pick these up automatically. Instead, they require formal instruction and schools to pass them down.</p>
<p>Therefore, coding is a prime example of biologically secondary knowledge. The human brain is remarkably plastic, but it didn't evolve to interpret syntax, manage memory allocation, or debug logical loops.</p>
<p>These are cultural inventions, not natural instincts. Unlike learning to walk or speak your native language (which are biologically primary skills) you can't learn to code simply by “being around” computers.</p>
<p>Recognising that the human brain is not instinctively prepared for coding allows you to change your strategy. Once you accept that coding concepts are not “natural,” you can finally approach them with the structured, deliberate effort they require.</p>
<p>The second set of concepts beginner self-taught developers should know and understand are working memory, Miller's Laws, chunking, long-term memory, and schemas.</p>
<h3 id="heading-working-memory">Working Memory</h3>
<p>Working memory is where thinking happens. It's the active mental workspace where you hold information while you process it. When you encounter concepts like syntax, loops, functions, or an if/elseif statement for the first time, all of that information sits inside your working memory. The problem is that working memory is extremely limited and fragile.</p>
<p>When you first learn to code, your working memory functions like a small mental desk where only a few items can be placed at once.</p>
<p>Imagine trying to assemble a piece of IKEA furniture on a tiny coffee table. If you spread out the instruction manual, the screws, the wooden panels, and the tools all at the same time, the table becomes cluttered instantly. You start losing track of which part goes where, not because you’re incapable, but because the surface you’re working on is too small to hold everything at once.</p>
<p>Working memory behaves the same way. When you’re learning new concepts – like arrays, loops, functions, or error handling – each idea takes up space on that mental desk. If you then overload it, the desk becomes overcrowded.</p>
<p>Once it exceeds its capacity, things begin to fall off, and your ability to retain collapses.</p>
<p>It’s not a lack of intelligence. It’s simply the natural limit of working memory.</p>
<p>Now this collapse happens because you went against the threshold your working memory can hold. This is backed up by research that shows that working memory can typically process only 5–9 pieces of information at any given time (Miller, 1956). This is known as Miller’s Law.</p>
<h3 id="heading-millers-law">Miller's Law</h3>
<p>In 1956, George Miller found that the average human can hold about seven items (plus or minus two) in working memory at once, even some recent research has stated the number is even lower about four item (Nelson Cowan, 2001).</p>
<p>So imagine you encounter a tutorial that introduces the following concepts all at the same time: a Route, a Controller, a Model, a Migration, a View, a Request, Helper files, Jobs and Queues, Middleware, Roles and Permissions, and a Service Provider. If you attempt to hold all of these in your mind simultaneously, you'll inevitably hit Miller’s Wall, as your working memory becomes overloaded, and you'll likely forget the first concept long before you reach the last.</p>
<p>So how do you handle complex tasks if the brain can only juggle 4–9 items at once?</p>
<p>You use chunking — the process of grouping small pieces of information into a single, meaningful unit.</p>
<h3 id="heading-chunking">Chunking</h3>
<p>Chunking is the brain’s strategy for compressing complexity. Instead of forcing working memory to hold a dozen unrelated items, you reorganise them into a few coherent structures. This reduces cognitive load, prevents overload, and allows you to work with far more information than your raw working‑memory limits would normally allow.</p>
<p>Let's consider an example:</p>
<p>A beginner learning Laravel might see Route, Controller, Model, Migration, and View as five separate, overwhelming items. To a beginner, each one feels like a distinct cognitive burden. But an experienced developer doesn't treat them as isolated concepts. Instead, they're understood as a single meaningful unit: the MVC pattern. Instead of holding five items in working memory, the expert holds one.</p>
<p>This raises an important question: how does a beginner know that these five elements belong together when they have only just encountered them?</p>
<p>It's crucial to emphasise that chunking isn't automatic. It depends on recognising meaningful relationships between concepts, and beginners typically lack the prior knowledge needed to perceive those relationships early on.</p>
<p>But as learners repeatedly encounter the same sequence during the learning process, they begin to notice consistent patterns. Over time, the brain’s natural tendency to seek structure enables them to identify which components reliably operate together, allowing these elements to gradually fuse into a single, meaningful chunk.</p>
<p>For example, when I first followed a Laravel e-commerce tutorial, I noticed that for every new resource the tutor created –&nbsp;Payment, Cart, KYC, and Contact – the same pattern was repeated: a Controller, a Model, and a View were always created together.</p>
<p>After encountering this sequence several times, it became clear that these components consistently belonged together as a set. Over time, I began to perceive the Controller, Model, and View not as separate elements, but as a single, integrated unit.</p>
<p>So beginners may not be able to chunk effectively on day one because they lack the prior knowledge needed to recognise what belongs together. But with time, and repeated encounters across different contexts, these individual pieces fuse into stable mental units stored in long‑term memory.</p>
<p>What feels overwhelming at first eventually becomes effortless, not because the task became simpler, but because your internal representation became more organised.</p>
<p>This is the power of chunking: it transforms scattered pieces of information into organised units that fit comfortably within the limits of working memory.</p>
<p>Without chunking, beginners drown in details. With chunking, they gain the cognitive space needed to understand, retain, and apply what they learn.</p>
<h3 id="heading-long-term-memory">Long-term memory</h3>
<p>Unlike working memory, long‑term memory has virtually infinite capacity. The goal of all study is to move information from the cramped working memory into the vast long‑term memory.</p>
<p>Here is the real secret: you don’t learn in working memory – you only process there.</p>
<p>True learning is the permanent change that happens in long‑term memory.</p>
<h3 id="heading-schema">Schema</h3>
<p>Once stored in long-term memory, information becomes part of a schema — a mental map or filing system that organizes related ideas.</p>
<p>For example, when you finally learn that Laravel is an MVC framework, you aren’t just memorizing three letters. You're building a schema that tells your brain: Models handle data, Views handle presentation, and Controllers handle logic.</p>
<p>Once a schema is built, it can be pulled into working memory as a single chunk, effectively bypassing Miller’s Law.</p>
<p>This is how experts think effortlessly while beginners feel overwhelmed.</p>
<p>And this is why Garnett (2020) argues that "being competent or lacking competence in something depends entirely on how secure the retrieval of knowledge held in the schema is".</p>
<p>Now that the foundations of working memory, long‑term memory, schemas, and chunking are clear, we can turn to another set of concepts every self‑taught developer must understand: intrinsic load, extraneous load, and germane load. These three components make up the full structure of Cognitive Load Theory, and they determine whether learning feels manageable or overwhelming.</p>
<h3 id="heading-intrinsic-load-the-natural-difficulty-of-the-task">Intrinsic Load: The Natural Difficulty of the Task</h3>
<p>Intrinsic load refers to the inherent complexity of the material itself. Some concepts are simply harder than others because they contain more interacting elements that must be processed at the same time.</p>
<p>In Laravel, understanding a simple Route has low intrinsic load.</p>
<p>But concepts like Dependency Injection or Polymorphic Relationships have high intrinsic load because they involve multiple layers of abstraction and interdependent ideas.</p>
<p>You can't change the intrinsic load of a concept, but you can manage it by breaking the idea into smaller, more digestible sub‑tasks. This is why good teaching — and good self‑teaching — always begins with simplification and sequencing.</p>
<p>Simplification means stripping a concept down to its essential parts so the learner isn't overwhelmed by unnecessary detail.</p>
<p>Sequencing means introducing parts in a logical order, where each step builds on the previous one. This helps reduce unnecessary cognitive load and allows learners to devote more mental effort (germane load) to building schemas.</p>
<p>It’s like meeting someone new, and they tell you their name and it happens to be your mother’s name. Instantly, your brain forms a connection. You associate this new person’s name with the strong, deeply stored memory of your mother.</p>
<p>Because that schema already exists in your long-term memory, the new information “attaches” to it. Later, when you try to recall the name, you don’t struggle, you simply think of your mother, and the name comes back easily.</p>
<p>While many believe self‑taught developers struggle because they lack immediate, reliable, personal guidance, there's actually a hidden advantage in this predicament. When a teacher explains a concept, even if they try their best to “chunk” the information, they can't truly know the student’s internal limits — how much intrinsic load the learner can handle, how quickly they can process new ideas, or how much prior knowledge they can activate.</p>
<p>This is where self‑taught developer quietly shines. Because you are both the teacher and the student, you know your own cognitive limits better than anyone else. You can slow down when something feels heavy, pause when working memory is overloaded, and chunk information in a way that perfectly matches your personal capacity.</p>
<p>You can simplify a concept to its bare essentials and sequence it at a pace that aligns with your own understanding.</p>
<h3 id="heading-extraneous-load-the-mental-noise">Extraneous Load: The Mental Noise</h3>
<p>Extraneous load is the enemy of the self‑taught developer. It's the mental effort wasted on tasks that don't contribute to actual learning. This is where a self-taught developer's strength must truly shine.</p>
<p>A teacher in a classroom is responsible for removing any distractions that might derail a child or slow down their assimilation of knowledge. As a self-taught developer, that responsibility falls entirely on you. You must identify these distractions and eliminate them.</p>
<p>As a self-taught developer myself, I use specific strategies to ensure I stay focused. Before starting any course, I spend time reading the comment section to see what others have experienced. If I see complaints about low audio quality, unclear explanations, or tutorials that move too fast, I immediately abandon that course and look for one with better reviews.</p>
<p>Anything that might derail my progress must be removed. If you spend half of your mental energy trying to figure out all of these, you only have the remaining half available for understanding the logic of the code. And remember: when learning new concepts, we use working memory, which is fragile.</p>
<p>As your own “inner teacher,” you must eliminate this noise so your limited working memory can focus entirely on the material that matters.</p>
<h3 id="heading-germane-load-the-construction-work">Germane Load: The Construction Work</h3>
<p>Germane load is the productive mental effort used to build and refine schemas — the mental structures that make future learning easier.</p>
<p>This is the “Aha!” moment when new information connects meaningfully to what you already know.</p>
<p>For example, germane load appears when you realise that a Database Migration is essentially a version‑control system for your table structure.</p>
<p>That insight is schema construction in action.</p>
<p>Teachers are often advised to help manage a child's germane load. One way they do this is by connecting the new idea being taught to an existing concept.</p>
<p>By doing this, they help the student build schemas: mental frameworks that organise and interpret information.</p>
<p>For a self-taught developer, this means instead of memorizing a new syntax in isolation, you look for a 'hook' in something you already understand.</p>
<p>For example, if you already know how a physical filing cabinet works, understanding Arrays or Objects in code becomes much easier.</p>
<p>You aren't learning from scratch – you're simply "plugging" new data into an old socket. This reduces the mental strain and makes the new knowledge stick permanently.</p>
<p>But this can only happen when intrinsic load is properly managed and extraneous load is removed.</p>
<p>It's important to note that, unlike intrinsic and extraneous load, germane load isn't an independent type of cognitive load.</p>
<p>Instead, it represents the portion of your working memory that remains available to handle the element interactivity associated with intrinsic load.</p>
<p>In other words, germane load is the mental energy you have left for learning once the unnecessary noise is stripped away.</p>
<p>Understanding cognitive load explains why learning can feel overwhelming in the moment, but it doesn't explain why knowledge fades after the moment has passed. For that, we turn to another foundational principle in learning science: the Ebbinghaus Forgetting Curve.</p>
<h2 id="heading-ebbinghaus-forgetting-curve">Ebbinghaus Forgetting Curve</h2>
<p>If you remember the bucket analogy, this curve represents one of the holes at the bottom — the brain’s natural tendency to let information leak away unless it's reinforced.</p>
<p>In the late 19th century, Hermann Ebbinghaus discovered that human memory follows a predictable pattern of decline. After learning something new, we forget most of it astonishingly quickly — often within hours — unless the information is revisited. The forgetting curve shows that memory retention drops sharply at first and then continues to decline more slowly over time.</p>
<p>Studies based on Ebbinghaus’ forgetting curve found that without a conscious effort to retain newly acquired information, we lose approximately 50% of new information within 24 hours, and up to 90% within a week (Clearwater, 2024).</p>
<p>In other words, the brain is designed to discard information that isn't reinforced.</p>
<p>For self‑taught developers, this has profound implications.</p>
<p>You may understand a Laravel controller today, spatial roles and permission concepts, and so on – but if you don't revisit it, practice it, or apply it within the next few hours, your brain will naturally let it fade.</p>
<p>This is not a sign of weakness or lack of talent. It's simply how human brain works.</p>
<p>The forgetting curve also explains why tutorials feel deceptively easy the moment you're going through them.</p>
<p>While watching, everything seems clear — but a week later, the same concepts feel unfamiliar.</p>
<p>The knowledge never made it into long‑term memory because you didn't revisit, practice, or connect it to existing schemas.</p>
<p>Since the human brain is designed to forget anything that isn't repeated, repetition becomes the signal that tells the brain, “This matters — keep it.”</p>
<p>This is why, when you meet someone for the first time and they tell you their name, you'll almost certainly forget it unless you consciously repeat it to yourself several times. If you don’t reinforce it, you end up asking — often with embarrassment — “Sorry, what was your name again?”</p>
<p>The same principle applies to learning code: without deliberate repetition, the brain simply lets the information fade. However, with a technique called spaced repetition, retention is significantly improved .</p>
<h2 id="heading-how-the-theory-of-spaced-repetition-works">How the Theory of Spaced Repetition Works</h2>
<p>Spaced repetition is a learning technique grounded in cognitive psychology that involves reviewing information at increasingly spaced intervals to strengthen long‑term memory retention.</p>
<p>It's based on the principle that memory decays predictably over time — as demonstrated by the Ebbinghaus Forgetting Curve — and that strategically timed reviews or repetition interrupt this decay, making the memory more durable with each repetition.</p>
<p>This idea is what gave birth to Anki-Flash cards.</p>
<p>Imagine you're trying to memorise the time complexity of different algorithms.</p>
<p>This is a classic "dry" academic topic that's easy to forget.</p>
<p>To understand why spaced repetition is so powerful, consider a familiar scenario. You spend Sunday night staring at a chart of Big‑O complexities for four hours. By Monday’s review, you can recall most of them. By Friday, only a few remain. Two weeks later, the entire chart has vanished from memory.</p>
<p>Spaced repetition reverses this process by reviewing information at the precise moment it's about to be forgotten. Instead of cramming Big‑O notation in a single session, you revisit it across expanding intervals:</p>
<ol>
<li><p>Day 1 (Initial Learning): You study the Big‑O chart and understand each complexity class.</p>
</li>
<li><p>Day 2 (First Review): You test yourself. If you recall an item correctly, you schedule the next review three days later. If you miss it, you review it again the following day.</p>
</li>
<li><p>Day 5 (Second Review): You encounter the material again. Because you still remember it, the interval expands to ten days.</p>
</li>
<li><p>Day 15 (Third Review): Your memory has begun to fade, but the moment you see the prompt, the concept resurfaces. This slight struggle to retrieve the information is precisely what strengthens long‑term retention.</p>
</li>
<li><p>Day 45 (Fourth Review): By now, the memory is deeply consolidated. Concepts like O(log⁡n) feel as natural and accessible as your own phone number.</p>
</li>
</ol>
<p>Through this process, spaced repetition transforms fragile, short‑term awareness into durable, long‑term knowledge. Each review interrupts the forgetting curve, reinforces the schema, and reduces the cognitive load required to recall the concept in the future.</p>
<p>For self-taught developers, spaced repetition can take many forms. You might rewrite code from memory, re‑implement a feature days later, build small variations of the same concept, or return to the concept after working on different tasks.</p>
<p>Every review strengthens the schema and reduces the cognitive load required to recall it. Over time, what once felt complex becomes automatic — not because the concept changed, but because your brain reorganised it into a stable, efficient structure.</p>
<p>As you can see, learning isn't a single event but a cycle of exposure, forgetting, and reinforcement.</p>
<p>Mastery comes not from seeing something once, but from returning to it until it becomes part of your cognitive architecture.</p>
<p>But we must be careful with repetition. Doing the same thing over and over again doesn't guarantee improvement. In fact, mindless repetition can trap you at the same level indefinitely.</p>
<p>This is where the theory of deliberate practice becomes essential, as it emphasises increasing the level of challenge, focusing on specific weaknesses, and actively seeking feedback so that each repetition leads to measurable improvement rather than just familiarity.</p>
<h2 id="heading-theory-of-deliberate-practice">Theory of Deliberate Practice</h2>
<p>Developed by psychologist K. Anders Ericsson, it argues that expertise is not the result of talent but of high‑quality, intentional practice (Ericsson, 1993). This type of practice is fundamentally different from simply doing something repeatedly.</p>
<p>He coined the term "deliberate practice" while researching how people become experts. Studying experts from several different fields, he dismantled the myth that expert performers have unusual innate talents.</p>
<p>Instead, he discovered that experts attain their high performance through how they practice: it's a deliberate effort to become an expert. This effort is characterized by breaking down required skills into smaller parts and practicing these parts repeatedly.</p>
<p>According to Anders Ericsson, Deliberate Practice requires:</p>
<ol>
<li><p>Clear goals</p>
</li>
<li><p>Immediate feedback</p>
</li>
<li><p>Tasks that stretch your ability just beyond your comfort zone</p>
</li>
<li><p>Full concentration and effort</p>
</li>
</ol>
<p>The main tenet of Deliberate Practice is that tasks must stretch your ability just beyond your comfort zone. This is paramount to the advancement of learning.</p>
<p>Imagine a child being taught 1+1 every day. That child will never grow beyond basic arithmetic. Anders Ericsson calls this "Arrested Development" (Ericsson, Nandagopal and Roring, 2005). For that child to grow to become a mathematician, their knowledge must be stretched.</p>
<p>The takeaway for developers is a play on the DRY principle (Don’t Repeat Yourself): If you are only repeating what you already know without stretching yourself, you aren't growing. This "stretch" is the extra edge that Deliberate Practice adds to Spaced Repetition.</p>
<p>Building a simple to-do list, a calculator, or a weather app over and over again won't take you anywhere. You already know how to do those.</p>
<p>To truly grow, you must stretch yourself. Instead, try a project that integrates new ideas, like building a mini-app where the weather data affects your to-do list. For example, if the API shows it's raining, the app automatically hides outdoor tasks and calculates the time you'll save or the indoor tasks you should prioritize instead.</p>
<p>This forces you to handle complex logic and state management, moving you beyond simple repetition into true mastery.</p>
<p>This ability to create brings me to the last theory: Bloom's Taxonomy.</p>
<h2 id="heading-what-is-blooms-taxonomy">What is Bloom's Taxonomy?</h2>
<p>Bloom’s Taxonomy provides a hierarchy of cognitive skills that learners move through as they develop mastery. It begins with the simplest tasks and progresses toward the most complex:</p>
<ol>
<li><p>Remember – recalling facts or syntax</p>
</li>
<li><p>Understand – explaining concepts in your own words</p>
</li>
<li><p>Apply – using knowledge in real situations</p>
</li>
<li><p>Analyze – breaking problems into parts</p>
</li>
<li><p>Evaluate – judging solutions or comparing approaches</p>
</li>
<li><p>Create – building original systems or applications</p>
</li>
</ol>
<p>Most self‑taught developers get stuck in the first two levels. They memorize syntax and understand examples, but they struggle to apply, analyze, or create.</p>
<p>This isn't because they lack ability. Rather, it's because they haven't been taught that learning must progress through these stages.</p>
<p>Bloom’s Taxonomy gives structure to the learning journey.</p>
<p>It reminds self-taught developers that mastery isn't achieved by watching tutorials but by climbing the ladder from remembering → understanding → applying → analyzing → evaluating → creating (with an emphasis on Creation).</p>
<p>Creation is one of the most difficult yet most transformative experiences in your journey as a developer. It forces you to think abstractly, confront ambiguity, and notice dimensions of a problem that tutorials rarely reveal.</p>
<p>When you build something real, the neatness of the theory in your head collapses, and you begin to see its true complexity. You must then devise strategies to navigate these challenges, and through this process, you learn.</p>
<p>And as with anything worthwhile, the process isn't smooth. You'll encounter bugs — not just one or two, but hundreds. Yet this is precisely how real knowledge is built. Every bug you solve becomes a permanent entry in your long‑term memory.</p>
<p>The next time you see that error, you won’t panic. Instead, you’ll recognise it instantly and know exactly where it’s coming from and how to fix it.</p>
<p>Some self‑taught developers encounter a few bugs and never return to their projects again, concluding that “coding isn’t for me.”</p>
<p>After trying several fixes and seeing no progress, they abandon the work and look for something else. But this is the wrong conclusion. The problem is rarely a lack of talent — it's a misunderstanding of how the brain behaves under cognitive strain.</p>
<h3 id="heading-focused-mode-vs-diffuse-mode">Focused Mode vs Diffuse Mode</h3>
<p>When you spend a long time wrestling with a bug, you may be experiencing mental fixation or functional fixedness.</p>
<p>This is when your brain becomes locked into a single line of reasoning, repeating the same logic path over and over because it feels like the right direction. The longer you stare at the problem, the deeper the cognitive rut becomes. You develop tunnel vision, making it almost impossible to see alternative solutions.</p>
<p>This is where understanding how the brain operates becomes essential.</p>
<p>According to Oakley (2014), the brain works in two primary modes:</p>
<ol>
<li><p>Focused Mode: Ideal for executing a known formula or following a clear procedure, terrible for discovering a new approach or breaking out of a mental rut.</p>
</li>
<li><p>Diffuse Mode: This is activated when you step away — walking, showering, relaxing, or sleeping.</p>
</li>
</ol>
<p>In this second mode, the brain enters a “big‑picture” state where neural connections stretch across different regions.</p>
<p>The background processes continue working on the problem without the restrictive tunnel vision of conscious focus.</p>
<p>This phenomenon is known as incubation.</p>
<p>This is why solutions often appear when you’re not actively thinking about the problem. You step away, and suddenly the answer emerges, not because you stopped working, but because a different part of your brain started working for you.</p>
<p>The reality is that many developers never allow for incubation. While you step away from the problem, your brain performs subconscious synthesis: it clears out the noise (Extraneous Load) and lets the core logic (Germane Load) settle. When you return, the “wrong” paths you were obsessing over have faded, and the correct path which was there all along often finally becomes visible.</p>
<p>This is why developers must deliberately allow for incubation. We can take some lessons from great minds of the past:</p>
<p>Henri Poincaré famously struggled with Fuchsian functions for weeks. It was only during a geological excursion when he had completely forgotten about the mathematics that the solution appeared with “perfect certainty” the moment he stepped onto an omnibus. His breakthrough did not come from more effort, but from stepping away long enough for diffuse mode to take over.</p>
<p>Friedrich August Kekulé experienced something similar after years of wondering why benzene’s carbon atoms didn't fit a linear structure.</p>
<p>If some of the greatest minds in history stepped away from their problems and found solutions in diffuse mode, why should developers treat themselves any differently?</p>
<p>Now that you're familiar with some key learning strategies –&nbsp;Cognitive Load Theory, Spaced Repetition, and Bloom's Taxonomy –&nbsp;creating or building a project from the ground up should be your next task. It will help you curate, retrieve, organise, and seal in all that diverse knowledge you've gathered as a self-taught developer.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, we explored why the human brain isn't instinctively wired to understand programming. Coding is a biologically secondary skill, which means it doesn't develop naturally through immersion but requires explicit instruction, structure, and patience.</p>
<p>We also talked about the limits of working memory, the importance of chunking, and the need to manage cognitive load so that learning remains possible rather than overwhelming.</p>
<p>We then analyzed the three components of Cognitive Load Theory –&nbsp;intrinsic, extraneous, and germane load –&nbsp;and discussed how each influences the learning process. Reducing extraneous load is especially crucial for self‑taught developers, as it frees up mental resources for meaningful understanding.</p>
<p>From there, we turned to the Ebbinghaus Forgetting Curve, which demonstrates how quickly newly learned information fades without reinforcement.</p>
<p>To counter this natural forgetting, we introduced Spaced Repetition, a method that strengthens memory by reviewing material at expanding intervals. We also examined Deliberate Practice, which pushes learners just beyond their comfort zone to promote genuine skill development, and Bloom’s Taxonomy, which outlines the stages of cognitive growth from remembering to creating.</p>
<p>Finally, we emphasized the importance of knowing when to step back. The brain operates in both focused and diffuse modes, and effective learning requires movement between the two. Breaks are not signs of weakness but essential components of consolidation and insight.</p>
<p>Together, these theories form a comprehensive framework for learning to code with scientific precision. When self‑taught developers understand how their brain learns, forgets, and grows, they can design a learning process that isn't only more efficient but far more sustainable.</p>
<p>With all this new knowledge, one truth is certain: focus, determination, and consistency are the forces that transform theory into mastery.</p>
<p>Learning science can guide the process, but only sustained effort turns knowledge into skill.</p>
<h2 id="heading-references">References</h2>
<ol>
<li><p>Clearwater, L. (2024). <em>Understanding the Science Behind Learning Retention | Reports | What We Think | Indegene</em>. [online] <a href="http://www.indegene.com">www.indegene.com</a>. Available at: <a href="https://www.indegene.com/what-we-think/reports/understanding-science-behind-learning-retention">https://www.indegene.com/what-we-think/reports/understanding-science-behind-learning-retention</a>.</p>
</li>
<li><p>Dylan Wiliam [@dylanwiliam]. (2017, January 25). <em>I’ve come to the conclusion Sweller’s Cognitive Load Theory is the single most important thing for teachers to know</em> [Tweet]. X. <a href="https://x.com/dylanwiliam/status/824682504602943489">https://x.com/dylanwiliam/status/824682504602943489</a></p>
</li>
<li><p>Ericsson, K. A., Krampe, R. T., &amp; Tesch-Römer, C. (1993).<br><em>The role of deliberate practice in the acquisition of expert performance.</em><br><strong>Psychological Review, 100(3), 363–406.</strong></p>
</li>
<li><p>Garnett, S. (2020.). <em>Cognitive Load Theory A handbook for teachers</em>. [online] Available at: <a href="https://www.crownhouse.co.uk/assets/look-inside/9781785835018.pdf">https://www.crownhouse.co.uk/assets/look-inside/9781785835018.pdf</a>.</p>
</li>
<li><p>Geary, D. C. (2007). <em>An evolutionary perspective on learning disability in mathematics</em>. Developmental Neuropsychology, 32(1), 471–519. <a href="https://doi.org/10.1080/87565640701360924">https://doi.org/10.1080/87565640701360924</a></p>
</li>
<li><p>Geary, D. C. (2008). <em>An evolutionarily informed education science</em>. Educational Psychologist, 43(4), 179–195. <a href="https://doi.org/10.1080/00461520802392133">https://doi.org/10.1080/00461520802392133</a></p>
</li>
<li><p>George A. Miller (1956). <em>The magical number seven, plus or minus two: Some limits on our capacity for processing information</em>. Psychological Review, 63(2), 81–97. <a href="https://doi.org/10.1037/h0043158">https://doi.org/10.1037/h0043158</a></p>
</li>
<li><p>Nelson Cowan (2001). <em>The magical number 4 in short-term memory: A reconsideration of mental storage capacity</em>. Behavioral and Brain Sciences, 24(1), 87–114. <a href="https://doi.org/10.1017/S0140525X01003922">https://doi.org/10.1017/S0140525X01003922</a></p>
</li>
<li><p>Oakley, B. (2014). <em>A Mind for Numbers: How to Excel at Math and Science (Even If You Flunked Algebra).</em> New York: TarcherPerigee.</p>
</li>
<li><p>Sweller, J. (1988). Cognitive Load during Problem Solving: Effects on Learning. <em>Cognitive Science</em>, [online] 12(2), pp.257–285. doi:<a href="https://doi.org/10.1207/s15516709cog1202_4">https://doi.org/10.1207/s15516709cog1202_4</a>.</p>
</li>
</ol>
<p>‌</p>
<p>‌</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build and Deploy a Fitness Tracker Using Python Django and PythonAnywhere - A Beginner Friendly Guide ]]>
                </title>
                <description>
                    <![CDATA[ If you've learned some Python basics but still feel stuck when it comes to building something real, you're not alone. Many beginners go through tutorials, learn about variables, functions, and loops,  ]]>
                </description>
                <link>https://www.freecodecamp.org/news/build-and-deploy-a-fitness-tracker-using-python-django-and-pythonanywhere/</link>
                <guid isPermaLink="false">69cfff6ce466e2b762506a84</guid>
                
                    <category>
                        <![CDATA[ Programming Blogs ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Django ]]>
                    </category>
                
                    <category>
                        <![CDATA[ deployment ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Beginner Developers ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Prabodh Tuladhar ]]>
                </dc:creator>
                <pubDate>Fri, 03 Apr 2026 17:57:00 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/a1ae273b-9f92-4fc2-89aa-1452fc0df895.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you've learned some Python basics but still feel stuck when it comes to building something real, you're not alone. Many beginners go through tutorials, learn about variables, functions, and loops, and then hit a wall when they try to create an actual project.</p>
<p>The gap between "I know Python syntax" and "I can build a working web app" can feel enormous. But it does not have to be.</p>
<p>In this tutorial, you'll build a fitness tracker web application from scratch using Django, one of the most popular Python web frameworks. By the end, you'll have a fully functional app running live on the internet – something you can show to friends, add to your portfolio, or keep building on.</p>
<p>Here's what you'll learn:</p>
<ul>
<li><p>How Django projects and apps are structured</p>
</li>
<li><p>How to define database models to store workout data</p>
</li>
<li><p>How to create views that handle user requests</p>
</li>
<li><p>How to build HTML templates that display your data</p>
</li>
<li><p>How to connect URLs to views so users can navigate your app</p>
</li>
<li><p>How to deploy your finished app to PythonAnywhere so anyone can access it</p>
</li>
</ul>
<p>The app itself is straightforward: you can log a workout by entering an activity name, duration, and date. You can then view all your logged workouts on a separate page. It's simple, but it covers the core Django concepts you need to build much bigger things later.</p>
<p>Let's get started.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a href="#heading-prerequisites">Prerequisites</a></p>
</li>
<li><p><a href="#heading-what-you-are-going-build">What You Are Going Build</a></p>
</li>
<li><p><a href="#heading-step-1-how-to-set-up-your-django-project">Step 1: How to Set Up Your Django Project</a></p>
<ul>
<li><p><a href="#heading-1-1-how-to-create-a-virtual-environment">1. 1 How to create a virtual environment</a></p>
</li>
<li><p><a href="#heading-12-how-to-install-django">1.2 How to install Django</a></p>
</li>
<li><p><a href="#heading-13-how-to-create-the-project">1.3 How to Create the Project</a></p>
</li>
<li><p><a href="#heading-14-how-to-run-the-development-server">1.4 How to run the development server</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-step-2-how-to-create-a-django-app">Step 2: How to Create a Django App</a></p>
<ul>
<li><p><a href="#heading-21-how-to-generate-the-app">2.1 How to Generate the App</a></p>
</li>
<li><p><a href="#heading-22-how-to-register-the-app">2.2 How to Register the App</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-step-3-how-to-create-a-workout-model">Step 3: How to create a Workout Model</a></p>
<ul>
<li><a href="#heading-31-how-to-define-the-model">3.1 How to Define the Model</a></li>
</ul>
</li>
<li><p><a href="#heading-step-4-how-to-apply-migrations">Step 4: How to Apply Migrations</a></p>
<ul>
<li><p><a href="#heading-41-how-to-generate-the-migration">4.1 How to Generate the Migration</a></p>
</li>
<li><p><a href="#heading-42-how-to-apply-the-migration">4.2 How to Apply the Migration</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-step-5-how-to-register-the-model-in-the-admin-panel">Step 5: How to Register the Model in the Admin Panel</a></p>
<ul>
<li><p><a href="#heading-52-how-to-create-a-superuser">5.2 How to Create a Superuser</a></p>
</li>
<li><p><a href="#heading-53-how-to-access-the-admin-panel">5.3 How to Access the Admin Panel</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-step-6-how-to-create-views-for-the-app">Step 6: How to Create Views for the App</a></p>
<ul>
<li><p><a href="#heading-61-how-to-create-a-form-class">6.1 How to Create a Form Class</a></p>
</li>
<li><p><a href="#heading-62-how-to-write-views">6.2 How to Write Views</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-step-7-how-to-create-templates">Step 7: How to Create Templates</a></p>
<ul>
<li><p><a href="#heading-71-how-to-set-up-the-template-directory">7.1 How to Set Up the Template Directory</a></p>
</li>
<li><p><a href="#heading-72-how-to-create-the-workout-list-template">7.2 How to Create the Workout List Template</a></p>
</li>
<li><p><a href="#heading-73-how-to-create-add-workout-template">7.3 How to Create Add Workout Template</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-step-8-how-to-connect-urls">Step 8: How to Connect URLs</a></p>
<ul>
<li><p><a href="#heading-81-how-to-create-app-level-urls">8.1 How to Create App Level URLs</a></p>
</li>
<li><p><a href="#heading-82-how-to-link-app-urls-to-project">8.2 How to Link App URLs to project</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-step-9-how-to-test-the-application-locally">Step 9: How to Test the Application Locally</a></p>
</li>
<li><p><a href="#heading-step-10-how-to-prepare-for-deployment">Step 10: How to Prepare for Deployment</a></p>
<ul>
<li><a href="#heading-101-how-to-update-settings-for-production">10.1 How to Update Settings for Production</a></li>
</ul>
</li>
<li><p><a href="#heading-step-11-how-to-deploy-your-django-app-on-pythonanywhere">Step 11: How to Deploy Your Django App on PythonAnywhere</a></p>
<ul>
<li><p><a href="#heading-111-how-to-create-a-pythonanywhere-account">11.1 How to Create a PythonAnywhere Account</a></p>
</li>
<li><p><a href="#heading-112-how-to-upload-your-project-files">11.2 How to Upload Your Project Files</a></p>
</li>
<li><p><a href="#heading-113-how-to-set-up-a-virtual-environment-in-pythonanywhere">11.3 How to Set Up a Virtual Environment in PythonAnywhere</a></p>
</li>
<li><p><a href="#heading-114-how-to-run-migrations-and-create-a-superuser-on-pythonanywhere">11.4 How to Run Migrations and Create a SuperUser on PythonAnywhere</a></p>
</li>
<li><p><a href="#heading-114-how-to-configure-the-web-app-in-pythonanywhere">11.4 How to Configure the Web App in Pythonanywhere</a></p>
</li>
<li><p><a href="#heading-115-how-to-set-the-virtual-environment-path">11.5 How to Set the Virtual Environment Path</a></p>
</li>
<li><p><a href="#heading-116-how-to-configure-the-wsgi-file">11.6 How to Configure the WSGI file</a></p>
</li>
<li><p><a href="#heading-117-how-to-set-up-static-files">11.7 How to Set Up Static Files</a></p>
</li>
<li><p><a href="#heading-118-how-to-view-your-live-application">11.8 How to View Your Live Application</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-common-mistakes-and-how-to-fix-them">Common Mistakes and How to Fix Them</a></p>
</li>
<li><p><a href="#heading-how-you-can-improve-this-project">How You Can Improve This Project</a></p>
</li>
<li><p><a href="#heading-conclusion">Conclusion</a></p>
</li>
</ul>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>Before you begin, make sure you are comfortable with the following:</p>
<p><strong>Python fundamentals:</strong> You should understand variables, functions, lists, dictionaries, and basic control flow (if/else statements and loops).</p>
<p><strong>Basic command line usage:</strong> You'll be running commands in your terminal throughout this tutorial. You should know how to open a terminal, navigate between folders, and run commands. If you're on Windows, you can use Command Prompt or PowerShell. On macOS or Linux, the default Terminal app works well.</p>
<p><strong>Tools you'll need installed:</strong></p>
<ul>
<li><p><strong>Python 3.8 or higher.</strong> You can check your version by running <code>python --version</code> or <code>python3 --version</code> in your terminal.&nbsp; If you don't have Python installed, download it from <a href="https://www.python.org">python.org</a></p>
</li>
<li><p><strong>pip.</strong> This is Python's package manager. It usually comes bundled with Python. You can verify by running <code>pip --version</code> or pip3 --version. Note the commands <code>python3</code> and <code>pip3</code> tell the terminal that you are explicitly using <strong>Python Version 3</strong></p>
</li>
<li><p><strong>A code editor.</strong> Visual Studio Code is a great free option, but you can use any editor you're comfortable with.</p>
</li>
</ul>
<p>That's everything. You don't need prior Django experience or web development knowledge. This tutorial will walk you through each step.</p>
<h2 id="heading-what-you-are-going-build">What You Are Going Build</h2>
<p>The fitness tracker you will build has two main features:</p>
<ol>
<li><strong>A form to log workouts.</strong> You will enter the name of an activity (like "Running" or "Push-ups"), how long you did it (in minutes), and the date. When you submit the form, Django saves that workout to a database.</li>
</ol>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/fe6b2a89-fc29-4710-a640-ce2757267e38.png" alt="The image shows a form to log workouts" style="display: block;" width="1864" height="1544" loading="lazy">

<ol>
<li><strong>A page to view all your workouts.</strong> This page displays every workout you have logged, showing the activity, duration, and date in a clean list.</li>
</ol>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/8f6bd09e-497a-4480-83e5-af162028a0a3.png" alt="The image shows a list of logged workouts" style="display: block;" width="2144" height="1720" loading="lazy">

<p>Here's how data flows through the app at a high level:</p>
<ol>
<li><p>You fill out the workout form in your browser and click submit.</p>
</li>
<li><p>Your browser sends that data to Django.</p>
</li>
<li><p>Django's view function receives the data, validates it, and saves it to the database.</p>
</li>
<li><p>When you visit the workouts page, Django's view function pulls all saved workouts from the database.</p>
</li>
<li><p>Django passes that data to an HTML template, which renders it as a page your browser can display.</p>
</li>
</ol>
<img alt="The image shows the data flow of the fitness tracker app with 5 steps" style="display: block;" width="600" height="400" loading="lazy">

<p>This request-response cycle is the foundation of how Django works. Once you understand it, you can build almost anything.</p>
<h2 id="heading-step-1-how-to-set-up-your-django-project">Step 1: How to Set Up Your Django Project</h2>
<p>Every Django project starts with a few setup steps. You'll create an isolated Python environment, install Django, and generate the initial project structure.</p>
<h3 id="heading-1-1-how-to-create-a-virtual-environment">1. 1 How to Create a Virtual Environment</h3>
<p>A virtual environment is a self-contained folder that contains its own Python interpreter and installed packages for a specific project. This keeps your project's dependencies separate from other Python projects on your computer. This separation prevents version conflicts and keeps setups consistent.</p>
<p>For example, one project might require an older version of Django, while another needs the latest version, and a virtual environment allows both to work smoothly on the same system.</p>
<p>Without it, global installations can clash, break projects, and make setups hard to reproduce. Over time, the system environment becomes cluttered with unused or incompatible packages making debugging and maintenance more difficult.</p>
<p>Now let's set it up.</p>
<p>Open your terminal, and navigate to where you want your project to live and run the following command</p>
<pre><code class="language-shell">mkdir fitness-tracker
cd fitness-tracker
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/b4715e51-c2e3-4e97-ad7b-b41066aeefd9.png" alt="An image of the terminal showing the commands mkdir (make directory) and cd (change directory) being typed " style="display: block;" width="2442" height="542" loading="lazy">

<p>The first command creates a new folder called <code>fitness-tracker</code>. The second command moves you into that folder.</p>
<p>You'll create the Python virutal environment here.</p>
<pre><code class="language-shell">python3 -m venv venv
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/3d1723ae-d069-48fd-9954-440a191f585f.png" alt="The image shows the command to create the python virtual enviroment." style="display: block;" width="2374" height="512" loading="lazy">

<p>The above command creates a virtual environment inside a folder called <code>venv</code>. The first <code>venv</code> is the command and the second <code>venv</code> represents the name of the folder. You can name the folder anything though <code>venv</code> is usually preferred.</p>
<p>By using the <code>ls</code> command, you can see that we've created the virtual environment folder.</p>
<p>To activate the virtual environment, we need to use the following command:</p>
<p>On macOS/Linux:</p>
<pre><code class="language-shell">source venv/bin/activate
</code></pre>
<p>On Windows:</p>
<pre><code class="language-shell">venv\Scripts\activate
</code></pre>
<p>You'll know it worked when you see <code>(venv)</code> at the beginning of your terminal prompt. From this point on, any Python packages you install will only exist inside this <strong>virtual environment</strong>.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/dabe362d-2f50-4745-a0bc-e57ad3536723.png" alt="The image shows the virtual environment being activated" style="display: block;" width="2434" height="1066" loading="lazy">

<h3 id="heading-12-how-to-install-django">1.2 How to Install Django</h3>
<p>With your virtual environment activated, install Django using pip:</p>
<pre><code class="language-shell">pip install django
</code></pre>
<p>This downloads and installs the latest stable version of Django. You can verify the installation by running:</p>
<pre><code class="language-shell">python3 -m django --version
</code></pre>
<p>After running both these commands, you should see Django being installed and the version number:</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/bda2ed0d-44bf-439b-a9fd-1cf3fcaf35ca.png" alt="The image shows django being installed and the version of django that has been installed" style="display: block;" width="2818" height="968" loading="lazy">

<h3 id="heading-13-how-to-create-the-project">1.3 How to Create the Project</h3>
<p>We have finished installing Django. Now let's create a Django project. Django provides a command line utility that generates the boilerplate files that you need. Type the following command:</p>
<pre><code class="language-shell">django-admin startproject fitness_project .
</code></pre>
<p>The command creates a folder named <code>fitness-project</code>. Notice the dot at the end of the command. The dot at the end is important. It tells Django to create the project files in your current directory instead of creating an extra nested folder.</p>
<p>Now that we've created our Django project, let's open the project in your favourite text editor and look at folder structure.</p>
<p>You'll notice that the folder already comes with a bunch of files.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/eaffe95e-7078-4c2e-91f4-88a6c3696e88.png" alt="The image show the list of files created by the django-admin startproject command" width="2362" height="1488" loading="lazy">

<h3 id="heading-14-how-to-run-the-development-server">1.4 How to Run the Development Server</h3>
<p>Now let's make sure everything is working. You'll need to run a server for this. Type the following command:</p>
<pre><code class="language-shell">python manage.py runserver
</code></pre>
<p>You can type this command in the terminal with the virtual environment activated or you can use the integrated terminal if you're using VS Code. I'll be using the integrated terminal from this point on.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/53dbba38-9863-4972-a899-1e6ff66fb3f5.png" alt="This is an image of the server running after typing the runserver command" style="display: block;" width="2870" height="1662" loading="lazy">

<p>Open your browser and go to <a href="http://127.0.0.1:8000/">http://127.0.0.1:8000/</a>. You should see Django's default welcome page with a rocket ship graphic confirming that your project is set up correctly.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/25d2e3ce-ce72-44f6-9f5f-78aeaeb88b3e.png" alt="This is an image of Django's default homepage" style="display: block;" width="2872" height="1788" loading="lazy">

<p>Press <code>Ctrl + C</code> in your terminal to stop the server when you're ready to move on.</p>
<h2 id="heading-step-2-how-to-create-a-django-app">Step 2: How to Create a Django App</h2>
<p>In Django, a project is the overall container for your entire web application, while an app is a smaller, self-contained module inside that project that focuses on a specific piece of functionality.</p>
<p>A useful way to picture this is to think of a house. The project is the whole house. Each app is like a room inside that house. One room might be a kitchen, another a bedroom, each designed with a clear purpose. In the same way, a Django app is built to handle one responsibility, such as authentication, payments, or in this case, workout tracking.</p>
<p>Now, here's the important part: why not just put everything into one big project instead of using apps? You technically could, especially for very small projects. But as your application grows, that approach quickly becomes difficult to manage.</p>
<p>By using apps, you naturally separate concerns. It also makes collaboration smoother, since different people can work on different apps without constantly stepping on each other’s code.</p>
<p>Another major benefit is reusability. Since apps are modular, you can take an app from one project and reuse it in another.</p>
<p>For example, if you build a workout tracking app once, you could plug it into a completely different Django project later without rebuilding it from scratch. Later, you might create a completely different project, say a fitness coaching platform or a health dashboard. Instead of rebuilding the tracking feature from scratch, you can reuse the same app.</p>
<p>For this project, you'll create a single app called <code>tracker</code> that handles everything related to logging and displaying workouts.</p>
<h3 id="heading-21-how-to-generate-the-app">2.1 How to Generate the App</h3>
<p>Make sure you're in the same directory as the <code>manage.py</code> file, then run the following code:</p>
<pre><code class="language-shell">python manage.py startapp tracker
</code></pre>
<p>This create a new folder called tracker with the following following structure:</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/cb07105a-6e65-49f9-9c7a-d5a64db42b49.png" alt="The image shows the folder strucutre created by after running the startapp command" style="display: block;" width="2860" height="1250" loading="lazy">

<p>Each file has its own purpose. You'll work with <code>models.py</code>, <code>views.py</code> and <code>admin.py</code> throughout this project.</p>
<h3 id="heading-22-how-to-register-the-app">2.2 How to Register the App</h3>
<p>Django doesn't automatically know about your new app. You need to tell it by adding the app to the <code>INSTALLED_APPS</code> list in <code>settings.py</code> file.</p>
<p>Open <code>fitness_project/settings.py</code> and find the <code>INSTALLED_APPS</code> list. Add the name of the app, that is <code>tracker</code>, to the end of the list:</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/eec90a01-5219-449e-97f8-97465e4ac23f.png" alt="eec90a01-5219-449e-97f8-97465e4ac23f" style="display: block;" width="2868" height="1306" loading="lazy">

<p>You'll notice that a number of apps have already been installed automatically by Django. This is part of Django’s “batteries-included” philosophy, where many common features are ready to use out of the box.</p>
<p>Here is a short summary of what each of the apps does.</p>
<table>
<thead>
<tr>
<th><strong>App Name</strong></th>
<th><strong>Purpose</strong></th>
</tr>
</thead>
<tbody><tr>
<td><strong>django.contrib.admin</strong></td>
<td>Powers the built-in admin dashboard, letting you manage your data through a web interface.</td>
</tr>
<tr>
<td><strong>django.contrib.auth</strong></td>
<td>Handles users, login systems, permissions, and password management.</td>
</tr>
<tr>
<td><strong>django.contrib.contenttypes</strong></td>
<td>Helps Django track and manage relationships between different models.</td>
</tr>
<tr>
<td><strong>django.contrib.sessions</strong></td>
<td>Stores user session data, so users stay logged in across requests.</td>
</tr>
<tr>
<td><strong>django.contrib.messages</strong></td>
<td>Lets you show temporary notifications like success or error messages.</td>
</tr>
<tr>
<td><strong>django.contrib.staticfiles</strong></td>
<td>Manages static assets such as CSS, JavaScript, and images</td>
</tr>
</tbody></table>
<p>Now Django knows your <code>tracker</code> app exists and will include it when running the project.</p>
<h2 id="heading-step-3-how-to-create-a-workout-model">Step 3: How to Create a Workout Model</h2>
<p>A model in Django is a Python class that defines the structure of your data. Each model maps directly to a table in your database. Each attribute on the model becomes a column in that table.</p>
<p>Think of a model as a blueprint for a spreadsheet. The class name is the name of the spreadsheet, and each field is a column header. Every time you save a new workout, Django creates a new row in that spreadsheet.</p>
<h3 id="heading-31-how-to-define-the-model">3.1 How to Define the Model</h3>
<p>Open <code>tracker/models.py</code> and replace its contents with this code:</p>
<pre><code class="language-python">from django.db import models

class Workout(models.Model):
    activity = models.CharField(max_length=200)
    duration = models.IntegerField(help_text="Duration in minutes")
    date = models.DateField()

    def __str__(self):
        return f"{self.activity} - {self.duration} min on {self.date}"
</code></pre>
<p>Let's discuss what each part does:</p>
<ul>
<li><p><code>activity = models.CharField(max_length=200)</code> creates a text fields that can hold up to 200 characters. This is where you'll store the name of the exercise like "Running" or "Cycling".</p>
</li>
<li><p><code>duration = models.IntegerField(help_text="Duration in minutes")</code> creates a whole number field for storing how many minutes the workout lasted. The <code>help_text</code> parameter adds a hint that will appear in forms and the admin panel.</p>
</li>
<li><p><code>date = models.DateField()</code> creates a date field for recording when the workout happened.</p>
</li>
</ul>
<p>The <code>__str__()</code> method defines how a Workout object appears when printed or displayed in the admin panel. Instead of seeing something unhelpful like "<strong>Workout object (1)</strong>," you will see "<strong>Running - 30 min on 2025-03-15.</strong>"</p>
<h2 id="heading-step-4-how-to-apply-migrations">Step 4: How to Apply Migrations</h2>
<p>You've defined your model, but Django hasn't created the actual database table yet. To do that, you need to run migrations.</p>
<p>Migrations are Django's way of translating your Python model definitions into database instructions. Migrations are done in two steps.</p>
<p>When you change a model – maybe by adding a field, removing a field, or renaming one – you create a new migration that describes that change. You can do this using the <code>makemigrations</code> command.</p>
<p>Then you apply the migration using the <code>migrate</code> command and Django updates the database to match.</p>
<p>This two-step process of first detecting the change and then applying the change gives you a reliable record of every change to your database structure over time.</p>
<h3 id="heading-41-how-to-generate-the-migration">4.1 How to Generate the Migration</h3>
<p>Run the following command in the integrated terminal:</p>
<pre><code class="language-shell">python manage.py makemigrations
</code></pre>
<p>You should see output like this:</p>
<pre><code class="language-shell">Migrations for 'tracker': tracker/migrations/0001_initial.py 
    + Create model Workout
</code></pre>
<p>Django inspected your Workout model and created a migration file that describes how to build the corresponding database table. You can find this file at <code>tracker/migrations/0001_initial.py</code> if you want to look at it, but you don't need to edit it.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/fa46eed5-6ef3-408a-8c23-f39518b117f4.png" alt="The image shows the file creating after makemigrations command runs" style="display: block;" width="2880" height="1424" loading="lazy">

<h3 id="heading-42-how-to-apply-the-migration">4.2 How to Apply the Migration</h3>
<p>Now tell Django to execute that migration and actually create the table in the database:</p>
<pre><code class="language-shell">python manage.py migrate
</code></pre>
<p>You'll see several lines of output as Django applies not just your migration, but also the default migrations for Django's built-in apps (authentication, sessions, and so on).</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/fcaae5fe-0cc7-4c1f-b4c3-a3b173fd2551.png" alt="The image shows the output after applying migrations" style="display: block;" width="2864" height="1650" loading="lazy">

<p>When it finishes, your database has a table ready to store workouts.</p>
<p>When the migrate command runs, we can see the exact SQL commands that Django used to build and change the database. Though this isn't required for creating the application, it's always good to know what's happening under hood.</p>
<p>Run this command:</p>
<pre><code class="language-shell">python manage.py sqlmigrate tracker 001
</code></pre>
<p>And you should get this output:</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/016b0a33-06d0-47e8-97de-580e79a7d0e3.png" alt="The image shows the command to view sql queries created by django" style="display: block;" width="2824" height="1628" loading="lazy">

<p>The <code>001</code> you added at the end is the migration number and represents first version of the database schema.</p>
<p>In practice, your workflow usually looks like this: you change your models, run <code>makemigrations</code> to generate the migration files, and then run the <code>migrate</code> command to apply those changes to the database.</p>
<h2 id="heading-step-5-how-to-register-the-model-in-the-admin-panel">Step 5: How to Register the Model in the Admin Panel</h2>
<p>Django comes with a powerful admin interface built in. It gives you a graphical way to view, add, edit, and delete records in your database without writing any extra code. This is incredibly useful during development because you can quickly test your models and see your data.</p>
<p>But by default, it doesn’t know:</p>
<ul>
<li><p>Which models you want to manage</p>
</li>
<li><p>How you want them displayed</p>
</li>
</ul>
<p>So you <em>register</em> models in <code>admin.py</code> to tell Django to include the specific model in the admin interface.</p>
<h3 id="heading-51-how-to-add-model-to-admin">5.1 How to Add Model to Admin</h3>
<p>Open <code>tracker/admin.py</code> and add the following code:</p>
<pre><code class="language-python">from django.contrib import admin
from .models import Workout

admin.site.register(Workout)
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/ad017508-993a-4c28-ade1-8e73fa0c6a4a.png" alt="ad017508-993a-4c28-ade1-8e73fa0c6a4a" style="display: block;" width="2854" height="816" loading="lazy">

<p>This single line tells Django to include the <code>Workout</code> model in the admin interface.</p>
<h3 id="heading-52-how-to-create-a-superuser">5.2 How to Create a Superuser</h3>
<p>To access the admin panel, you need an admin account. Create one by running:</p>
<pre><code class="language-python">python manage.py createsuperuser
</code></pre>
<p>Django will prompt you for a username, email address, and password. Choose something you will remember. The email is optional – you can press Enter to skip it.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/4bbc7a15-682e-497d-a4a4-3e2dc4b848ac.png" alt="The image shows the superuser being created by adding username, email and password" style="display: block;" width="2878" height="1362" loading="lazy">

<h3 id="heading-53-how-to-access-the-admin-panel">5.3 How to Access the Admin Panel</h3>
<p>Start the development server:</p>
<pre><code class="language-python">python manage.py runserver
</code></pre>
<p>Then navigate to <a href="http://127.0.0.1:8000/admin/">http://127.0.0.1:8000/admin/</a> in your browser. Log in with the credentials you just created.</p>
<p>You should see the Django administration dashboard with a "<strong>Tracker</strong>" section containing your "<strong>Workouts</strong>" model.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/a1e576bf-45f6-40dc-b6b9-69899b2df9d5.png" alt="The image shows the Django admin panel and the Worker model of the Tracker app being added to the admin panel" style="display: block;" width="2860" height="1406" loading="lazy">

<p>Try clicking "Add" to create a couple of test workouts. This will confirm that your model is working correctly before you build the rest of the app.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/944ea6a4-bc6f-4321-87c0-5c7bcb267e26.png" alt="The image show some workouts (running and cycling) being added to the admin panel" style="display: block;" width="2876" height="1146" loading="lazy">

<h2 id="heading-step-6-how-to-create-views-for-the-app">Step 6: How to Create Views for the App</h2>
<p>A view in Django is a Python function (or class) that receives a web request and returns a web response. That response could be an HTML page, a redirect, a 404 error, or anything else a browser can handle.</p>
<p>Views are where your application logic lives. They decide what data to fetch, what processing to do, and what to show the user.</p>
<p>For this app, you need two views: one to display the form where users add a workout, and one to display the list of all saved workouts.</p>
<h3 id="heading-61-how-to-create-a-form-class">6.1 How to Create a Form Class</h3>
<p>Before writing the views, you need a Django form that handles the workout input.</p>
<p>Django forms are a built-in way to handle user input like login forms, contact forms, or anything that collects data from a user. Instead of manually writing HTML, validating inputs, and handling errors, Django gives you a structured way to do all of that in one place.</p>
<p>Most user inputs are based on the models you’ve created, and Django can automatically generate forms from those models using <code>ModelForms</code>, which speeds things up significantly.</p>
<p>Let's create a new file called <code>forms.py</code> in the <code>tracker</code> folder and add the following code:</p>
<pre><code class="language-python">from django import forms
from .models import Workout

class WorkoutForm(forms.ModelForm):

    class Meta:
        model = Workout
        fields = ['activity', 'duration', 'date']
        widgets = {
            'date': forms.DateInput(attrs={'type': 'date'}),
        }
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/e8bce19c-7184-45b3-9afe-3a5f73cff43b.png" alt="The image shows the file location of forms.py as well the code for forms.py file" style="display: block;" width="2866" height="1232" loading="lazy">

<p>In the above code, the <code>ModelForm</code> automatically generates form fields based on the <code>Workout</code> model. The <code>widgets</code> dictionary tells Django to render the date field as an HTML date picker instead of a plain text input.</p>
<p>We can actually see the forms being automatically created by Django. For this we need to enter the shell. In the terminal, type the following command:</p>
<pre><code class="language-shell">python manage.py shell
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/951829fb-98e8-48f5-8187-80cc98346e06.png" alt="The image shows the python shell being activated" style="display: block;" width="2244" height="932" loading="lazy">

<p>Now lets import the <code>WorkoutForm</code> class that we just created.</p>
<p>Type the following code:</p>
<pre><code class="language-shell">from tracker.forms import WorkoutForm
</code></pre>
<p>Notice that we've given the <strong>name of the app</strong> as well when we imported the form.</p>
<p>Then create an object of the <code>WorkoutForm</code> class and print it.</p>
<pre><code class="language-shell">from tracker.forms import WorkoutForm
workoutform = WorkoutForm()
print(workoutform) 
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/b81265a2-7c21-453b-ae57-3cfec97fbaf9.png" alt="The image shows the command to open the python shell where you can execute python statement throught the terminal" style="display: block;" width="2236" height="652" loading="lazy">

<p>You should get the following output:</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/094b0d89-b003-49b6-939d-07eacfb0c745.png" alt="This image shows the html generated from ModelForm" style="display: block;" width="936" height="632" loading="lazy">

<p>You can see that all the model fields have been renderd as HTML forms and the date field has been created as a date type that is <code>type="date"</code> instead of plain text.</p>
<h3 id="heading-62-how-to-write-views">6.2 How to Write Views</h3>
<p>As we've discussed above, our project has two views: one to add a workout and the other to display all the saved workouts.</p>
<p>First, let's create a view to add a workout. In the <code>tracker/views.py</code> file, type the following code:</p>
<pre><code class="language-python">from django.shortcuts import render, redirect
from .models import Workout

# view to list all workouts
def workout_list(request):
    workouts = Workout.objects.all().order_by('-date')
    return render(request, 'tracker/workout_list.html', {'workouts': workouts})
</code></pre>
<p>Let's walk through this view:</p>
<ul>
<li><p>The <code>workout_list</code> view handles the page that displays all workouts.</p>
</li>
<li><p>It queries the database for every <code>Workout</code> object, orders them by date (most recent first, thanks to the <code>-</code> prefix), and passes that list to a template called <code>workout_list.html</code>.</p>
</li>
<li><p>The <code>render</code> function combines the template with the data and returns the finished HTML page.</p>
</li>
</ul>
<p>To create the logic to add a workout, first add the <code>Workout</code> form import at the end of the import section. Then add the following code after the <code>workout_list</code> view:</p>
<pre><code class="language-python">from django.shortcuts import render, redirect
from .models import Workout
from .forms import WorkoutForm

# view to list all the workouts
def workout_list(request):
    workouts = Workout.objects.all().order_by('-date')
    return render(request, 'tracker/workout_list.html', {'workouts': workouts})

# view to add a workout
def add_workout(request):
    if request.method == 'POST':
        form = WorkoutForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('workout_list')
    else:
        form = WorkoutForm()
    return render(request, 'tracker/add_workout.html', {'form': form})
</code></pre>
<ul>
<li><p>The <code>add_workout</code> view handles both displaying the empty form and processing submitted form data.</p>
</li>
<li><p>When a user first visits the page, the request method is GET, so Django creates a blank form and renders it.</p>
</li>
<li><p>When the user fills out the form and clicks submit, the request method is POST. Django then validates the submitted data, saves it to the database if everything is correct, and redirects the user to the workout list page.</p>
</li>
<li><p>If the data isn't valid, Django re-renders the form with error messages.</p>
</li>
</ul>
<p>Here is the complete views code:</p>
<pre><code class="language-python">from django.shortcuts import render, redirect
from .models import Workout
from .forms import WorkoutForm

# view to list all workouts
def workout_list(request):
    workouts = Workout.objects.all().order_by('-date')
    return render(request, 'tracker/workout_list.html', {'workouts': workouts})

# view to add a workout
def add_workout(request):
    if request.method == 'POST':
        form = WorkoutForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('workout_list')
    else:
        form = WorkoutForm()
    return render(request, 'tracker/add_workout.html', {'form': form})

</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/8a0878c1-f029-49a4-8a7f-308cdb843b62.png" alt="The image shows the complete code for views.py with explanation about the add workout view" style="display: block;" width="2316" height="1076" loading="lazy">

<h2 id="heading-step-7-how-to-create-templates">Step 7: How to Create Templates</h2>
<p>Templates are HTML files that Django fills in with dynamic data. They're the front end of your application: the part users actually see in their browser.</p>
<h3 id="heading-71-how-to-set-up-the-template-directory">7.1 How to Set Up the Template Directory</h3>
<p>Django looks for templates inside a <code>templates</code> folder within each app. Create the following folder structure inside your <code>tracker</code> app.</p>
<p><code>tracker/templates/tracker</code></p>
<p>The double <code>tracker</code> folder name might look redundant, but it's a Django convention called <strong>template namespacing</strong>. It prevents naming conflicts if you have multiple apps with templates that share the same filename.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/cfbe85c3-36dc-413e-918a-aa64d706d2fc.png" alt="The image shows folder structure of the templates folder" style="display: block;" width="832" height="474" loading="lazy">

<h3 id="heading-72-how-to-create-the-workout-list-template">7.2 How to Create the Workout List Template</h3>
<p>Create a file called <code>tracker/templates/tracker/workout_list.html</code> and add the following code:</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
    &lt;title&gt;My Workouts&lt;/title&gt;
    &lt;style&gt;
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
            background-color: #f5f7fa;
            color: #333;
            line-height: 1.6;
            padding: 2rem;
        }

        .container {
            max-width: 700px;
            margin: 0 auto;
        }

        h1 {
            font-size: 1.8rem;
            margin-bottom: 1rem;
            color: #1a1a2e;
        }

        .add-link {
            display: inline-block;
            background-color: #4361ee;
            color: white;
            padding: 0.6rem 1.2rem;
            border-radius: 6px;
            text-decoration: none;
            margin-bottom: 1.5rem;
            font-size: 0.95rem;
        }

        .add-link:hover {
            background-color: #3a56d4;

        }

        .workout-card {
            background: white;
            border-radius: 8px;
            padding: 1rem 1.2rem;
            margin-bottom: 0.8rem;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
            display: flex;
            justify-content: space-between;
            align-items: center;

        }

        .workout-activity {
            font-weight: 600;
            font-size: 1.05rem;

        }

        .workout-details {
            color: #666;
            font-size: 0.9rem;

        }

        .empty-state {
            text-align: center;
            padding: 3rem 1rem;
            color: #888;

        }

    &lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;div class="container"&gt;
        &lt;h1&gt;My Workouts&lt;/h1&gt;
        &lt;a href="{% url 'add_workout' %}" class="add-link"&gt;+ Log a Workout&lt;/a&gt;
        {% if workouts %}
            {% for workout in workouts %}
                &lt;div class="workout-card"&gt;
                    &lt;div&gt;
                        &lt;div class="workout-activity"&gt;{{ workout.activity }}&lt;/div&gt;
                        &lt;div class="workout-details"&gt;{{ workout.duration }} minutes&lt;/div&gt;
                    &lt;/div&gt;
                    &lt;div class="workout-details"&gt;{{ workout.date }}&lt;/div&gt;
                &lt;/div&gt;
            {% endfor %}

        {% else %}
            &lt;div class="empty-state"&gt;
                &lt;p&gt;No workouts logged yet. Start by adding one!&lt;/p&gt;
            &lt;/div&gt;
        {% endif %}
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>There are a few things worth noting here:</p>
<p>If you look closely at the HTML, you'll spot some weird-looking tags wrapped in curly braces ( <code>{% %}</code> and <code>{{ }}</code> ). Think of them as special instructions for Django.</p>
<p>You use the double curly braces (<code>{{ }}</code>) when you want to output or display a piece of data directly on the page.</p>
<p>On the other hand, you use the brace-and-percent-sign combo ( <code>{% %}</code> ) when you need Django to actually perform an action or apply logic, like running a loop or checking a condition.</p>
<p>They allow us to inject dynamic data straight from our Python backend right into our otherwise static HTML.</p>
<p>Lets look at this code snippet for the <code>workout_list.html</code></p>
<pre><code class="language-html">&lt;body&gt;
    &lt;div class="container"&gt;
        &lt;h1&gt;My Workouts&lt;/h1&gt;
        &lt;a href="{% url 'add_workout' %}" class="add-link"&gt;+ Log a Workout&lt;/a&gt;
        {% if workouts %}
            {% for workout in workouts %}
                &lt;div class="workout-card"&gt;
                    &lt;div&gt;
                        &lt;div class="workout-activity"&gt;{{ workout.activity }}&lt;/div&gt;
                        &lt;div class="workout-details"&gt;{{ workout.duration }} minutes&lt;/div&gt;
                    &lt;/div&gt;
                    &lt;div class="workout-details"&gt;{{ workout.date }}&lt;/div&gt;
                &lt;/div&gt;
            {% endfor %}

        {% else %}
            &lt;div class="empty-state"&gt;
                &lt;p&gt;No workouts logged yet. Start by adding one!&lt;/p&gt;
            &lt;/div&gt;
        {% endif %}
    &lt;/div&gt;
&lt;/body&gt;
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/864ed3dc-ceda-44f8-ba3d-b061222714c7.png" alt="The image shows the the body section of the workout_list.html with the focus on django template tags" style="display: block;" width="1988" height="1160" loading="lazy">

<p>There are a few things worth noting here.</p>
<p>Right under the main heading, you'll see this line:<br><code>&lt;a href="{% url 'add_workout' %}"&gt;</code></p>
<p>Instead of hardcoding a web link like <code>href="/add-workout/"</code>, Django uses the <code>{% url %}</code> tag to generate the link dynamically. You pass it the name of the route (in this case, <code>add_workout</code>), and Django automatically figures out the correct URL path.</p>
<p>If you ever change the URL structure in your Python code later, Django updates this link automatically. You never have to hunt through HTML files to fix broken links!</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/2dc56430-d146-4fc9-8ae5-a3fb5a0d7dd1.png" alt="The image highlights the code that generates dynamic url" style="display: block;" width="1748" height="632" loading="lazy">

<p>The <code>{% if workouts %}</code> block checks whether there are any workouts to display. If the list is empty, it shows a friendly message instead of a blank page.</p>
<p>The <code>{% for workout in workouts %}</code> loop iterates over every workout in the list and renders a card for each one. The double curly braces <code>{{ workout.activity }}</code> insert the value of each field into the HTML</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/f75b5c7e-5cd0-457c-901f-e489c26a8175.png" alt="f75b5c7e-5cd0-457c-901f-e489c26a8175" style="display: block;" width="2012" height="1002" loading="lazy">

<p>Inside the loop, you'll notice tags that look like this:</p>
<ul>
<li><p><code>{{ workout.activity }}</code></p>
</li>
<li><p><code>{{ workout.duration }}</code></p>
</li>
<li><p><code>{{ workout.date }}</code></p>
</li>
</ul>
<p>As Django loops through each workout object, it uses dot notation to peek inside that specific object and grab its details. It grabs the activity type (like "Running"), the duration ("30"), and the date ("March 30"), and prints that exact text directly onto the webpage for the user to see.</p>
<h3 id="heading-73-how-to-create-add-workout-template">7.3 How to Create Add Workout Template</h3>
<p>Create a file called <code>tracker/templates/tracker/add_workout.html</code> and add the following code:</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
    &lt;title&gt;Log a Workout&lt;/title&gt;
    &lt;style&gt;
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;

        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
            background-color: #f5f7fa;
            color: #333;
            line-height: 1.6;
            padding: 2rem;
        }

        .container {
            max-width: 500px;
            margin: 0 auto;

        }

        h1 {
            font-size: 1.8rem;
            margin-bottom: 1.5rem;
            color: #1a1a2e;
        }

        .form-group {
            margin-bottom: 1.2rem;
        }

        label {
            display: block;
            margin-bottom: 0.3rem;
            font-weight: 600;
            font-size: 0.95rem;

        }

        input[type="text"],
        input[type="number"],
        input[type="date"] {
            width: 100%;
            padding: 0.6rem 0.8rem;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 1rem;
            transition: border-color 0.2s;
        }

        input:focus {
            outline: none;
            border-color: #4361ee;

        }

        .btn {
            background-color: #4361ee;
            color: white;
            padding: 0.7rem 1.5rem;
            border: none;
            border-radius: 6px;
            font-size: 1rem;
            cursor: pointer;
            margin-right: 0.5rem;
        }

        .btn:hover {
            background-color: #3a56d4;
        }

        .back-link {
            color: #4361ee;
            text-decoration: none;
            font-size: 0.95rem;
        }

        .back-link:hover {
            text-decoration: underline;
        }

        .actions {
            display: flex;
            align-items: center;
            gap: 1rem;
            margin-top: 0.5rem;
        }

        .error-list {
            color: #e74c3c;
            font-size: 0.85rem;
            margin-top: 0.3rem;

        }

    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div class="container"&gt;
       &lt;h1&gt;Log a Workout&lt;/h1&gt;
        &lt;form method="post"&gt;
            {% csrf_token %}
            &lt;div class="form-group"&gt;
                &lt;label for="id_activity"&gt;Activity&lt;/label&gt;
                {{ form.activity }}
                {% if form.activity.errors %}
                    &lt;div class="error-list"&gt;{{ form.activity.errors }}&lt;/div&gt;
                {% endif %}
            &lt;/div&gt;
            &lt;div class="form-group"&gt;
                &lt;label for="id_duration"&gt;Duration (minutes)&lt;/label&gt;
                {{ form.duration }}
                {% if form.duration.errors %}
                    &lt;div class="error-list"&gt;{{ form.duration.errors }}&lt;/div&gt;
                {% endif %}
            &lt;/div&gt;

            &lt;div class="form-group"&gt;
                &lt;label for="id_date"&gt;Date&lt;/label&gt;
                {{ form.date }}
                {% if form.date.errors %}
                    &lt;div class="error-list"&gt;{{ form.date.errors }}&lt;/div&gt;
                {% endif %}
            &lt;/div&gt;

            &lt;div class="actions"&gt;
                &lt;button type="submit" class="btn"&gt;Save Workout&lt;/button&gt;
                &lt;a href="{% url 'workout_list' %}" class="back-link"&gt;Cancel&lt;/a&gt;
            &lt;/div&gt;
        &lt;/form&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>In the previous template, we learned how to display data. Now, we're looking at a form that actually collects data. Handling forms manually in web development can get messy, but Django provides some powerful template tags to do the heavy lifting for us.</p>
<p>Let's look at the Django-specific logic powering this form:</p>
<p>First, right after opening the <code>&lt;form&gt;</code> tag, you'll spot a very important line: <code>{% csrf_token %}</code>. Whenever you submit data to a server using a "POST" method, malicious sites can potentially intercept or forge that request.</p>
<p>By including this <code>{% csrf_token %}</code>, you tell Django to generate a unique, hidden security key for the form. When the user clicks "Save Workout," Django checks this token to guarantee the request is legitimate. <strong>If you forget this tag, Django will simply reject your form!</strong></p>
<pre><code class="language-html">&lt;form method="post"&gt;
            {% csrf_token %}
            &lt;div class="form-group"&gt;
                &lt;label for="id_activity"&gt;Activity&lt;/label&gt;
                {{ form.activity }}
                {% if form.activity.errors %}
                    &lt;div class="error-list"&gt;{{ form.activity.errors }}&lt;/div&gt;
                {% endif %}
            &lt;/div&gt;
            &lt;div class="form-group"&gt;
                &lt;label for="id_duration"&gt;Duration (minutes)&lt;/label&gt;
                {{ form.duration }}
                {% if form.duration.errors %}
                    &lt;div class="error-list"&gt;{{ form.duration.errors }}&lt;/div&gt;
                {% endif %}
            &lt;/div&gt;

            &lt;div class="form-group"&gt;
                &lt;label for="id_date"&gt;Date&lt;/label&gt;
                {{ form.date }}
                {% if form.date.errors %}
                    &lt;div class="error-list"&gt;{{ form.date.errors }}&lt;/div&gt;
                {% endif %}
            &lt;/div&gt;

            &lt;div class="actions"&gt;
                &lt;button type="submit" class="btn"&gt;Save Workout&lt;/button&gt;
                &lt;a href="{% url 'workout_list' %}" class="back-link"&gt;Cancel&lt;/a&gt;
            &lt;/div&gt;
        &lt;/form&gt;
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/4ca2a034-119c-4dc7-a14a-cd0a81815c58.png" alt="The image shows a screenshot of the code and highlight the csrf token tag" style="display: block;" width="1580" height="824" loading="lazy">

<p>Now let's talk about automatically generating the form fields. Instead of manually typing out all the HTML <code>&lt;input&gt;</code> tags for the activity, duration, and date, we let Django do it for us using display tags (<code>{{ }}</code>).</p>
<p>Each <code>{{ form.activity }}</code>, <code>{{ form.duration }}</code>, and <code>{{ form.date }}</code> tag renders the corresponding form input. Django handles the HTML attributes, input types, and validation for you based on the model and form definitions.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/c2403685-b78d-4aa7-876d-63ca53481e37.png" alt="This image shows the code that automatically generates HTML forms" style="display: block;" width="936" height="572" loading="lazy">

<p>The error blocks below each field display validation messages if a user submits invalid data, like entering text in the duration field instead of a number. Users make mistakes. They might leave a required field blank or type text into a number field. Fortunately, Django validates the data for you and sends back errors if something goes wrong.</p>
<p>Underneath each input field, we use a logic block that looks like this:<br><code>{% if form.activity.errors %}</code></p>
<p>This code checks a simple condition: Did the user mess up this specific field? If Django found an error with the "activity" input, the code drops into the if block and uses<code>{{ form.activity.errors }}</code> block to print the exact error message (like "<strong>This field is required</strong>") right below the input box.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/97a61f9d-faf6-4ddd-ab17-d53da88e0d07.png" alt="This image displays the error blocks" style="display: block;" width="1908" height="1116" loading="lazy">

<p>You may notice that both templates include inline CSS rather than a separate stylesheet. For a small project like this, inline styles keep things simple and self-contained. In a larger project, you would use Django's static files system to manage CSS separately.</p>
<h2 id="heading-step-8-how-to-connect-urls">Step 8: How to Connect URLs</h2>
<p>You have views and templates, but Django doesn't know when to use them yet. You need to map URLs to views so that visiting a specific address in the browser triggers the right view function.</p>
<h3 id="heading-81-how-to-create-app-level-urls">8.1 How to Create App Level URLs</h3>
<p>Create a new file called <code>tracker/urls.py</code> and add the following code:</p>
<pre><code class="language-python">from django.urls import path
from . import views

urlpatterns = [ 
    path('', views.workout_list, name='workout_list'), 
    path('add/', views.add_workout, name='add_workout'), 
]
</code></pre>
<p>Each path function takes three arguments.</p>
<p>The first is the route string that represents a URL pattern (an empty string means the root of the app).</p>
<p>The second is the view function to call when that URL is visited.</p>
<p>The third is a name you can use to reference this URL elsewhere in your code, like in the <code>{% url %}</code> template tags you used earlier.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/d9128270-eec3-43af-93de-08780b4a53f5.png" alt="The image contains the description of three arguments of the path function" style="display: block;" width="2864" height="1056" loading="lazy">

<h3 id="heading-82-how-to-link-app-urls-to-project">8.2 How to Link App URLs to project</h3>
<p>Now that your app-level URLs are set up, the next step is to connect them to the main project so Django knows where to start routing requests. Think of it like linking a smaller map (your app) to a bigger map (your project), so everything works together smoothly.</p>
<p>Open <code>fitness_project.urls.py</code> and update it to include your app's URLs:</p>
<pre><code class="language-python">from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('tracker.urls')),
]
</code></pre>
<p>The <code>include()</code> function tells Django to look at the URL patterns defined in the <code>tracker/urls.py</code> file whenever someone visits your site. The empty string prefix means your tracker app handles requests at the root of the site.</p>
<p>Here's the full picture of how a request flows through the URL system.</p>
<p>When someone visits <a href="http://127.0.0.1:8000/add/">http://127.0.0.1:8000/add/</a>, Django first checks <code>fitness_project/urls.py</code>. It matches the empty prefix and delegates to <code>tracker/urls.py</code>. There, it matches <code>add/</code> and calls the <code>add_workout view</code>.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/4590c4e3-0d32-4865-90db-a6504ee508c1.png" alt="The image shows the how the URL flows through the system" style="display: block;" width="2764" height="1146" loading="lazy">

<h2 id="heading-step-9-how-to-test-the-application-locally">Step 9: How to Test the Application Locally</h2>
<p>At this point, your app has everything it needs to work. Let's test it.</p>
<p>Start the development server by running the command:</p>
<pre><code class="language-shell">python manage.py runserver
</code></pre>
<p>Open your browser and visit <a href="http://127.0.0.1:8000/">http://127.0.0.1:8000/</a>. You should see the workout list page with the heading "<strong>My Workouts</strong>" and a button that says "<strong>+ Log a Workout</strong>."</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/e15dc4cf-09b0-4ba9-95b1-baba32ce929f.png" alt="The image shows the My Workouts image with the button to log a workout" style="display: block;" width="2186" height="1006" loading="lazy">

<p>Click that button. You should see the workout form with fields for activity, duration, and date.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/d9790d3e-0b6a-4e1b-b3d9-f305bc254cfc.png" alt="The image shows an empty form to log a workout" style="display: block;" width="1146" height="838" loading="lazy">

<p>Fill in some test data:</p>
<ul>
<li><p>Activity: Skipping</p>
</li>
<li><p>Duration: 25</p>
</li>
<li><p>Date: Pick today's date from the date picker</p>
</li>
</ul>
<p>Click "<strong>Save Workout</strong>" You should be redirected back to the workout list page, and your new workout should appear as a card.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/3f1dbf8f-3547-45ec-961d-cff75092ec02.png" alt="The image shows the workout list after adding a new workout" style="display: block;" width="1656" height="1042" loading="lazy">

<p>Try adding a few more workouts with different activities and dates. Make sure they all show up on the list page in the correct order (most recent first).</p>
<p>This is also a good time to experiment. Try submitting the form with missing fields and see how Django handles validation.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/542e32cf-abf5-4f11-9d4e-0733697c591b.png" alt="The image shows an incomplete form being submitted and a correspoding error message" style="display: block;" width="1284" height="1012" loading="lazy">

<p>Try accessing the admin panel at <a href="http://127.0.0.1:8000/admin/">http://127.0.0.1:8000/admin/</a> to see your workouts there as well.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/cdfbcbf3-f7b6-4b97-92ee-dcc27e2ce60c.png" alt="This image shows the added workouts in Django admin" style="display: block;" width="2876" height="848" loading="lazy">

<p>If everything works as expected, you're ready to put your app on the internet.</p>
<h2 id="heading-step-10-how-to-prepare-for-deployment">Step 10: How to Prepare for Deployment</h2>
<p>Running your app on localhost is great for development, but nobody else can see it. Deployment means putting your app on a server that's accessible from anywhere on the internet.</p>
<p>Before you deploy, you'll need to make a few changes to your project's settings.</p>
<h3 id="heading-101-how-to-update-settings-for-production">10.1 How to Update Settings for Production</h3>
<p>Open <code>fitness_project/settings.py</code> and make the following changes.</p>
<p>First, set <code>DEBUG</code> to <code>False</code>.</p>
<p>During development, <code>DEBUG = True</code> shows detailed error pages that help you fix problems. In production, these error pages would expose sensitive information about your code and server to anyone who triggers an error.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/6b8b491e-d0ae-4a93-80bf-92134e46ff22.png" alt="The image shows the DEBUG being set to False in the settings.py file" style="display: block;" width="2866" height="1348" loading="lazy">

<p>Next, update <code>ALLOWED_HOSTS</code> to include <strong>PythonAnywhere's</strong> <strong>domain</strong>.</p>
<p>This setting tells Django which domain names are allowed to serve your app. Replace yourusername with the actual PythonAnywhere username you will create in the next step.</p>
<pre><code class="language-python">ALLOWED_HOSTS = ['yourusername.pythonanywhere.com']
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/050746f6-d076-41de-8810-08bf539bfda5.png" alt="The image shows the allowed host list being updated to add the pythonanywhere domain" style="display: block;" width="1622" height="1068" loading="lazy">

<p>Finally, add a <code>STATIC_ROOT</code> setting so Django knows where to collect your static files (CSS, JavaScript, images) for production:</p>
<pre><code class="language-python">import os
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/712e0514-42f6-4292-ae52-99f49b6f162b.png" alt="The image shows the code to collect static files" style="display: block;" width="2862" height="1054" loading="lazy">

<p>These are the minimum changes needed for a basic deployment.</p>
<p>💡 For a production app handling real user data, you would also want to set a secure SECRET_KEY, configure a proper database like PostgreSQL, and set up HTTPS. But for a learning project, these changes are enough.</p>
<h2 id="heading-step-11-how-to-deploy-your-django-app-on-pythonanywhere">Step 11: How to Deploy Your Django App on PythonAnywhere</h2>
<p>PythonAnywhere is a hosting platform designed specifically for Python web applications. It offers a free tier that's perfect for beginner projects, and it handles much of the server configuration that would otherwise be complex to set up on your own.</p>
<h3 id="heading-111-how-to-create-a-pythonanywhere-account">11.1 How to Create a PythonAnywhere Account</h3>
<p>Go to <a href="http://pythonanywhere.com">pythonanywhere.com</a> and sign up for a free "Beginner" account. Remember the username you choose, because your app will be available at <a href="http://yourusername.pythonanywhere.com"><strong>yourusername.pythonanywhere.com</strong></a><strong>.</strong></p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/e64e7ca4-7d7d-40a7-a56b-259bb706461f.png" alt="The image shows the homepage of pythonanywhere" style="display: block;" width="2854" height="1782" loading="lazy">

<p>Now signup to the website. Fill in the username, email and password and click on the free tier or now.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/fde55ec6-16f4-4a4f-8927-7b01d3e36a96.png" alt="The image shows the various tiers of python anywhere websites" style="display: block;" width="2758" height="1418" loading="lazy">

<h3 id="heading-112-how-to-upload-your-project-files">11.2 How to Upload Your Project Files</h3>
<p>After logging in, you have two options for getting your project files onto PythonAnywhere.</p>
<h4 id="heading-option-a-upload-using-git">Option A: Upload using Git</h4>
<p>If your project is in a Git repository, open a Bash console from the PythonAnywhere dashboard by clicking "Consoles" and then "Bash." Then clone your repository:</p>
<p>git clone <a href="https://github.com/yourusername/fitness-tracker.git">https://github.com/yourusername/fitness-tracker.git</a></p>
<p>In this tutorial, we won't be using Git. Instead we'll follow the second option.</p>
<h4 id="heading-option-b-upload-files-manually">Option B: Upload files manually</h4>
<p>First go your project folder in your computer and created a compressed version of the project.</p>
<p>IMPORTANT NOTE: When you create the compressed file, make sure to first create a copy of the project somewhere and remove the venv and pycache folder before you compress it.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/169dcd52-50f0-44c0-82d4-1dea1196ac88.png" alt="The image shows the project folder being compressed" style="display: block;" width="1564" height="422" loading="lazy">

<p>Navigate to your home directory and click on upload file tab and upload the compressed file.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/633c7b1f-0088-4d2d-8911-b45e86aa39c2.png" alt="The image shows the compressed file being uploaded to pythonanywhere" style="display: block;" width="2668" height="1096" loading="lazy">

<p>Now we need to unzip the compressed file. To do this, go to the Consoles tab and click on Bash console.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/7774a88e-362e-4680-a19d-32e0ef09fe04.png" alt="The image shows the Consoles tab and bash option" style="display: block;" width="2692" height="1198" loading="lazy">

<p>The bash console should open. Then type the following command in the console to unzip the folder:</p>
<pre><code class="language-shell">unzip fitness-tracker.zip
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/1ae044ad-8996-4191-868a-33566c2483d9.png" alt="The image shows the result of the unzip command" style="display: block;" width="2330" height="1078" loading="lazy">

<h3 id="heading-113-how-to-set-up-a-virtual-environment-in-pythonanywhere">11.3 How to Set Up a Virtual Environment in PythonAnywhere</h3>
<p>Open a Bash console from the PythonAnywhere dashboard. Navigate to your project directory and create a fresh virtual environment:</p>
<pre><code class="language-shell">cd fitness-tracker
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/c8113d5d-68a6-400f-ab9f-7c8903485eda.png" alt="The image shows changing the directory to fitness tracker" style="display: block;" width="2852" height="468" loading="lazy">

<p>Type the following command to install a virtual environment as we've done before and then activate the virtual environment:</p>
<pre><code class="language-shell">python3 -m venv venv

source venv/bin/activate
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/724767df-181c-4fcf-91e0-77c6dac566b0.png" alt="The image shows the virtual environment being created and activated" style="display: block;" width="2108" height="624" loading="lazy">

<p>Now install Django as before using <code>pip install django</code> command:</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/d6c37d87-7497-4ca1-a90f-6cd66422c2e5.png" alt="The image shows django being installed" style="display: block;" width="1980" height="952" loading="lazy">

<h3 id="heading-114-how-to-run-migrations-and-create-a-superuser-on-pythonanywhere">11.4 How to Run Migrations and Create a SuperUser on PythonAnywhere</h3>
<p>While you're still in the Bash console with your virtual environment activated, run the migrations to create the database tables on the server:</p>
<pre><code class="language-shell">python manage.py makemigrations

python manage.py migrate

python manage.py createsuperuser
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/0b763118-5a1c-4c3f-87f4-693cc7de0da2.png" alt="The image shows the make migrations and migrate commands running" style="display: block;" width="2026" height="768" loading="lazy">

<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/77183d3c-b4bc-40b7-b00f-5f03d2aea2ab.png" alt="The image shows the super user being created" style="display: block;" width="1814" height="506" loading="lazy">

<h3 id="heading-114-how-to-configure-the-web-app-in-pythonanywhere">11.4 How to Configure the Web App in Pythonanywhere</h3>
<p>Go to the "Web" tab on the PythonAnywhere dashboard and click "Add a new web app." Follow the setup wizard:</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/e1296e93-3e52-4327-b12a-4d4555e80845.png" alt="The image shows the web tab and add a new web app button" style="display: block;" width="2880" height="846" loading="lazy">

<p>Click "Next" on the domain name step (<em>remember the free tier uses</em> <a href="http://yourusername.pythonanywhere.com"><em>yourusername.pythonanywhere.com</em></a>).</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/24495b99-e1dc-437d-8ce8-47c0c962349f.png" alt="The image shows the web console where you specify the domain name" style="display: block;" width="2870" height="1302" loading="lazy">

<p>Select "Manual configuration" (not "Django" – the manual option gives you more control).</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/db470bd1-bbd1-4c61-b846-b7147d8f820f.png" alt="The image highlight the manual configuration option which should be selected" style="display: block;" width="2872" height="1326" loading="lazy">

<p>Then choose the Python version that matches what you installed. In my case it's 3.13, so I'll choose 3.13</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/dc51d44e-531c-4871-a225-e68b2db5dc65.png" alt="The image shows the Python version what is being selected" style="display: block;" width="2780" height="1384" loading="lazy">

<p>Click on Next button and a WSGI (Web Server Gateway Interface) will be created.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/3565512b-9c84-4b0d-82d9-3964cb0ff46b.png" alt="The image shows the final page before the web app is created" style="display: block;" width="2878" height="1422" loading="lazy">

<p>With this we've created the web app:</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/eda9fe63-01f4-48bc-98f1-07696bb798bf.png" alt="The image shows the final creation of the web app" style="display: block;" width="2874" height="1568" loading="lazy">

<p>After you've set up the web app, you have to do two more things:</p>
<ul>
<li><p>Set the virtual environment path</p>
</li>
<li><p>Configure the WSGI file</p>
</li>
</ul>
<h3 id="heading-115-how-to-set-the-virtual-environment-path">11.5 How to Set the Virtual Environment Path</h3>
<p>On the <strong>Web</strong> tab, scroll down to the "<strong>Virtualenv</strong>" section and enter the path to your virtual enviroment. The path to the file should be like this:</p>
<pre><code class="language-shell">/home/yourusername/fitness-tracker/venv
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/413ed047-ecc1-440f-a931-4a57aa91348b.png" alt="The image shows the added path of virtual environment" style="display: block;" width="2878" height="994" loading="lazy">

<h3 id="heading-116-how-to-configure-the-wsgi-file">11.6 How to Configure the WSGI file</h3>
<p>Still on the Web tab, scroll to the code section and click on the WSGI configuration file link:</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/934d1542-79d6-4140-8bb2-a4389fc17770.png" alt="The image shows the Code section and the WSGI configuration file path" style="display: block;" width="2264" height="548" loading="lazy">

<p>Delete all the contents and replace them with the content below and save the file:</p>
<pre><code class="language-python">import os
import sys
path = '/home/prabodhtuladhardev/fitness-tracker' #replace with your username
if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'fitness_project.settings'

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/416adac6-61d7-464d-b91f-b3b35272ef08.png" alt="The image shows the edited wsgi.py file and the highlights the save button" style="display: block;" width="1812" height="986" loading="lazy">

<h3 id="heading-117-how-to-set-up-static-files">11.7 How to Set Up Static Files</h3>
<p>Still on the "Web" tab, scroll down to the "Static files" section. Add an entry:</p>
<ul>
<li><p>URL: <code>/static/</code></p>
</li>
<li><p>Directory: <code>/home/yourusername/fitness-tracker/staticfiles</code></p>
</li>
</ul>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/f128dbd2-4acc-4387-89f8-d79de8c1e66e.png" alt="The image shows the static files section of the Web tab" style="display: block;" width="2488" height="728" loading="lazy">

<p>Then go back to your Bash console and run the following command:</p>
<pre><code class="language-shell">python manage.py collectstatic
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/207f8e67-2679-4ccc-8ebf-7d8aae5d7494.png" alt="The image shows the results of the collect static command" style="display: block;" width="2448" height="600" loading="lazy">

<p>This copies all static files to the staticfiles directory so PythonAnywhere can serve them directly.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/a14b75c4-cc1e-48ad-baf2-cf4f00906b85.png" alt="The image shows the folder named static files that was created" style="display: block;" width="2720" height="1026" loading="lazy">

<p>Go back to the "Web" tab and click the green "Reload" button at the top. This restarts your app with all the new configuration.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/08fab36e-8c8d-4d1b-8342-6e340fcf45d4.png" alt="The image shows the web tab with the reload button" style="display: block;" width="2874" height="1046" loading="lazy">

<h3 id="heading-118-how-to-view-your-live-application">11.8 How to View Your Live Application</h3>
<p>Open a new browser tab and visit <a href="https://yourusername.pythonanywhere.com">https://yourusername.pythonanywhere.com</a>. You should see your fitness tracker, live on the internet.</p>
<p>Try adding a workout.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/db67dbb1-3cb9-4b86-bfaa-67427ef5eac0.png" alt="The image shows the workout list view being opened in python anywhere" style="display: block;" width="2290" height="1278" loading="lazy">

<p>Visit the admin panel at <a href="https://yourusername.pythonanywhere.com/admin/">https://yourusername.pythonanywhere.com/admin/</a>.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/bd80d1e8-cf23-4ac2-b6a7-35bfdf61d023.png" alt="The image shows the workout django admin being opened in pythonanywhere" style="display: block;" width="2128" height="1310" loading="lazy">

<p>Everything should work just as it did on your local machine, but now anyone with the link can access it.</p>
<p>This is a meaningful milestone. You've gone from zero to a deployed Django application. Share the link with a friend or post it in a coding community. Seeing your work live on the internet is one of the most motivating experiences in learning to code.</p>
<h2 id="heading-common-mistakes-and-how-to-fix-them">Common Mistakes and How to Fix Them</h2>
<p>Even when you follow each step carefully, things can go wrong. Here are the most common issues beginners run into and how to solve them.</p>
<p><strong>"ModuleNotFoundError: No module named 'django'"</strong> – This usually means your virtual environment isn't activated. Run <code>source venv/bin/activate</code> (macOS/Linux) or <code>venv\Scripts\activate</code> (Windows) and try again. On PythonAnywhere, make sure the <strong>virtualenv</strong> path in the "<strong>Web</strong>" tab points to the correct location.</p>
<p><strong>"DisallowedHost" error</strong> – You forgot to add your domain to <code>ALLOWED_HOSTS</code> in <code>settings.py</code>, or there's a typo. Double-check that it matches your PythonAnywhere URL exactly.</p>
<p><strong>Static files not loading in production</strong> – Make sure you ran <code>python manage.py collectstatic</code> and that the static file mapping on PythonAnywhere points to the <strong>correct staticfiles</strong> directory. Also verify that <code>STATIC_ROOT</code> is set in <code>settings.py</code>.</p>
<p><strong>"No such table" or migration errors</strong> – You probably forgot to run <code>python manage.py migrate</code> after cloning or uploading your project to PythonAnywhere. Run the <code>migrate</code> command in the Bash console.</p>
<p><strong>Changes not showing up on PythonAnywhere</strong> – After making any code changes, you must click the "<strong>Reload</strong>" button on the "<strong>Web</strong>" tab. PythonAnywhere does not automatically detect file changes.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69bdd408475ca17974459537/08fab36e-8c8d-4d1b-8342-6e340fcf45d4.png" alt="The image shows the web tab and the reload buttton" style="display: block;" width="2874" height="1046" loading="lazy">

<h2 id="heading-how-you-can-improve-this-project">How You Can Improve This Project</h2>
<p>The fitness tracker you built is intentionally simple. That's a feature, not a limitation. A working simple project is the perfect foundation for learning more.</p>
<p>Here are some ideas for expanding it.</p>
<ol>
<li><p><strong>Add user authentication:</strong> Right now, anyone who visits the site sees the same workout data. Django has a built-in authentication system that lets you add registration, login, and logout. Each user could then have their own private list of workouts.</p>
</li>
<li><p><strong>Add the ability to edit and delete workouts.</strong> Currently, once a workout is saved, there's no way to change or remove it from the interface (you can do it through the admin panel, but not the main app). Try creating new views and templates for editing and deleting.</p>
</li>
<li><p><strong>Add workout categories or tags.</strong> Let users categorize their workouts as "Cardio," "Strength," "Flexibility," and so on. This would involve adding a new field to the model or creating a separate Category model with a foreign key relationship.</p>
</li>
<li><p><strong>Add charts and progress tracking.</strong> Use a JavaScript charting library like Chart.js to display workout trends over time. For example, you could show a bar chart of total minutes exercised per week.</p>
</li>
<li><p><strong>Build an API with Django REST Framework.</strong> If you want to learn about building APIs, try installing Django REST Framework (DRF) and creating API endpoints for your workouts. This would let you build a mobile app or a separate front end that communicates with your Django back end.</p>
</li>
</ol>
<p>Each of these improvements will teach you something new about Django while building on the foundation you already have.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>You've built a fully functional fitness tracker web app with Django and deployed it to the internet. That's no small achievement.</p>
<p>Along the way, you learned how Django projects and apps are structured, how models define the shape of your data, how migrations translate those models into database tables, how views handle the logic of your application, how templates render dynamic HTML, and how URLs tie everything together. You also went through the entire deployment process on PythonAnywhere.</p>
<p>These are the core building blocks of Django development. The patterns you practiced here – defining a model, creating a form, writing a view, building a template, and connecting a URL – are the same patterns you will use in every Django project, no matter how complex.</p>
<p>The best way to solidify what you have learned is to keep building. Try one of the improvements mentioned above, or start a completely new project. A calorie tracker, a habit tracker, an expense tracker, or a personal journal would all use the same Django concepts with slightly different models and views.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Go From Hello World to Building Real-World Applications ]]>
                </title>
                <description>
                    <![CDATA[ Many developers start learning programming by building simple projects like todo apps, calculators, and basic CRUD applications. These projects are useful at the beginning, as they help you understand how a programming language works and give you the... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-go-from-hello-world-to-building-real-world-applications/</link>
                <guid isPermaLink="false">697d098607632dbd100433e8</guid>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Beginner Developers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Learning Journey ]]>
                    </category>
                
                    <category>
                        <![CDATA[ coding ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Spruce Emmanuel ]]>
                </dc:creator>
                <pubDate>Fri, 30 Jan 2026 19:41:58 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769802056548/2b1b2ede-5f7f-423f-b6ee-19e0c0ac7b43.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Many developers start learning programming by building simple projects like todo apps, calculators, and basic CRUD applications. These projects are useful at the beginning, as they help you understand how a programming language works and give you the confidence to start building things. But for many developers, progress stops there.</p>
<p>Real world applications aren’t just about showing data on a screen. They solve real problems, work with real users, and handle situations that don’t always go as planned. This is where many developers struggle.</p>
<p>When I review junior developers’ résumés, I notice a common pattern: the projects section is often filled with beginner apps that look very similar. In today’s job market, this is usually not enough. Employers want to see that you can build something useful, something people would actually use.</p>
<p>The goal of this article is to help you move past simple Hello World projects like todo apps, calculators, and basic CRUD applications. By the end, you’ll understand how to approach building real applications that solve real problems and feel closer to what is built in the real world.</p>
<p>You might be wondering why you should listen to me.</p>
<p>Over the last 10 years, I’ve spent a lot of time building, breaking, and rebuilding software. I have experimented, failed many times, and eventually built applications that thousands of people use every day. A few weeks ago, I launched one of my own SaaS products and watched real users use it at scale, with over a thousand active users during peak hours, without the system crashing.</p>
<p>I’m sharing this because I’ve been where you are now.</p>
<p>If you continue reading, you will:</p>
<ul>
<li><p>Learn from real experience building applications used by real users</p>
</li>
<li><p>Learn what not to do, based on years of mistakes and lessons</p>
</li>
<li><p>Learn what actually works and what helps you stand out as a junior developer</p>
</li>
<li><p>Clear up common misconceptions that slow people down</p>
</li>
</ul>
<p>This article is not about theory. It’s about building real things.</p>
<p>To drive this point home, we’ll build a real world application that solves a real problem and is used by real people. Along the way, you’ll learn how to come up with real application ideas, how to build them with simple tools, and how to serve them to many users.</p>
<p>If this sounds like something you’re up for, then let’s get started.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ol>
<li><p><a class="post-section-overview" href="#heading-you-probably-think-you-dont-know-enough">You Probably Think You Don’t Know Enough</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-find-real-world-application-ideas">How to Find Real World Application Ideas</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-are-we-going-to-build">What Are We Going to Build</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-prerequisites">Prerequisites</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-step-1-setting-up-the-backend">Step 1: Setting Up the Backend</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-step-2-adding-background-removal-to-the-backend">Step 2: Adding Background Removal to the Backend</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-step-3-building-the-frontend">Step 3: Building the Frontend</a></p>
<ul>
<li><a class="post-section-overview" href="#heading-running-and-testing-the-application-locally">Running and Testing the Application Locally</a></li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-step-4-putting-the-backend-on-the-internet">Step 4: Putting the Backend on the Internet</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-deploying-the-backend-on-cloud-run">Deploying the Backend on Cloud Run</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-updating-the-frontend-to-use-the-live-backend">Updating the Frontend to Use the Live Backend</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-step-5-making-the-backend-and-frontend-work-together-cors">Step 5: Making the Backend and Frontend Work Together CORS</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-step-6-putting-the-frontend-on-the-internet">Step 6: Putting the Frontend on the Internet</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-final-thoughts-what-you-just-built-matters">Final Thoughts What You Just Built Matters</a></p>
</li>
</ol>
<h2 id="heading-you-probably-think-you-dont-know-enough"><strong>You Probably Think You Don't Know Enough</strong></h2>
<p>Before we begin, I want to clear up the most common misconception beginners have.</p>
<p>Many developers believe they don’t know enough to start building real world applications. They think they need to learn more JavaScript, more Python, or another framework before they are ready. Some even think learning React is the final step that will suddenly make everything click.</p>
<p>This belief is very common, but it’s not true.</p>
<p>If you know how to write HTML, CSS, and a simple loop or function in any programming language, you already have most of what it takes to build a real world application. This tutorial is proof of that.</p>
<p>That’s why I am writing this article. Not to tell you to learn more first, but to show you how far you can go with what you already know.</p>
<h2 id="heading-how-to-find-real-world-application-ideas">How to Find Real World Application Ideas</h2>
<p>One question beginners ask a lot is, “What kind of apps should I build?”</p>
<p>This is rarely talked about, but it matters more than most people think.</p>
<p>A simple rule is this: build things that already exist.</p>
<p>Look at the apps you use every day, especially the simple ones. Tools that do one thing well. If you find yourself using an app often, that app is solving a real problem.</p>
<p>For example, people use background removers to clean up images. They use URL shorteners to share links. They use notes apps to save quick thoughts. None of these ideas are new, but they are real.</p>
<p>You don’t need to invent something original. You need to understand a problem and build a working solution for it.</p>
<p>When you replicate real tools, you naturally learn how real applications are structured. You also end up with projects that make sense on a résumé, because they solve problems people recognize.</p>
<p>That’s exactly what we are going to do in this tutorial.</p>
<h2 id="heading-what-are-we-going-to-build">What Are We Going to Build?</h2>
<p>I’ll tell you now, it is not going to be another Hello World application. We’re going to be building a background remover web application.</p>
<p>This is the kind of tool people actually use. Designers use it for images, content creators use it for thumbnails, and developers build similar features into real products. It works with real files, real data, and real results.</p>
<p>If you want to see the final result before we start building, you can try the working app here: <a target="_blank" href="https://iamspruce.github.io/background-remover/">https://iamspruce.github.io/background-remover/</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769502551999/c2bdf45f-8768-4dc8-a816-6fa9a05dc15b.png" alt="The background remover application we are about to build" class="image--center mx-auto" width="2614" height="1848" loading="lazy"></p>
<p>We’ll build this app using simple tools on purpose. Plain HTML, CSS, and JavaScript for the frontend, and Python for the backend. No heavy frameworks and no complicated setup.</p>
<p>Before we continue, let me clear up <strong>another common misconception.</strong></p>
<p>Many developers believe that for an application to be taken seriously, it must be built with complex frameworks. In my experience building applications for clients around the world over the last 10 years, not a single client has ever asked me what framework I used.</p>
<p>They only cared about one thing: Did it work, and did it solve their problem?</p>
<p>Users won’t care how your app is built. They care that it works. If HTML, CSS, and JavaScript can solve the problem, there’s no reason to wait months just to learn a new framework.</p>
<p>Now that we understand <em>why</em> we’re building this app and <em>what</em> problem it solves, it’s time to start writing code.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>Before we start writing code, let’s quickly talk about what you need.</p>
<p>This tutorial is not for absolute beginners, but it’s also not super advanced. If you’ve built small things before and you want to build something that actually feels real, you’re in the right place.</p>
<h3 id="heading-what-you-should-already-know">What You Should Already Know</h3>
<p>You should be comfortable with:</p>
<ul>
<li><p>Basic HTML: You know what inputs, buttons, images, and divs do.</p>
</li>
<li><p>Basic CSS: You can style a page and make it look presentable.</p>
</li>
<li><p>Basic JavaScript: You know how to listen for a button click and send a request using <code>fetch</code>.</p>
</li>
</ul>
<p>That’s enough to follow along.</p>
<p>You don’t need React or any other frontend framework.</p>
<h3 id="heading-backend-knowledge">Backend Knowledge</h3>
<p>For the backend, you don’t need to be a Python expert.</p>
<p>You just need to understand that:</p>
<ul>
<li><p>Python can run a server</p>
</li>
<li><p>A server can receive requests</p>
</li>
<li><p>A server can send back responses</p>
</li>
</ul>
<p>Everything else will be explained as we go.</p>
<h3 id="heading-tools-you-need">Tools You Need</h3>
<p>Make sure you have these installed:</p>
<ul>
<li><p>Python 3.9 or newer</p>
</li>
<li><p>Git</p>
</li>
<li><p>A code editor like VS Code</p>
</li>
<li><p>A browser</p>
</li>
</ul>
<p>No Docker knowledge or cloud experience required.</p>
<h3 id="heading-github-account-important">GitHub Account (Important)</h3>
<p>We’ll deploy the backend directly from GitHub, so you’ll need a GitHub account.</p>
<p>If you’ve never pushed a project to GitHub or hosted one before, I’ve already written a <a target="_blank" href="https://www.freecodecamp.org/news/host-your-first-project-on-github/">beginner-friendly guide</a> you can follow first.</p>
<p>Read that article, then come back here.</p>
<h3 id="heading-a-quick-mindset-check">A Quick Mindset Check</h3>
<p>This is not a copy-paste tutorial. You will see real errors. Things may break. That’s normal. That’s how real applications are built.</p>
<p>Now that we’re clear on what you need, let’s start writing code.</p>
<p>We’ll begin with the backend. This is an important decision, so let’s explain it properly.</p>
<h2 id="heading-step-1-setting-up-the-backend">Step 1: Setting Up the Backend</h2>
<h3 id="heading-what-is-a-backend-and-why-do-we-need-one">What Is a Backend and Why Do We Need One?</h3>
<p>A backend is a program that runs on a server and does the heavy work for an application.</p>
<p>In our case, the heavy work is image processing. Removing a background from an image requires libraries that can’t run inside the browser. Browsers are designed for safety and user interaction, not for this kind of processing.</p>
<p>That’s why we need a backend.</p>
<p>The backend will:</p>
<ul>
<li><p>Receive an image from the user</p>
</li>
<li><p>Remove the background</p>
</li>
<li><p>Send the processed image back</p>
</li>
</ul>
<p>The frontend will simply talk to this backend later.</p>
<h3 id="heading-keeping-things-simple-on-purpose">Keeping Things Simple on Purpose</h3>
<p>Because this might be your first real project, we’re going to keep the backend as simple as possible.</p>
<ul>
<li><p>One programming language (Python)</p>
</li>
<li><p>One backend file</p>
</li>
<li><p>No complex folder structure</p>
</li>
<li><p>No advanced concepts</p>
</li>
</ul>
<p>This is intentional. Real world applications don’t have to start out complex. They typically start small and grow.</p>
<h3 id="heading-project-structure">Project Structure</h3>
<p>Create a new folder called:</p>
<pre><code class="lang-bash">background-remover
</code></pre>
<p>Inside it, create a folder for the backend:</p>
<pre><code class="lang-bash">background-remover/
  backend/
</code></pre>
<p>Move into the backend folder:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> background-remover/backend
</code></pre>
<p>Now create a virtual environment:</p>
<pre><code class="lang-bash">python -m venv env
</code></pre>
<p>A virtual environment keeps this project’s dependencies separate from everything else on your computer. This is standard practice and something you’ll see in real projects.</p>
<p>Now activate it:</p>
<p>macOS or Linux:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">source</span> env/bin/activate
</code></pre>
<p>Windows:</p>
<pre><code class="lang-bash">env\Scripts\activate
</code></pre>
<p>Now create a folder for your application code:</p>
<pre><code class="lang-bash">mkdir api
</code></pre>
<p>Your structure should now look like this:</p>
<pre><code class="lang-bash">background-remover/
  backend/
    env/
    api/
</code></pre>
<p>At this stage, nothing looks impressive yet. That’s normal.</p>
<h3 id="heading-installing-fastapi">Installing FastAPI</h3>
<p>We’ll use FastAPI to build the backend API.</p>
<p>Install it together with Uvicorn, which is the server that runs our app:</p>
<pre><code class="lang-bash">pip install fastapi uvicorn
</code></pre>
<p>FastAPI allows us to define endpoints clearly and with very little code, which is perfect for us.</p>
<h3 id="heading-creating-the-first-backend-file">Creating the First Backend File</h3>
<p>Inside the <code>api</code> folder, create a file called <code>main.py</code>.</p>
<p>Add the following code:</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> fastapi <span class="hljs-keyword">import</span> FastAPI

app = FastAPI()

<span class="hljs-meta">@app.get("/health")</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">health</span>():</span>
    <span class="hljs-keyword">return</span> {<span class="hljs-string">"status"</span>: <span class="hljs-string">"ok"</span>}
</code></pre>
<p>Let’s pause and understand what this does.</p>
<ul>
<li><p>We created a FastAPI application</p>
</li>
<li><p>We added a <code>/health</code> endpoint</p>
</li>
<li><p>This endpoint simply returns a message</p>
</li>
</ul>
<p>Before building real features, developers always confirm that their server actually runs. That is exactly what this endpoint is for.</p>
<h3 id="heading-running-the-server">Running the Server</h3>
<p>From inside the <code>backend</code> folder, start the server:</p>
<pre><code class="lang-bash">uvicorn api.main:app --reload
</code></pre>
<p>Now open a new terminal and run:</p>
<pre><code class="lang-bash">curl http://localhost:8000/health
</code></pre>
<p>You should see:</p>
<pre><code class="lang-bash">{<span class="hljs-string">"status"</span>:<span class="hljs-string">"ok"</span>}
</code></pre>
<p>This is an important moment.</p>
<p>You now have:</p>
<ul>
<li><p>A running backend server</p>
</li>
<li><p>A real HTTP endpoint</p>
</li>
<li><p>A response coming from your own code</p>
</li>
</ul>
<p>This is how real backend services start.</p>
<h3 id="heading-why-we-did-this-first">Why We Did This First</h3>
<p>At this point, you might wonder why we didn’t jump straight into background removal.</p>
<p>The reason is simple: if the server doesn’t run, nothing else matters.</p>
<p>By starting with a health endpoint, we removed uncertainty. We know the server works. Everything we add next is built on top of something we already know is working.</p>
<p>Now that the foundation is in place, we can move on to the real feature.</p>
<h2 id="heading-step-2-adding-background-removal-to-the-backend">Step 2: Adding Background Removal to the Backend</h2>
<p>Before we write any code here, we need to clear up an important misconception.</p>
<h3 id="heading-a-common-misconception-about-machine-learning">A Common Misconception About Machine Learning</h3>
<p>When people hear “background removal,” they often think machine learning is too advanced for them.</p>
<p>In real world development, this is almost never how it works.</p>
<p>You aren’t expected to build machine learning models yourself. You use libraries created by others and focus on integrating them correctly.</p>
<p>That is exactly what we’re doing here.</p>
<h3 id="heading-installing-the-background-removal-library">Installing the Background Removal Library</h3>
<p>Install the required packages:</p>
<pre><code class="lang-bash">pip install rembg pillow onnxruntime
</code></pre>
<ul>
<li><p><code>rembg</code> handles the background removal</p>
</li>
<li><p><code>pillow</code> helps us work with images</p>
</li>
</ul>
<p>For our purposes here, you don’t need to understand how these libraries work internally. You only need to know how to use them.</p>
<h3 id="heading-adding-the-background-removal-endpoint">Adding the Background Removal Endpoint</h3>
<p>Now update <code>main.py</code> so it looks like this:</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> fastapi <span class="hljs-keyword">import</span> FastAPI, UploadFile, File
<span class="hljs-keyword">from</span> rembg <span class="hljs-keyword">import</span> remove
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-keyword">import</span> io

app = FastAPI()

<span class="hljs-meta">@app.get("/health")</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">health</span>():</span>
    <span class="hljs-keyword">return</span> {<span class="hljs-string">"status"</span>: <span class="hljs-string">"ok"</span>}

<span class="hljs-meta">@app.post("/remove-bg")</span>
<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">remove_bg</span>(<span class="hljs-params">file: UploadFile = File(<span class="hljs-params">...</span>)</span>):</span>
    image_bytes = <span class="hljs-keyword">await</span> file.read()
    image = Image.open(io.BytesIO(image_bytes))

    output = remove(image)

    buffer = io.BytesIO()
    output.save(buffer, format=<span class="hljs-string">"PNG"</span>)
    buffer.seek(<span class="hljs-number">0</span>)

    <span class="hljs-keyword">return</span> buffer.getvalue()
</code></pre>
<p>Let’s explain this carefully.</p>
<ul>
<li><p>The endpoint accepts an uploaded image</p>
</li>
<li><p>The image is read into memory</p>
</li>
<li><p>The background is removed</p>
</li>
<li><p>The result is saved as a PNG with transparency</p>
</li>
<li><p>The image is returned to the client</p>
</li>
</ul>
<p>This endpoint is the core of our application.</p>
<h3 id="heading-testing-the-endpoint-with-curl">Testing the Endpoint With curl</h3>
<p>Before building the frontend, we’ll test the backend directly.</p>
<p>Run this command:</p>
<pre><code class="lang-javascript">curl -X POST \
  -F <span class="hljs-string">"file=@person.jpg"</span> \
  <span class="hljs-attr">http</span>:<span class="hljs-comment">//localhost:8000/remove-bg \</span>
  --output result.png
</code></pre>
<p>Open <code>result.png</code>. If you see the background removed, then the backend is complete.</p>
<p>At this point, you have built a backend that:</p>
<ul>
<li><p>Accepts real user input</p>
</li>
<li><p>Processes real data</p>
</li>
<li><p>Returns a meaningful result</p>
</li>
</ul>
<p>This is a real backend.</p>
<h3 id="heading-where-we-are-now">Where We Are Now</h3>
<p>Let’s pause and summarize:</p>
<ul>
<li><p>We set up a backend server</p>
</li>
<li><p>We confirmed that it runs</p>
</li>
<li><p>We added a real feature</p>
</li>
<li><p>We tested it without a frontend</p>
</li>
</ul>
<p>This is exactly how real developers work.</p>
<p>In the next section, we’ll build a simple frontend that talks to this backend and turns it into something users can interact with.</p>
<h2 id="heading-step-3-building-the-frontend-what-the-user-actually-sees">Step 3: Building the Frontend (What the User Actually Sees)</h2>
<p>At this point, our backend is working.</p>
<p>It can receive an image, remove the background, and send the result back. But right now, only developers can use it, because it requires terminal commands.</p>
<p>To make this useful to actual (non-technical) people, we need a frontend.</p>
<p>The frontend is simply the part of the application users see and interact with in their browser.</p>
<h3 id="heading-clearing-a-common-misconception-about-frontends">Clearing a Common Misconception About Frontends</h3>
<p>Many beginners think building a frontend means learning a framework first.</p>
<p>This is not true.</p>
<p>Frameworks help later, but they aren’t required to build real applications. Under the hood, every frontend still comes down to HTML, CSS, and JavaScript.</p>
<p>That’s why we are using plain HTML, CSS, and JavaScript here. No React, no build tools, no setup. Just the basics.</p>
<h3 id="heading-what-our-frontend-will-do">What Our Frontend Will Do</h3>
<p>Our frontend has one job. It will:</p>
<ul>
<li><p>Let the user select an image</p>
</li>
<li><p>Send that image to the backend</p>
</li>
<li><p>Receive the processed image</p>
</li>
<li><p>Show it on the screen</p>
</li>
<li><p>Allow the user to download it</p>
</li>
</ul>
<p>That’s all.</p>
<p>If it does these things correctly, it’s a real frontend.</p>
<h3 id="heading-creating-the-frontend">Creating the Frontend</h3>
<p>Go back to the root of your project and create three files:</p>
<pre><code class="lang-bash">index.html
styles.css
app.js
</code></pre>
<p>This simple setup is very common. Each file has a clear responsibility, which makes the code easier to understand.</p>
<h3 id="heading-writing-the-html-page">Writing the HTML Page</h3>
<p>Open <code>index.html</code> and add the following:</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Background Remover<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"styles.css"</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Background Remover<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"file"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"imageInput"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"removeBtn"</span>&gt;</span>Remove Background<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"result"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"resultImage"</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"downloadLink"</span> <span class="hljs-attr">download</span>&gt;</span>Download Image<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"app.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>Right now, this page won’t do anything interesting. That’s expected.</p>
<p>HTML only describes what should be on the page. The behavior comes from JavaScript, which we’ll add after we add some styling.</p>
<h3 id="heading-adding-some-basic-styling">Adding Some Basic Styling</h3>
<p>Open <code>styles.css</code> and add this:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">font-family</span>: sans-serif;
  <span class="hljs-attribute">max-width</span>: <span class="hljs-number">600px</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">40px</span> auto;
}

<span class="hljs-selector-tag">button</span> {
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">10px</span>;
}

<span class="hljs-selector-class">.result</span> {
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">20px</span>;
}

<span class="hljs-selector-tag">img</span> {
  <span class="hljs-attribute">max-width</span>: <span class="hljs-number">100%</span>;
}

<span class="hljs-selector-id">#downloadLink</span> {
  <span class="hljs-attribute">display</span>: none;
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p>This is not about making things look fancy.</p>
<p>The goal here is simply to make the page readable and pleasant to use. Many real internal tools look no better than this. (And you can always improve the styling later if you want.)</p>
<h3 id="heading-connecting-the-frontend-to-the-backend">Connecting the Frontend to the Backend</h3>
<p>Now we’ll write the JavaScript that makes everything work.</p>
<p>Open <code>app.js</code> and add the following code:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> imageInput = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"imageInput"</span>);
<span class="hljs-keyword">const</span> removeBtn = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"removeBtn"</span>);
<span class="hljs-keyword">const</span> resultImage = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"resultImage"</span>);
<span class="hljs-keyword">const</span> downloadLink = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"downloadLink"</span>);

removeBtn.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-keyword">async</span> () =&gt; {
  <span class="hljs-keyword">const</span> file = imageInput.files[<span class="hljs-number">0</span>];

  <span class="hljs-keyword">if</span> (!file) {
    <span class="hljs-keyword">return</span>;
  }

  <span class="hljs-keyword">const</span> formData = <span class="hljs-keyword">new</span> FormData();
  formData.append(<span class="hljs-string">"file"</span>, file);

  <span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">"http://localhost:8000/remove-bg"</span>, {
    <span class="hljs-attr">method</span>: <span class="hljs-string">"POST"</span>,
    <span class="hljs-attr">body</span>: formData,
  });

  <span class="hljs-keyword">const</span> blob = <span class="hljs-keyword">await</span> response.blob();
  <span class="hljs-keyword">const</span> imageUrl = URL.createObjectURL(blob);

  resultImage.src = imageUrl;
  downloadLink.href = imageUrl;
  downloadLink.style.display = <span class="hljs-string">"inline"</span>;
});
</code></pre>
<p>Let’s slow down and explain what’s happening here:</p>
<ul>
<li><p>We read the image selected by the user</p>
</li>
<li><p>We wrap it in <code>FormData</code> so it can be sent to the backend</p>
</li>
<li><p>We send it to our <code>/remove-bg</code> endpoint</p>
</li>
<li><p>We receive the processed image back</p>
</li>
<li><p>We display it and prepare it for download</p>
</li>
</ul>
<p>This is the moment where the frontend and backend finally talk to each other.</p>
<h3 id="heading-running-the-frontend-with-live-server">Running the Frontend With Live Server</h3>
<p>Before testing, make sure your backend is still running.</p>
<p>Now, instead of opening <code>index.html</code> directly, use the <strong>Live Server</strong> extension in VS Code.</p>
<p>If you don’t have it installed, just open VS Code extensions, search for “Live Server”, and then install it. Then right click on <code>index.html</code> and click “Open with Live Server”.</p>
<p>This starts a small local server for the frontend.</p>
<p>Why does this matter?</p>
<p>Many browser features work better when files are served through a server instead of opened directly from the file system. Using Live Server also matches how real frontends are served.</p>
<h3 id="heading-testing-the-full-application-locally">Testing the Full Application Locally</h3>
<p>Now choose an image and click the button.</p>
<p>If everything is working:</p>
<ul>
<li><p>The image is sent to the backend</p>
</li>
<li><p>The background is removed</p>
</li>
<li><p>The result appears on the page</p>
</li>
<li><p>The download link shows up</p>
</li>
</ul>
<p>Take a moment here. You have just built:</p>
<ul>
<li><p>A backend that processes real data</p>
</li>
<li><p>A frontend that talks to it</p>
</li>
<li><p>A complete application running locally</p>
</li>
</ul>
<p>This is already more than a “Hello World” project.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769503437045/6a984e58-cee9-4255-84aa-76ee26b805b3.png" alt="The application running locally after connecting the frontend and backend and removing background from an image" class="image--center mx-auto" width="2614" height="1848" loading="lazy"></p>
<h3 id="heading-clearing-one-more-misconception">Clearing One More Misconception</h3>
<p>Some beginners look at this and think: “This feels too simple to be a real app.”</p>
<p>This is another misconception. Real applications aren’t defined by complexity. They’re defined by usefulness. If your app solves a real problem and people can use it, it’s a real application.</p>
<p>In the next section, we’ll take this exact app and put it on the internet so anyone can use it.</p>
<h2 id="heading-step-4-putting-the-backend-on-the-internet">Step 4: Putting the Backend on the Internet</h2>
<p>Right now, your backend is running on your computer.</p>
<p>That means:</p>
<ul>
<li><p>It works only for you</p>
</li>
<li><p>If you close your laptop, it stops</p>
</li>
<li><p>If someone opens your frontend, it cannot reach your backend</p>
</li>
</ul>
<p>To fix this, we need to run the backend on a computer that is <strong>always online</strong>.</p>
<p>This process is called <strong>deployment</strong>.</p>
<h3 id="heading-a-simple-way-to-think-about-deployment">A Simple Way to Think About Deployment</h3>
<p>Deployment does <strong>not</strong> mean writing new code.</p>
<p>It simply means this: instead of running your backend on your laptop, you run it on another computer that never sleeps.</p>
<p>Everything we do next exists only to make that happen.</p>
<h3 id="heading-why-we-arent-using-netlify-or-vercel">Why We Aren’t Using Netlify or Vercel</h3>
<p>You might be wondering why we aren’t using Netlify or Vercel. Those platforms are great, but they’re mainly for <strong>frontends</strong>.</p>
<p>They work best when your app is:</p>
<ul>
<li><p>Static HTML, CSS, and JavaScript</p>
</li>
<li><p>A frontend framework like React or Vue</p>
</li>
<li><p>Small serverless functions</p>
</li>
</ul>
<p>Our backend is different. It’s a <strong>Python server</strong> that:</p>
<ul>
<li><p>Stays running</p>
</li>
<li><p>Accepts image uploads</p>
</li>
<li><p>Processes images</p>
</li>
<li><p>Uses heavy native libraries for background removal</p>
</li>
</ul>
<p>This kind of backend needs a <strong>real server</strong>, not a lightweight serverless function.</p>
<p>That’s why Netlify and Vercel aren’t a good fit here.</p>
<h3 id="heading-why-were-using-cloud-run">Why We’re Using Cloud Run</h3>
<p>Instead, we’re using <strong>Cloud Run</strong>.</p>
<p>Cloud Run lets us run real backend servers on Google’s infrastructure without managing servers ourselves.</p>
<p>We’re using it because:</p>
<ul>
<li><p>It supports full Python backends</p>
</li>
<li><p>It deploys directly from GitHub</p>
</li>
<li><p>It handles scaling and servers for us</p>
</li>
<li><p>It works well with heavy workloads</p>
</li>
<li><p>It’s beginner-friendly</p>
</li>
</ul>
<p>Most importantly, it lets you deploy a <strong>real backend</strong> without learning cloud commands or CI/CD pipelines.</p>
<h3 id="heading-preparing-the-backend-for-cloud-run">Preparing the Backend for Cloud Run</h3>
<p>Before deploying, we need to make sure our backend is ready.</p>
<h4 id="heading-creating-requirementstxt">Creating <code>requirements.txt</code></h4>
<p>Inside the <code>backend</code> folder, create a file called <code>requirements.txt</code>.</p>
<p>Add this:</p>
<pre><code class="lang-go">fastapi
uvicorn
rembg
pillow
onnxruntime
</code></pre>
<p>This file tells Cloud Run which Python libraries to install.</p>
<h3 id="heading-creating-a-github-repository">Creating a GitHub Repository</h3>
<p>Cloud Run deploys directly from GitHub, so our code must live there.</p>
<p>From the project root, run:</p>
<pre><code class="lang-go">git init
git add .
git commit -m <span class="hljs-string">"Initial background remover project"</span>
git branch -M main
git remote add origin YOUR_REPO_URL
git push -u origin main
</code></pre>
<p>This <strong>single repository</strong> will be used for both backend and frontend.</p>
<h3 id="heading-deploying-the-backend-on-cloud-run">Deploying the Backend on Cloud Run</h3>
<p>Now open your browser and go to <strong>Google Cloud Console</strong>.</p>
<h4 id="heading-1-create-a-new-project">1. Create a New Project</h4>
<p>Open <a target="_blank" href="https://console.cloud.google.com">Google Cloud Console</a> and click New Project. Give it a name (for example: <code>background-remover</code>) and then click Create.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769749541636/778464de-2c95-4f7e-9505-9729a84f2001.png" alt="Creating a new Google Cloud project" class="image--center mx-auto" width="2614" height="1848" loading="lazy"></p>
<h4 id="heading-2-open-cloud-run">2. Open Cloud Run</h4>
<p>Use the search bar at the top and search for <strong>Cloud Run.</strong> Then open it.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769749581066/9078ae2e-fa00-4dfa-be04-383d9702bb90.png" alt="Cloud Run overview page" class="image--center mx-auto" width="2614" height="1848" loading="lazy"></p>
<p>Cloud Run will automatically enable the required APIs.</p>
<p>You will be asked to set up billing. Google gives you $300 free credit, which is more than enough for this tutorial.</p>
<h4 id="heading-3-start-creating-the-service">3. Start Creating the Service</h4>
<p>Click Create Service and choose Deploy continuously from a repository.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769749636809/348f720a-b1b1-46e4-9eab-48928adeb2f3.png" alt="Creating a Cloud Run service from a repository" class="image--center mx-auto" width="2614" height="1848" loading="lazy"></p>
<h4 id="heading-4-connect-your-github-account">4. Connect Your GitHub Account</h4>
<p>Select <strong>GitHub</strong> as the repository provider and authenticate your GitHub account. Then install Google Cloud Build on your GitHub account. Choose <strong>only the repository</strong> you want to deploy.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769749686780/89571b5e-0bd7-4127-82d2-b9445a5044e4.png" alt="Installing Google Cloud Build on GitHub" class="image--center mx-auto" width="2272" height="1664" loading="lazy"></p>
<p>This allows Google Cloud to build and deploy your code automatically.</p>
<h4 id="heading-5-select-the-repository">5. Select the Repository</h4>
<p>Then choose the repository you just installed Cloud Build on and select the <code>main</code> branch.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769749745522/a9f95c4b-7fd3-480d-bae1-7ae92bcdd52f.png" alt="Selecting the GitHub repository" class="image--center mx-auto" width="2614" height="1848" loading="lazy"></p>
<h4 id="heading-6-configure-the-build">6. Configure the Build</h4>
<p>Now comes the important part: building the context directory.</p>
<p>Set this to:</p>
<pre><code class="lang-bash">backend
</code></pre>
<p>This tells Cloud Run:</p>
<blockquote>
<p>“My backend code lives inside the <code>backend</code> folder.”</p>
</blockquote>
<p>For the entry command, enter:</p>
<pre><code class="lang-bash">uvicorn api.main:app --host 0.0.0.0 --port 8080
</code></pre>
<p>This is how Cloud Run starts your FastAPI server.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769749801126/87676cce-3e75-4244-b32f-401f782d7c85.png" alt="Build configuration for the backend" class="image--center mx-auto" width="2614" height="1848" loading="lazy"></p>
<h4 id="heading-7-configure-container-resources">7. Configure Container Resources</h4>
<p>Our backend runs a <strong>background-removal model</strong>, which is heavy.</p>
<p>So we must increase resources.</p>
<ul>
<li><p>Change memory from <strong>512 MB → 2 GB</strong></p>
</li>
<li><p>Set CPU to <strong>4</strong></p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769749870471/a24e5d37-af21-48a6-b720-b6748d478b6d.png" alt="Increasing memory and CPU" class="image--center mx-auto" width="2614" height="1848" loading="lazy"></p>
<p>This ensures the model can load and run properly.</p>
<h4 id="heading-8-deploy">8. Deploy</h4>
<p>Now click <strong>Create</strong>.</p>
<p>Cloud Run will:</p>
<ul>
<li><p>Build your app</p>
</li>
<li><p>Install dependencies</p>
</li>
<li><p>Create a container</p>
</li>
<li><p>Deploy it to the internet</p>
</li>
</ul>
<p>You’ll see logs showing the build and deployment process.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769749916316/5eb276f6-01c1-413c-aeb7-13a8d34dbbe2.png" alt="Cloud Build running" class="image--center mx-auto" width="2614" height="1848" loading="lazy"></p>
<p>This can take a few minutes. That’s normal.</p>
<h3 id="heading-checking-that-the-backend-is-live">Checking That the Backend Is Live</h3>
<p>Once deployment finishes, Cloud Run will show you a <strong>public URL</strong>.</p>
<p>Test it:</p>
<pre><code class="lang-bash">curl https://YOUR_CLOUD_RUN_URL/health
</code></pre>
<p>If you see:</p>
<pre><code class="lang-bash">{<span class="hljs-string">"status"</span>:<span class="hljs-string">"ok"</span>}
</code></pre>
<p>Your backend is officially live on the internet.</p>
<p>Pause here for a second.</p>
<p>You just deployed a real backend. Congratulations.</p>
<h3 id="heading-updating-the-frontend-to-use-the-live-backend">Updating the Frontend to Use the Live Backend</h3>
<p>Open <code>app.js</code>.</p>
<p>Replace:</p>
<pre><code class="lang-bash">http://localhost:8000/remove-bg
</code></pre>
<p>With:</p>
<pre><code class="lang-bash">https://YOUR_CLOUD_RUN_URL/remove-bg
</code></pre>
<p>Save the file and reload the frontend.</p>
<h2 id="heading-step-5-making-the-backend-and-frontend-work-together"><strong>Step 5: Making the Backend and Frontend Work Together</strong></h2>
<p>At this point, we have two things:</p>
<ul>
<li><p>A backend running on the internet</p>
</li>
<li><p>A frontend running in the browser</p>
</li>
</ul>
<p>Now we want them to talk to each other.</p>
<p>Open your frontend, select an image, and click the button. You’ll notice that it still doesn’t work. This is expected.</p>
<h3 id="heading-what-is-happening-here">What Is Happening Here?</h3>
<p>Your frontend is running on one address, while your backend is running on another address.</p>
<p>Browsers are very strict about this. By default, a browser will block requests from one website to another unless the backend explicitly allows it. This is a security feature.</p>
<p>This rule is called <strong>CORS</strong>.</p>
<h3 id="heading-clearing-a-common-misconception-about-cors">Clearing a Common Misconception About CORS</h3>
<p>When beginners see a CORS error, they often think something is broken.</p>
<p>Nothing is broken. CORS is simply the browser saying: “I need the backend to confirm that this frontend is allowed to talk to it.”</p>
<p>So all we need to do is tell the backend: “It’s okay for requests to come from my frontend.”</p>
<h3 id="heading-allowing-only-our-frontend-not-everyone">Allowing Only Our Frontend (Not Everyone)</h3>
<p>Instead of allowing requests from everywhere, we’ll allow requests only from our frontend. This is a good habit to learn early.</p>
<p>Open <code>backend/api/main.py</code>.</p>
<p>Add this import at the top:</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> fastapi.middleware.cors <span class="hljs-keyword">import</span> CORSMiddleware
</code></pre>
<p>Then, after creating the FastAPI app, add this:</p>
<pre><code class="lang-python">app.add_middleware(
    CORSMiddleware,
    allow_origins=[
        <span class="hljs-string">"http://127.0.0.1:5500"</span>,
        <span class="hljs-string">"http://localhost:5500"</span>
    ],
    allow_methods=[<span class="hljs-string">"POST"</span>],
    allow_headers=[<span class="hljs-string">"*"</span>],
)
</code></pre>
<p>Why these URLs?</p>
<p>If you’re using the Live Server extension, your frontend is usually served on port <code>5500</code>. These are the addresses your browser is using locally.</p>
<p>We’re telling the backend: “Only accept requests from this frontend.”</p>
<p>That is exactly what we want.</p>
<h3 id="heading-redeploying-the-backend">Redeploying the Backend</h3>
<p>Any time you change backend code, you need to redeploy it.</p>
<p>Since our backend is deployed on Cloud Run and set up with automatic deploy, redeploying is simple, all you need to do is push your changes.</p>
<p>From the project root, run:</p>
<pre><code class="lang-go">git add .
git commit -m <span class="hljs-string">"Add CORS configuration"</span>
git push
</code></pre>
<p>Cloud Run will automatically detect the change and redeploy your backend.</p>
<p>Wait for the deployment to finish. Once it’s done, your backend will now allow requests from your local frontend.</p>
<h3 id="heading-testing-again">Testing Again</h3>
<p>Reload your frontend in the browser.</p>
<p>Select an image and click the button. This time, it should work.</p>
<p>You just handled a real browser security rule that every production app runs into. That alone is a huge learning step.</p>
<h2 id="heading-step-6-putting-the-frontend-on-the-internet-github-pages">Step 6: Putting the Frontend on the Internet (GitHub Pages)</h2>
<p>Right now, your frontend works only on your computer.</p>
<p>Just like the backend earlier, this means no one else can use it.</p>
<p>Let’s fix that.</p>
<h3 id="heading-why-github-pages">Why GitHub Pages?</h3>
<p>Our frontend is:</p>
<ul>
<li><p>Just HTML, CSS, and JavaScript</p>
</li>
<li><p>No backend code</p>
</li>
<li><p>No build step</p>
</li>
</ul>
<p>This makes it perfect for GitHub Pages. GitHub Pages can host static sites for free, and it’s very beginner friendly.</p>
<h3 id="heading-preparing-the-frontend-for-deployment">Preparing the Frontend for Deployment</h3>
<p>Make sure all your frontend files are inside the frontend folder:</p>
<pre><code class="lang-javascript">frontend/
  index.html
  styles.css
  app.js
</code></pre>
<p>Open app.js and make sure the backend URL is the Cloud Run URL, not localhost.</p>
<pre><code class="lang-javascript">fetch(<span class="hljs-string">"https://YOUR_CLOUD_RUN_URL/remove-bg"</span>, {
  <span class="hljs-attr">method</span>: <span class="hljs-string">"POST"</span>,
  <span class="hljs-attr">body</span>: formData,
});
</code></pre>
<p>Save the file.</p>
<h3 id="heading-pushing-the-frontend-to-github">Pushing the Frontend to GitHub</h3>
<p>We already created a GitHub repository earlier, so we’ll reuse it.</p>
<p>From the project root, run:</p>
<pre><code class="lang-javascript">git add .
git commit -m <span class="hljs-string">"Add frontend and prepare for GitHub Pages"</span>
git push
</code></pre>
<h3 id="heading-enabling-github-pages">Enabling GitHub Pages</h3>
<ol>
<li><p>Go to your repository on GitHub.</p>
</li>
<li><p>Open Settings.</p>
</li>
<li><p>Click Pages.</p>
</li>
</ol>
<p>Under Source, select:</p>
<ol>
<li><p>Branch: main</p>
</li>
<li><p>Folder: /(root)</p>
</li>
</ol>
<p>Save everything. After a few seconds, GitHub will give you a URL. This URL is now your frontend on the internet.</p>
<h3 id="heading-updating-cors-for-the-live-frontend">Updating CORS for the Live Frontend</h3>
<p>Now that the frontend is live, go back to backend/api/main.py.</p>
<p>Replace the local origins with your GitHub Pages URL:</p>
<pre><code class="lang-python">allow_origins=[
    <span class="hljs-string">"https://YOUR_GITHUB_USERNAME.github.io"</span>
]
</code></pre>
<p>Commit and push the change:</p>
<pre><code class="lang-bash">git add .
git commit -m <span class="hljs-string">"Update CORS for GitHub Pages"</span>
git push
</code></pre>
<p>Cloud Run will redeploy the backend automatically.</p>
<h3 id="heading-final-test">Final Test</h3>
<p>Open your GitHub Pages URL.</p>
<p>Upload an image, remove the background, and download the result.</p>
<p>Everything is now live.</p>
<h2 id="heading-where-you-are-now">Where You Are Now</h2>
<p>Let’s be very clear about what you just did.</p>
<p>You:</p>
<ul>
<li><p>Built a real backend</p>
</li>
<li><p>Deployed it to the internet</p>
</li>
<li><p>Built a frontend</p>
</li>
<li><p>Deployed it to the internet</p>
</li>
<li><p>Fixed real production issues</p>
</li>
<li><p>Connected everything properly</p>
</li>
</ul>
<p>This is not a demo project. This is a real application.</p>
<p>In the final section, we’ll wrap things up, talk about what you learned, and where you can go next.</p>
<h2 id="heading-final-thoughts-what-you-just-built-matters">Final Thoughts: What You Just Built Matters</h2>
<p>At this point, it is worth stopping and looking back at what you have actually done.</p>
<p>You didn’t just follow steps. You didn’t just copy code. You built a real application.</p>
<h3 id="heading-lets-be-clear-about-what-you-accomplished">Let’s Be Clear About What You Accomplished</h3>
<p>You started with nothing more than basic tools and ideas.</p>
<p>By the end of this tutorial, you:</p>
<ul>
<li><p>Built a backend that processes real data</p>
</li>
<li><p>Used a machine learning tool without fear or overthinking</p>
</li>
<li><p>Exposed a backend to the internet</p>
</li>
<li><p>Built a frontend with plain HTML, CSS, and JavaScript</p>
</li>
<li><p>Connected the frontend and backend properly</p>
</li>
<li><p>Deployed both parts so real users can access them</p>
</li>
</ul>
<p>This is exactly how real applications are built, just at a smaller and more manageable scale.</p>
<h3 id="heading-why-this-is-no-longer-a-beginner-project">Why This Is No Longer a “Beginner Project”</h3>
<p>Many projects are called beginner projects, but they stop at showing things on a screen.</p>
<p>This one does not.</p>
<p>Your app:</p>
<ul>
<li><p>Accepts real input</p>
</li>
<li><p>Performs real work</p>
</li>
<li><p>Runs on real servers</p>
</li>
<li><p>Handles real browser rules</p>
</li>
<li><p>Can be shared with anyone</p>
</li>
</ul>
<p>That is the difference between learning syntax and building software.</p>
<h3 id="heading-the-most-important-lesson-in-this-tutorial">The Most Important Lesson in This Tutorial</h3>
<p>The most important thing you should take away from this is not the project you built.</p>
<p>It is this: You didn’t need to “know more” before you started.</p>
<p>You learned by building. You figured things out as they appeared. You fixed problems when they showed up.</p>
<p>That is how experience is gained. No one has experience before building real applications. No one lacks experience after building many of them.</p>
<h3 id="heading-what-you-can-do-next">What You Can Do Next</h3>
<p>This project isn’t the end. It’s a starting point.</p>
<p>Here are a few ideas you can explore next, using what you already know:</p>
<ul>
<li><p>Improve the user interface</p>
</li>
<li><p>Add loading states and better feedback</p>
</li>
<li><p>Restrict image size or file types</p>
</li>
<li><p>Add simple rate limiting</p>
</li>
<li><p>Build another small tool that solves a real problem</p>
</li>
</ul>
<p>You don’t need to jump to frameworks yet.</p>
<p>If you can build a few more projects like this, frameworks will make a lot more sense when you meet them.</p>
<h3 id="heading-one-last-thought">One Last Thought</h3>
<p>If this was your first real project, you should be proud of yourself.</p>
<p>You moved past tutorials, built something useful, and put it on the internet. That’s the line many developers never cross.</p>
<p>Now that you have crossed it, the next one will be easier.</p>
<p>So keep building!</p>
<h3 id="heading-source-code-and-live-demo">Source Code and Live Demo</h3>
<p>If you want to explore the full project or build on top of it, you can find everything here.</p>
<ul>
<li><p>Live application: <a target="_blank" href="https://iamspruce.github.io/background-remover/">https://iamspruce.github.io/background-remover/</a></p>
</li>
<li><p>GitHub repository: <a target="_blank" href="https://github.com/iamspruce/background-remover">https://github.com/iamspruce/background-remover</a></p>
</li>
</ul>
<p>If you have questions, reach me on X at <a target="_blank" href="https://x.com/sprucekhalifa"><code>@sprucekhalifa</code></a>. I write practical tech articles like this regularly.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Handle Permissions in Flutter: A Comprehensive Guide ]]>
                </title>
                <description>
                    <![CDATA[ Permissions are crucial when building mobile applications that require access to device features such as location, camera, contacts, microphone, storage, and more. And handling permissions effectively ensures that your app provides a seamless user ex... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-handle-permissions-in-flutter-for-beginners/</link>
                <guid isPermaLink="false">68af2b5d6d32776366258694</guid>
                
                    <category>
                        <![CDATA[ Flutter ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flutter-aware ]]>
                    </category>
                
                    <category>
                        <![CDATA[ permissions ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Beginner Developers ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Atuoha Anthony ]]>
                </dc:creator>
                <pubDate>Wed, 27 Aug 2025 15:59:25 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1756310343452/8db020d5-5cec-4b88-9a02-a8dc2a81190c.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Permissions are crucial when building mobile applications that require access to device features such as location, camera, contacts, microphone, storage, and more. And handling permissions effectively ensures that your app provides a seamless user experience while respecting privacy and security requirements.</p>
<p>In Flutter, one of the most popular packages to manage permissions is <a target="_blank" href="https://pub.dev/packages/permission_handler"><code>permission_handler</code></a>. This article will guide you through how to:</p>
<ol>
<li><p>Install and set up <code>permission_handler</code> and <code>fluttertoast</code></p>
</li>
<li><p>Request and handle different permissions</p>
</li>
<li><p>Understand what each permission does and its use cases</p>
</li>
<li><p>Handling Android and iOS configurations</p>
</li>
<li><p>Implement best practices</p>
</li>
<li><p>Handle testing permissions</p>
</li>
<li><p>Provide expected outcomes and conclusions</p>
</li>
</ol>
<h2 id="heading-table-of-contents">Table of Contents:</h2>
<ul>
<li><p><a class="post-section-overview" href="#heading-table-of-contents">Table of Contents:</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-1-prerequisites">1. Prerequisites</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-2-installing-dependencies">2. Installing Dependencies</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-3-understanding-permission-states">3. Understanding Permission States</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-4-reusable-permission-handling-function">4. Reusable Permission Handling Function</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-5-permissions-their-use-cases-and-examples">5. Permissions, Their Use Cases, and Examples</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-51-calendar-permissions">5.1 Calendar Permissions</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-52-camera-permission">5.2 Camera Permission</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-53-contacts-permission">5.3 Contacts Permission</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-54-location-permissions">5.4 Location Permissions</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-55-media-library-ios-only">5.5 Media Library (iOS only)</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-56-microphone-permission">5.6 Microphone Permission</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-57-phone-permission">5.7 Phone Permission</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-58-photos-permissions">5.8 Photos Permissions</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-59-reminders-permission">5.9 Reminders Permission</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-510-sensors-permissions">5.10 Sensors Permissions</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-511-sms-permission">5.11 SMS Permission</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-512-speech-recognition-permission">5.12 Speech Recognition Permission</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-513-storage-permissions">5.13 Storage Permissions</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-514-ignore-battery-optimizations">5.14 Ignore Battery Optimizations</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-515-notifications">5.15 Notifications</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-516-bluetooth-permissions">5.16 Bluetooth Permissions</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-517-app-tracking-transparency-ios-only">5.17 App Tracking Transparency (iOS only)</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-6-android-manifest-configuration">6. Android Manifest Configuration</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-7-ios-infoplist-configuration">7. iOS Info.plist Configuration</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-8-expected-outcomes">8. Expected Outcomes</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-best-practices-for-handling-permissions-in-flutter">Best Practices for Handling Permissions in Flutter</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-1-request-only-necessary-permissions">1. Request only necessary permissions</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-2-explain-why-permissions-are-needed">2. Explain why permissions are needed</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-3-use-runtime-permission-requests">3. Use runtime permission requests</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-4-handle-denial-gracefully">4. Handle denial gracefully</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-5-handle-permanent-denials">5. Handle permanent denials</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-6-test-on-both-platforms">6. Test on both platforms</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-7-follow-platform-guidelines">7. Follow platform guidelines</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-8-avoid-over-permissioning">8. Avoid over-permissioning</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-9-use-a-centralized-permission-manager">9. Use a centralized permission manager</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-10-monitor-permission-changes">10. Monitor permission changes</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-references">References</a></p>
</li>
</ul>
<h2 id="heading-1-prerequisites">1. Prerequisites</h2>
<p>Before starting, ensure you have the following:</p>
<ol>
<li><p>Flutter SDK installed (version 3.0.0 or higher recommended)</p>
</li>
<li><p>A code editor such as Android Studio or VS Code</p>
</li>
<li><p>Basic understanding of Flutter widgets, async/await in Dart, and state management</p>
</li>
<li><p>A physical device (recommended) or emulator/simulator</p>
</li>
<li><p>Internet connection to install dependencies</p>
</li>
</ol>
<h2 id="heading-2-installing-dependencies">2. Installing Dependencies</h2>
<p>To get started, add the following to your <code>pubspec.yaml</code> file:</p>
<pre><code class="lang-yaml"><span class="hljs-attr">dependencies:</span>
  <span class="hljs-attr">permission_handler:</span> <span class="hljs-string">^11.3.1</span>
  <span class="hljs-attr">fluttertoast:</span> <span class="hljs-string">^8.2.4</span>
</code></pre>
<p>Then run:</p>
<pre><code class="lang-bash">flutter pub get
</code></pre>
<ul>
<li><p><code>permission_handler</code> is used to request and check permissions on Android and iOS.</p>
</li>
<li><p><code>fluttertoast</code> allows you to display messages to users when permissions are granted or denied.</p>
</li>
</ul>
<h2 id="heading-3-understanding-permission-states">3. Understanding Permission States</h2>
<p>When requesting permissions with <code>permission_handler</code>, you can get the following states:</p>
<ol>
<li><p><code>isGranted</code> – The permission is granted.</p>
</li>
<li><p><code>isDenied</code> – The permission is denied, but can be requested again.</p>
</li>
<li><p><code>isPermanentlyDenied</code> – The permission is permanently denied, meaning the user must enable it from <strong>app settings</strong>.</p>
</li>
<li><p><code>isRestricted</code> – The permission is restricted by the system (common on iOS).</p>
</li>
<li><p><code>isLimited</code> – Partial access granted (mainly iOS photo library).</p>
</li>
</ol>
<h2 id="heading-4-reusable-permission-handling-function">4. Reusable Permission Handling Function</h2>
<p>Instead of writing multiple functions for each permission, we’ll create a reusable function:</p>
<pre><code class="lang-dart"><span class="hljs-keyword">import</span> <span class="hljs-string">'package:permission_handler/permission_handler.dart'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'package:fluttertoast/fluttertoast.dart'</span>;

Future&lt;<span class="hljs-keyword">void</span>&gt; handlePermission(Permission permission, <span class="hljs-built_in">String</span> name) <span class="hljs-keyword">async</span> {
  <span class="hljs-keyword">var</span> status = <span class="hljs-keyword">await</span> permission.request();

  <span class="hljs-keyword">if</span> (status.isGranted) {
    Fluttertoast.showToast(msg: <span class="hljs-string">'<span class="hljs-subst">$name</span> permission granted'</span>);
  } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (status.isPermanentlyDenied) {
    Fluttertoast.showToast(msg: <span class="hljs-string">'<span class="hljs-subst">$name</span> permission permanently denied. Enable it in settings.'</span>);
    openAppSettings();
  } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (status.isRestricted) {
    Fluttertoast.showToast(msg: <span class="hljs-string">'<span class="hljs-subst">$name</span> permission restricted by system.'</span>);
  } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (status.isLimited) {
    Fluttertoast.showToast(msg: <span class="hljs-string">'<span class="hljs-subst">$name</span> permission limited access granted.'</span>);
  } <span class="hljs-keyword">else</span> {
    Fluttertoast.showToast(msg: <span class="hljs-string">'<span class="hljs-subst">$name</span> permission denied'</span>);
  }
}
</code></pre>
<p>Usage example:</p>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.camera, <span class="hljs-string">"Camera"</span>);
<span class="hljs-keyword">await</span> handlePermission(Permission.location, <span class="hljs-string">"Location"</span>);
</code></pre>
<h2 id="heading-5-permissions-their-use-cases-and-examples">5. Permissions, Their Use Cases, and Examples</h2>
<p>Let’s now look at a bunch of different types of permissions you might have to enable in your Flutter apps. I’ll explain what the permission does and its common use cases as well.</p>
<h3 id="heading-51-calendar-permissions">5.1 Calendar Permissions</h3>
<ul>
<li><p><strong>Permission:</strong> <code>calendar</code>, <code>calendarReadOnly</code>, <code>calendarFullAccess</code></p>
</li>
<li><p><strong>What it does:</strong> Accesses the user’s calendar to read or write events.</p>
</li>
<li><p><strong>Use case:</strong> Event apps, scheduling apps.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.calendar, <span class="hljs-string">"Calendar"</span>);
</code></pre>
<h3 id="heading-52-camera-permission">5.2 Camera Permission</h3>
<ul>
<li><p><strong>Permission:</strong> <code>camera</code></p>
</li>
<li><p><strong>What it does:</strong> Access device camera for capturing photos/videos.</p>
</li>
<li><p><strong>Use case:</strong> QR scanning, photo apps, video recording.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.camera, <span class="hljs-string">"Camera"</span>);
</code></pre>
<h3 id="heading-53-contacts-permission">5.3 Contacts Permission</h3>
<ul>
<li><p><strong>Permission:</strong> <code>contacts</code></p>
</li>
<li><p><strong>What it does:</strong> Read or modify user contacts.</p>
</li>
<li><p><strong>Use case:</strong> Messaging apps, social networking apps.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.contacts, <span class="hljs-string">"Contacts"</span>);
</code></pre>
<h3 id="heading-54-location-permissions">5.4 Location Permissions</h3>
<ul>
<li><p><strong>Permission:</strong> <code>location</code>, <code>locationAlways</code>, <code>locationWhenInUse</code></p>
</li>
<li><p><strong>What it does:</strong> Access user’s location.</p>
</li>
<li><p><strong>Use case:</strong> Navigation apps, ride-hailing apps, geofencing.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.locationWhenInUse, <span class="hljs-string">"Location"</span>);
</code></pre>
<h3 id="heading-55-media-library-ios-only">5.5 Media Library (iOS only)</h3>
<ul>
<li><p><strong>Permission:</strong> <code>mediaLibrary</code></p>
</li>
<li><p><strong>What it does:</strong> Access media files on iOS devices.</p>
</li>
<li><p><strong>Use case:</strong> Photo sharing apps, media editors.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.mediaLibrary, <span class="hljs-string">"Media Library"</span>);
</code></pre>
<h3 id="heading-56-microphone-permission">5.6 Microphone Permission</h3>
<ul>
<li><p><strong>Permission:</strong> <code>microphone</code></p>
</li>
<li><p><strong>What it does:</strong> Record audio.</p>
</li>
<li><p><strong>Use case:</strong> Voice notes, video calls, voice commands.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.microphone, <span class="hljs-string">"Microphone"</span>);
</code></pre>
<h3 id="heading-57-phone-permission">5.7 Phone Permission</h3>
<ul>
<li><p><strong>Permission:</strong> <code>phone</code></p>
</li>
<li><p><strong>What it does:</strong> Access phone state, make calls, read call logs.</p>
</li>
<li><p><strong>Use case:</strong> Telephony apps, call management apps.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.phone, <span class="hljs-string">"Phone"</span>);
</code></pre>
<h3 id="heading-58-photos-permissions">5.8 Photos Permissions</h3>
<ul>
<li><p><strong>Permission:</strong> <code>photos</code>, <code>photosAddOnly</code></p>
</li>
<li><p><strong>What it does:</strong> Access or add photos to user library.</p>
</li>
<li><p><strong>Use case:</strong> Media apps, social apps.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.photos, <span class="hljs-string">"Photos"</span>);
</code></pre>
<h3 id="heading-59-reminders-permission">5.9 Reminders Permission</h3>
<ul>
<li><p><strong>Permission:</strong> <code>reminders</code></p>
</li>
<li><p><strong>What it does:</strong> Access and manage device reminders.</p>
</li>
<li><p><strong>Use case:</strong> To-do apps, productivity apps.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.reminders, <span class="hljs-string">"Reminders"</span>);
</code></pre>
<h3 id="heading-510-sensors-permissions">5.10 Sensors Permissions</h3>
<ul>
<li><p><strong>Permission:</strong> <code>sensors</code>, <code>sensorsAlways</code></p>
</li>
<li><p><strong>What it does:</strong> Access device sensors like accelerometer or gyroscope.</p>
</li>
<li><p><strong>Use case:</strong> Fitness apps, motion tracking apps.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.sensors, <span class="hljs-string">"Sensors"</span>);
</code></pre>
<h3 id="heading-511-sms-permission">5.11 SMS Permission</h3>
<ul>
<li><p><strong>Permission:</strong> <code>sms</code></p>
</li>
<li><p><strong>What it does:</strong> Read or send SMS messages.</p>
</li>
<li><p><strong>Use case:</strong> OTP verification, messaging apps.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.sms, <span class="hljs-string">"SMS"</span>);
</code></pre>
<h3 id="heading-512-speech-recognition-permission">5.12 Speech Recognition Permission</h3>
<ul>
<li><p><strong>Permission:</strong> <code>speech</code></p>
</li>
<li><p><strong>What it does:</strong> Use speech-to-text features.</p>
</li>
<li><p><strong>Use case:</strong> Voice commands, dictation apps.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.speech, <span class="hljs-string">"Speech Recognition"</span>);
</code></pre>
<h3 id="heading-513-storage-permissions">5.13 Storage Permissions</h3>
<ul>
<li><p><strong>Permission:</strong> <code>storage</code>, <code>manageExternalStorage</code></p>
</li>
<li><p><strong>What it does:</strong> Access internal/external storage to read/write files.</p>
</li>
<li><p><strong>Use case:</strong> File managers, download managers.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.storage, <span class="hljs-string">"Storage"</span>);
</code></pre>
<h3 id="heading-514-ignore-battery-optimizations">5.14 Ignore Battery Optimizations</h3>
<ul>
<li><p><strong>Permission:</strong> <code>ignoreBatteryOptimizations</code></p>
</li>
<li><p><strong>What it does:</strong> Request to exclude app from battery optimizations.</p>
</li>
<li><p><strong>Use case:</strong> Alarm apps, background services.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.ignoreBatteryOptimizations, <span class="hljs-string">"Battery Optimizations"</span>);
</code></pre>
<h3 id="heading-515-notifications">5.15 Notifications</h3>
<ul>
<li><p><strong>Permission:</strong> <code>notification</code></p>
</li>
<li><p><strong>What it does:</strong> Allow sending notifications.</p>
</li>
<li><p><strong>Use case:</strong> Messaging, reminders, alerts.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.notification, <span class="hljs-string">"Notifications"</span>);
</code></pre>
<h3 id="heading-516-bluetooth-permissions">5.16 Bluetooth Permissions</h3>
<ul>
<li><p><strong>Permission:</strong> <code>bluetooth</code>, <code>bluetoothScan</code>, <code>bluetoothAdvertise</code>, <code>bluetoothConnect</code></p>
</li>
<li><p><strong>What it does:</strong> Manage or connect to Bluetooth devices.</p>
</li>
<li><p><strong>Use case:</strong> Wearables, IoT devices, headphones.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.bluetooth, <span class="hljs-string">"Bluetooth"</span>);
</code></pre>
<h3 id="heading-517-app-tracking-transparency-ios-only">5.17 App Tracking Transparency (iOS only)</h3>
<ul>
<li><p><strong>Permission:</strong> <code>appTrackingTransparency</code></p>
</li>
<li><p><strong>What it does:</strong> Request tracking permission for personalized ads.</p>
</li>
<li><p><strong>Use case:</strong> Analytics, advertising, user tracking.</p>
</li>
</ul>
<pre><code class="lang-dart"><span class="hljs-keyword">await</span> handlePermission(Permission.appTrackingTransparency, <span class="hljs-string">"App Tracking"</span>);
</code></pre>
<h2 id="heading-6-android-manifest-configuration">6. Android Manifest Configuration</h2>
<p>On <strong>Android</strong>, all apps must declare the permissions they intend to use in the <code>AndroidManifest.xml</code> file. This acts as the app’s “contract” with the system, letting Android know what sensitive resources (like internet, location, camera) the app might request.</p>
<p>Without declaring these in the manifest, runtime permission requests will fail, even if you’ve added the <code>permission_handler</code> package.</p>
<p>For example, if you try to access the camera without first declaring the camera permission here, your app will crash or fail when requesting it at runtime.</p>
<p>Below is a comprehensive list of common permissions:</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!-- Camera access for taking pictures or recording videos --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.CAMERA"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Read user contacts (e.g., for social features, friend finder) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.READ_CONTACTS"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Fine-grained location (GPS) for maps, navigation, geofencing --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.ACCESS_FINE_LOCATION"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Coarse location (network-based, less accurate, uses WiFi/Cell) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.ACCESS_COARSE_LOCATION"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Record audio from the microphone (e.g., voice notes, calls) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.RECORD_AUDIO"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Read external storage (access user’s files like images, docs) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.READ_EXTERNAL_STORAGE"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Write to external storage (save downloaded files, photos) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.WRITE_EXTERNAL_STORAGE"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Send SMS directly from the app --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.SEND_SMS"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Receive SMS (read OTP messages for login/verification) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.RECEIVE_SMS"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Read SMS messages (OTP autofill, chat backup restore) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.READ_SMS"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Bluetooth usage (connect to Bluetooth devices like headsets, printers) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.BLUETOOTH"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Bluetooth Admin (manage paired devices, discover nearby devices) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.BLUETOOTH_ADMIN"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Bluetooth Scan (needed from Android 12+) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.BLUETOOTH_SCAN"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Bluetooth Connect (needed from Android 12+) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.BLUETOOTH_CONNECT"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Bluetooth Advertise (for beacon-style apps, Android 12+) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.BLUETOOTH_ADVERTISE"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Ignore battery optimizations (keep app alive in background tasks) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Internet access (needed for network requests, APIs, file uploads) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.INTERNET"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Check if a network connection exists (WiFi/Mobile data) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.ACCESS_NETWORK_STATE"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Access WiFi state (check SSID, connection info, used for network control) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.ACCESS_WIFI_STATE"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Change WiFi state (enable/disable WiFi programmatically) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.CHANGE_WIFI_STATE"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Access phone state (read device ID, SIM details, call status) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.READ_PHONE_STATE"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Make phone calls directly from the app --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.CALL_PHONE"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Use fingerprint authentication (for biometric login) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.USE_FINGERPRINT"</span> /&gt;</span>

<span class="hljs-comment">&lt;!-- Use Biometric authentication (newer than fingerprint, includes face) --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.USE_BIOMETRIC"</span> /&gt;</span>
</code></pre>
<h2 id="heading-7-ios-infoplist-configuration">7. iOS <code>Info.plist</code> Configuration</h2>
<p>For iOS, you must provide descriptive keys in the <code>Info.plist</code> file to inform users why your app needs specific permissions. Below are the configurations for each permission example:</p>
<ol>
<li><p><strong>Camera Permission</strong></p>
<pre><code class="lang-xml"> <span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>NSCameraUsageDescription<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>We need access to your camera for taking pictures.<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Contacts Permission</strong></p>
<pre><code class="lang-xml"> <span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>NSContactsUsageDescription<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>We need access to your contacts for better communication.<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Location Permissions</strong></p>
<pre><code class="lang-xml"> <span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>NSLocationWhenInUseUsageDescription<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>We need access to your location to provide location-based services.<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>NSLocationAlwaysUsageDescription<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>We need access to your location to track your movement even when the app is not active.<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Media Library/Storage Permission</strong></p>
<pre><code class="lang-xml"> <span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>NSPhotoLibraryUsageDescription<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>We need access to your photos for sharing or uploading media.<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Microphone Permission</strong></p>
<pre><code class="lang-xml"> <span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>NSMicrophoneUsageDescription<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>We need access to your microphone for voice recording.<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Phone Permission</strong></p>
<pre><code class="lang-xml"> <span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>NSPhoneUsageDescription<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>We need access to phone services to enable calls.<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Photos Permission</strong></p>
<pre><code class="lang-xml"> <span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>NSPhotoLibraryAddUsageDescription<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>We need permission to add photos to your library.<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Reminders Permission</strong></p>
<pre><code class="lang-xml"> <span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>NSRemindersUsageDescription<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>We need access to your reminders for task management.<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Sensors Permission</strong></p>
<pre><code class="lang-xml"> <span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>NSSensorsUsageDescription<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>We need access to your sensors for fitness tracking.<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>SMS Permission</strong> (Handled automatically by iOS if SMS services are requested)</p>
</li>
<li><p><strong>Speech Recognition Permission</strong></p>
</li>
</ol>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>NSSpeechRecognitionUsageDescription<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>We need access to speech recognition for voice commands.<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span>
</code></pre>
<ol start="12">
<li><p><strong>Ignore Battery Optimizations</strong> (Not applicable on iOS)</p>
</li>
<li><p><strong>Notifications Permission</strong></p>
</li>
</ol>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>NSUserNotificationUsageDescription<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>We need permission to send notifications.<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span>
</code></pre>
<ol start="14">
<li><p><strong>Access Media Location Permission</strong> (Handled automatically on iOS)</p>
</li>
<li><p><strong>Activity Recognition Permission</strong></p>
</li>
</ol>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>NSMotionUsageDescription<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>We need access to motion data for fitness tracking.<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span>
</code></pre>
<ol start="16">
<li><strong>Bluetooth Permissions</strong></li>
</ol>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>NSBluetoothPeripheralUsageDescription<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>We need access to Bluetooth for device connectivity.<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span>
</code></pre>
<ol start="17">
<li><strong>App Tracking Transparency</strong></li>
</ol>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>NSUserTrackingUsageDescription<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>We need permission to track your activity across apps and websites for personalized ads.<span class="hljs-tag">&lt;/<span class="hljs-name">st</span></span>
</code></pre>
<h2 id="heading-8-expected-outcomes">8. Expected Outcomes</h2>
<p>By implementing permissions and connectivity checks this way, your Flutter app will:</p>
<ol>
<li><p>Request permissions dynamically at runtime in a user-friendly way.</p>
</li>
<li><p>Handle all possible states gracefully, including granted, denied, permanently denied, restricted, and limited.</p>
</li>
<li><p>Provide users with meaningful feedback, guiding them to settings if necessary.</p>
</li>
<li><p>Maintain compliance with Android and iOS permission policies while ensuring security and transparency.</p>
</li>
<li><p>Listen continuously to network connectivity changes via the global BLoC listener.</p>
</li>
<li><p>Notify users instantly with a toast/snackbar whenever internet status changes (connected/disconnected).</p>
</li>
<li><p>Reduce redundant API calls and improve UX by avoiding “fake” offline or cached-only states.</p>
</li>
</ol>
<h2 id="heading-best-practices-for-handling-permissions-in-flutter">Best Practices for Handling Permissions in Flutter</h2>
<p>There are some common best practices you should follow when handling permissions in Flutter.</p>
<h3 id="heading-1-request-only-necessary-permissions">1. Request only necessary permissions</h3>
<p>Ask only for the permissions your app truly needs. For example, if your app just uploads images, you probably only need <strong>storage/photos access</strong>, not location, contacts, or SMS.</p>
<pre><code class="lang-dart"><span class="hljs-keyword">final</span> status = <span class="hljs-keyword">await</span> Permission.photos.request();
<span class="hljs-keyword">if</span> (status.isGranted) {
  <span class="hljs-comment">// Proceed with photo upload</span>
}
</code></pre>
<h3 id="heading-2-explain-why-permissions-are-needed">2. Explain why permissions are needed</h3>
<p>Always tell the user <em>why</em> you’re asking for a sensitive permission before the system dialog appears. This helps build trust.</p>
<p>Example of a custom dialog before requesting:</p>
<pre><code class="lang-dart">Future&lt;<span class="hljs-keyword">void</span>&gt; _showPermissionRationale(BuildContext context) <span class="hljs-keyword">async</span> {
  showDialog(
    context: context,
    builder: (context) =&gt; AlertDialog(
      title: Text(<span class="hljs-string">"Camera Access Needed"</span>),
      content: Text(<span class="hljs-string">"We need access to your camera so you can take profile photos."</span>),
      actions: [
        TextButton(
          onPressed: () {
            Navigator.pop(context);
            Permission.camera.request();
          },
          child: Text(<span class="hljs-string">"Allow"</span>),
        ),
        TextButton(
          onPressed: () =&gt; Navigator.pop(context),
          child: Text(<span class="hljs-string">"Cancel"</span>),
        ),
      ],
    ),
  );
}
</code></pre>
<h3 id="heading-3-use-runtime-permission-requests">3. Use runtime permission requests</h3>
<p>On Android 6.0+ and iOS, permissions must be requested <strong>at runtime</strong> (not just declared in <code>AndroidManifest.xml</code> or <code>Info.plist</code>).</p>
<pre><code class="lang-dart"><span class="hljs-keyword">final</span> status = <span class="hljs-keyword">await</span> Permission.location.request();
<span class="hljs-keyword">if</span> (status.isGranted) {
  <span class="hljs-comment">// Use location</span>
}
</code></pre>
<h3 id="heading-4-handle-denial-gracefully">4. Handle denial gracefully</h3>
<p>Don’t block the entire app when permissions are denied. Provide alternative flows.</p>
<p>For example, instead of forcing camera access:</p>
<pre><code class="lang-dart"><span class="hljs-keyword">if</span> (<span class="hljs-keyword">await</span> Permission.camera.isDenied) {
  <span class="hljs-comment">// Offer file upload as fallback</span>
  _pickImageFromGallery();
}
</code></pre>
<p>This way, users can still use your app without being forced.</p>
<h3 id="heading-5-handle-permanent-denials">5. Handle permanent denials</h3>
<p>When a user selects <em>“Don’t ask again”</em> (Android) or disables a permission in Settings (iOS), you should guide them to <strong>Settings</strong>.</p>
<pre><code class="lang-dart"><span class="hljs-keyword">if</span> (<span class="hljs-keyword">await</span> Permission.camera.isPermanentlyDenied) {
  openAppSettings(); <span class="hljs-comment">// Takes user to app settings</span>
}
</code></pre>
<p>UX Example:</p>
<ul>
<li>Show a snackbar: <em>“Camera access is required. Enable it in Settings.”</em> with a <strong>Go to Settings</strong> button.</li>
</ul>
<h3 id="heading-6-test-on-both-platforms">6. Test on both platforms</h3>
<p>Permissions behave differently across Android and iOS. Example:</p>
<ul>
<li><p>iOS may return limited photo library access.</p>
</li>
<li><p>Android 13+ has new granular media permissions (<code>READ_MEDIA_IMAGES</code>, <code>READ_MEDIA_VIDEO</code>).</p>
</li>
</ul>
<p>Always test all scenarios:</p>
<ul>
<li><p>Granted</p>
</li>
<li><p>Denied once</p>
</li>
<li><p>Denied permanently</p>
</li>
<li><p>Limited (iOS only)</p>
</li>
</ul>
<h3 id="heading-7-follow-platform-guidelines">7. Follow platform guidelines</h3>
<p>Make sure your manifest and Info.plist contain clear explanations.</p>
<p><strong>Info.plist example (iOS):</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>NSCameraUsageDescription<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>This app requires camera access to let you take profile pictures.<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span>
</code></pre>
<p>This is required for App Store approval.</p>
<h3 id="heading-8-avoid-over-permissioning">8. Avoid over-permissioning</h3>
<p>Example: Don’t request SMS if you only need phone number autofill. Users will abandon your app if they see irrelevant requests.</p>
<p><strong>Bad:</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">uses-permission</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.permission.SEND_SMS"</span> /&gt;</span>
</code></pre>
<p>Just use <code>READ_PHONE_NUMBERS</code> if that’s the actual need.</p>
<h3 id="heading-9-use-a-centralized-permission-manager">9. Use a centralized permission manager</h3>
<p>Instead of scattering requests across the app, create a PermissionService that handles all requests consistently.</p>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PermissionService</span> </span>{
  Future&lt;<span class="hljs-built_in">bool</span>&gt; requestCamera() <span class="hljs-keyword">async</span> {
    <span class="hljs-keyword">final</span> status = <span class="hljs-keyword">await</span> Permission.camera.request();
    <span class="hljs-keyword">return</span> status.isGranted;
  }

  Future&lt;<span class="hljs-built_in">bool</span>&gt; requestLocation() <span class="hljs-keyword">async</span> {
    <span class="hljs-keyword">final</span> status = <span class="hljs-keyword">await</span> Permission.location.request();
    <span class="hljs-keyword">return</span> status.isGranted;
  }
}
</code></pre>
<p>This keeps permission handling uniform.</p>
<h3 id="heading-10-monitor-permission-changes">10. Monitor permission changes</h3>
<p>Permissions can change while the app is open (user goes to Settings and disables it). Always check before use.</p>
<pre><code class="lang-dart"><span class="hljs-meta">@override</span>
<span class="hljs-keyword">void</span> initState() {
  <span class="hljs-keyword">super</span>.initState();
  Timer.periodic(<span class="hljs-built_in">Duration</span>(seconds: <span class="hljs-number">5</span>), (timer) <span class="hljs-keyword">async</span> {
    <span class="hljs-keyword">final</span> cameraStatus = <span class="hljs-keyword">await</span> Permission.camera.status;
    <span class="hljs-keyword">if</span> (!cameraStatus.isGranted) {
      <span class="hljs-comment">// Disable camera UI</span>
    }
  });
}
</code></pre>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Permissions are fundamental for building fully functional and secure mobile applications. Using <code>permission_handler</code> in Flutter allows you to manage permissions across Android and iOS efficiently.</p>
<p>And just remember: always request only necessary permissions, provide clear explanations, and handle all possible states to maintain trust with users.</p>
<p>By combining correct permission logic with proper AndroidManifest and Info.plist setup, you ensure a seamless user experience while staying compliant with platform guidelines.</p>
<h2 id="heading-references">References</h2>
<ol>
<li><p><a target="_blank" href="https://pub.dev/packages/permission_handler">permission_handler Flutter Package Documentation</a></p>
</li>
<li><p><a target="_blank" href="https://docs.flutter.dev/cookbook/plugins/picture-using-camera">Flutter Official Documentation: Handling Permissions</a></p>
</li>
<li><p><a target="_blank" href="https://developer.android.com/guide/topics/permissions/overview">Android Developer Guide: Permissions</a></p>
</li>
<li><p><a target="_blank" href="https://developer.apple.com/documentation/bundleresources/information_property_list">iOS Developer Guide: App Permissions</a></p>
</li>
<li><p><a target="_blank" href="https://pub.dev/packages/fluttertoast">Fluttertoast Package Documentation</a></p>
</li>
</ol>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Fix the Python ENOENT Error When Setting Up MCP Servers – A Complete Guide ]]>
                </title>
                <description>
                    <![CDATA[ Getting the "spawn python ENOENT" error while setting up an MCP (Model Context Protocol) server on macOS can be frustrating. But don't worry – in this tutorial, I'll guide you through fixing it by rebuilding your Python virtual environment. By the en... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-fix-the-python-enoent-error-when-setting-up-mcp-servers-a-complete-guide/</link>
                <guid isPermaLink="false">68963890790ac4491c15b00a</guid>
                
                    <category>
                        <![CDATA[ mcp server ]]>
                    </category>
                
                    <category>
                        <![CDATA[ AI ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Developer ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Beginner Developers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ macOS ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Idris Olubisi ]]>
                </dc:creator>
                <pubDate>Fri, 08 Aug 2025 17:49:04 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1754675334533/6a05e45a-9703-49c0-b427-6c4960c01d86.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Getting the "spawn python ENOENT" error while setting up an MCP (Model Context Protocol) server on macOS can be frustrating. But don't worry – in this tutorial, I'll guide you through fixing it by rebuilding your Python virtual environment.</p>
<p>By the end, you'll have a fully functional MCP server integrated with Claude Desktop in about 10 minutes. This solution applies to any MCP setup facing this standard error after Python upgrades.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ol>
<li><p><a class="post-section-overview" href="#heading-what-causes-the-enoent-error">What Causes the ENOENT Error?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-prerequisites">Prerequisites</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-diagnose-your-broken-virtual-environment">How to Diagnose Your Broken Virtual Environment</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-completely-rebuild-your-virtual-environment">How to Completely Rebuild Your Virtual Environment</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-install-mcp-server-dependencies">How to Install MCP Server Dependencies</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-locate-your-server-files">How to Locate Your Server Files</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-test-your-server-setup">How to Test Your Server Setup</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-configure-claude-desktop">How to Configure Claude Desktop</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-restart-claude-desktop-and-test-integration">How to Restart Claude Desktop and Test Integration</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-understanding-mcp-server-capabilities">Understanding MCP Server Capabilities</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-alternative-installation-methods">Alternative Installation Methods</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-method-1-direct-package-installation">Method 1: Direct Package Installation</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-method-2-using-uv-package-manager">Method 2: Using UV Package Manager</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-prevent-future-enoent-errors">How to Prevent Future ENOENT Errors</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-troubleshooting-common-issues">Troubleshooting Common Issues</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></p>
</li>
</ol>
<h2 id="heading-what-causes-the-enoent-error">What Causes the ENOENT Error?</h2>
<p>The ENOENT (Error NO ENTry) error means your system can’t locate the Python executable at the specified path. This occurs when the file is missing or inaccessible.</p>
<p>On macOS, this typically happens when:</p>
<ul>
<li><p>You've upgraded Python through Homebrew</p>
</li>
<li><p>The <code>brew cleanup</code> command removed old Python versions</p>
</li>
<li><p>Your virtual environment's symlinks now point to non-existent files</p>
</li>
</ul>
<p>What makes this particularly challenging is that your virtual environment folder still exists – it looks fine from the outside, but the Python executable inside is completely broken.</p>
<p>When MCP servers try to spawn Python processes using these broken paths, you get the dreaded ENOENT error. This affects any Python-based MCP server, whether you're building custom tools, connecting to APIs, or working with file systems.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>To follow this tutorial, you'll need:</p>
<ul>
<li><p>macOS with <a target="_blank" href="https://brew.sh/">Homebrew</a> installed</p>
</li>
<li><p>Python 3.10 or higher</p>
</li>
<li><p>An MCP server repository cloned locally</p>
</li>
<li><p><a target="_blank" href="https://claude.ai/download">Claude Desktop</a> installed</p>
</li>
<li><p>Basic familiarity with terminal commands and Python virtual environments</p>
</li>
</ul>
<p>If you haven't cloned an MCP server repository yet, you can start with any open-source MCP server. For this tutorial, I'll use generic examples that work with any MCP setup:</p>
<pre><code class="lang-bash">git <span class="hljs-built_in">clone</span> https://github.com/your-username/your-mcp-server.git
<span class="hljs-built_in">cd</span> your-mcp-server
</code></pre>
<h2 id="heading-how-to-diagnose-your-broken-virtual-environment">How to Diagnose Your Broken Virtual Environment</h2>
<p>First, you need to confirm that your virtual environment is actually the problem. Open your terminal and navigate to your MCP directory:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> /path/to/your/mcp-server
</code></pre>
<p>Now check if your Python executable exists:</p>
<pre><code class="lang-bash">ls -la venv/bin/python*
</code></pre>
<p>If you see broken symlinks or get "No such file or directory" errors, you've found your problem. You might see output like:</p>
<pre><code class="lang-bash">lrwxr-xr-x  1 username  staff  16 Jan  1 12:00 python -&gt; /usr/<span class="hljs-built_in">local</span>/bin/python3.11
lrwxr-xr-x  1 username  staff  16 Jan  1 12:00 python3 -&gt; /usr/<span class="hljs-built_in">local</span>/bin/python3.11
</code></pre>
<p>But when you try to run these Python executables:</p>
<pre><code class="lang-bash">./venv/bin/python --version
</code></pre>
<p>You'll get an error because the target files no longer exist. This confirms your virtual environment is broken and needs rebuilding.</p>
<h2 id="heading-how-to-completely-rebuild-your-virtual-environment">How to Completely Rebuild Your Virtual Environment</h2>
<p>The most reliable solution is to rebuild your virtual environment from scratch. This ensures all paths and dependencies are correctly configured for your current Python installation.</p>
<p>Here's your step-by-step rebuild process:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Make sure you're in the MCP server directory</span>
<span class="hljs-built_in">cd</span> /path/to/your/mcp-server

<span class="hljs-comment"># Remove the corrupted virtual environment</span>
rm -rf venv

<span class="hljs-comment"># Create a fresh virtual environment</span>
python3 -m venv venv

<span class="hljs-comment"># Activate the new environment</span>
<span class="hljs-built_in">source</span> venv/bin/activate
</code></pre>
<p>You should now see <code>(venv)</code> in your terminal prompt, indicating the virtual environment is active. This prefix confirms you're working within the isolated Python environment.</p>
<h2 id="heading-how-to-install-mcp-server-dependencies">How to Install MCP Server Dependencies</h2>
<p>With your fresh virtual environment active, install the MCP server and its dependencies. The exact installation command depends on your specific MCP server, but typically follows one of these patterns:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># For package-based installation</span>
pip install -e .

<span class="hljs-comment"># Or for requirements file</span>
pip install -r requirements.txt

<span class="hljs-comment"># Or for specific MCP frameworks</span>
pip install fastmcp
</code></pre>
<p>Common MCP server dependencies include:</p>
<ul>
<li><p>FastMCP for the server framework</p>
</li>
<li><p>JSON-RPC libraries for communication protocols</p>
</li>
<li><p>HTTP clients for API integrations</p>
</li>
<li><p>File system utilities for local operations</p>
</li>
</ul>
<p>The installation process displays all packages as they install. Don't worry if you see deprecation warnings – they're normal and won't affect functionality.</p>
<h2 id="heading-how-to-locate-your-server-files">How to Locate Your Server Files</h2>
<p>After installation, identify where your main server file lives. Run this command to find all server.py files:</p>
<pre><code class="lang-bash">find . -name <span class="hljs-string">"server.py"</span> -<span class="hljs-built_in">type</span> f
</code></pre>
<p>You may see results like:</p>
<ul>
<li><p><code>./server.py</code> (in the root directory)</p>
</li>
<li><p><code>./src/server.py</code> (in a source directory)</p>
</li>
<li><p><code>./mcp_server/server.py</code> (in a package directory)</p>
</li>
</ul>
<p>Check your current directory structure:</p>
<pre><code class="lang-bash">ls -la
</code></pre>
<p>Look for the main server entry point. Most MCP servers follow standard Python project structures with either a root-level server file or one nested in a package directory.</p>
<h2 id="heading-how-to-test-your-server-setup">How to Test Your Server Setup</h2>
<p>Now you’ll want to test your server to ensure it's working correctly. Start with the main server file you identified:</p>
<pre><code class="lang-bash">python server.py
</code></pre>
<p>If this is the correct server and everything is configured correctly, you'll see output similar to:</p>
<pre><code class="lang-typescript">╭─ MCP Server ───────────────────────────────────────────────────────────────╮
│ 🖥️  Server name: Example-MCP                                              │
│ 📦 Transport: STDIO                                                        │
│ 🤝 Protocol: <span class="hljs-built_in">JSON</span>-RPC                                                      │
╰────────────────────────────────────────────────────────────────────────────╯
[INFO] Starting MCP server <span class="hljs-keyword">with</span> transport <span class="hljs-string">'stdio'</span>
[INFO] Server ready <span class="hljs-keyword">for</span> connections
</code></pre>
<p>This output confirms your MCP server is working correctly. The server uses standard input/output (STDIO) for communication, which is perfect for Claude Desktop integration. You can stop the server with <code>Ctrl+C</code>.</p>
<h2 id="heading-how-to-configure-claude-desktop">How to Configure Claude Desktop</h2>
<p>Now that your server runs properly, configure Claude Desktop to connect to it. The configuration file location depends on your operating system:</p>
<p><strong>For macOS:</strong></p>
<pre><code class="lang-bash">~/Library/Application Support/Claude/claude_desktop_config.json
</code></pre>
<p><strong>For Windows:</strong></p>
<pre><code class="lang-bash">%APPDATA%\Claude\claude_desktop_config.json
</code></pre>
<p><strong>For Linux:</strong></p>
<pre><code class="lang-bash">~/.config/Claude/claude_desktop_config.json
</code></pre>
<p>Create or edit this file with your exact paths. Your configuration should look like this:</p>
<pre><code class="lang-json">{
  <span class="hljs-attr">"mcpServers"</span>: {
    <span class="hljs-attr">"example-mcp"</span>: {
      <span class="hljs-attr">"command"</span>: <span class="hljs-string">"/Users/yourusername/path/to/mcp-server/venv/bin/python"</span>,
      <span class="hljs-attr">"args"</span>: [<span class="hljs-string">"/Users/yourusername/path/to/mcp-server/server.py"</span>],
      <span class="hljs-attr">"cwd"</span>: <span class="hljs-string">"/Users/yourusername/path/to/mcp-server"</span>
    }
  }
}
</code></pre>
<p>Replace <code>/Users/yourusername/path/to/mcp-server/</code> with your actual path. You can get your precise path by running <code>pwd</code> in your MCP server directory.</p>
<p>The configuration tells Claude Desktop:</p>
<ul>
<li><p>Which Python interpreter to use (from your virtual environment)</p>
</li>
<li><p>Where to find the server script</p>
</li>
<li><p>Which directory to run the server from</p>
</li>
</ul>
<h2 id="heading-how-to-restart-claude-desktop-and-test-integration">How to Restart Claude Desktop and Test Integration</h2>
<p>After saving your configuration file, altogether quit Claude Desktop (not just close the window). On macOS, use <code>Cmd+Q</code> or right-click the dock icon and select Quit. Then restart Claude Desktop.</p>
<p>Once Claude Desktop is running again, test your MCP integration. You can verify the connection by:</p>
<ol>
<li><p>Looking for your MCP server name in Claude's interface</p>
</li>
<li><p>Testing basic MCP functionality with prompts like:</p>
<ul>
<li><p>"What MCP tools are available?"</p>
</li>
<li><p>"Can you check the MCP server status?"</p>
</li>
<li><p>"Show me the available MCP commands"</p>
</li>
</ul>
</li>
</ol>
<p>If everything is working correctly, Claude will respond using the MCP server tools, confirming successful integration.</p>
<h2 id="heading-understanding-mcp-server-capabilities">Understanding MCP Server Capabilities</h2>
<p>MCP servers extend Claude's capabilities by providing structured access to external tools and data sources. Common MCP server implementations include:</p>
<ol>
<li><p>File system operations: MCP servers can provide controlled access to local files, allowing Claude to read, analyze, and process documents while maintaining security boundaries.</p>
</li>
<li><p>API integrations: Connect Claude to external services through MCP servers that handle authentication, rate limiting, and data formatting for various APIs.</p>
</li>
<li><p>Database connections: Query databases safely through MCP servers that manage connections, handle credentials securely, and format results for Claude's consumption.</p>
</li>
<li><p>Custom tools: Build specialized tools for your workflow, from code analysis to data processing, all accessible through the standardized MCP interface.</p>
</li>
</ol>
<p>The beauty of MCP is its flexibility – you can create servers for virtually any tool or service you need Claude to interact with.</p>
<h2 id="heading-alternative-installation-methods">Alternative Installation Methods</h2>
<p>If you want more streamlined approaches for future setups, here are two excellent alternatives:</p>
<h3 id="heading-method-1-direct-package-installation">Method 1: Direct Package Installation</h3>
<p>For MCP servers available as packages, you can install directly:</p>
<pre><code class="lang-bash">pip install mcp-server-package
</code></pre>
<p>Then use this simpler configuration:</p>
<pre><code class="lang-json">{
  <span class="hljs-attr">"mcpServers"</span>: {
    <span class="hljs-attr">"example-mcp"</span>: {
      <span class="hljs-attr">"command"</span>: <span class="hljs-string">"mcp-server-command"</span>
    }
  }
}
</code></pre>
<p>This method works when the MCP server provides a command-line entry point through its setup configuration.</p>
<h3 id="heading-method-2-using-uv-package-manager">Method 2: Using UV Package Manager</h3>
<p>UV provides more robust dependency management – perfect if you're tired of Python version conflicts:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Install UV</span>
curl -LsSf https://astral.sh/uv/install.sh | sh

<span class="hljs-comment"># Use UV in your configuration</span>
{
  <span class="hljs-string">"mcpServers"</span>: {
    <span class="hljs-string">"example-mcp"</span>: {
      <span class="hljs-string">"command"</span>: <span class="hljs-string">"uv"</span>,
      <span class="hljs-string">"args"</span>: [
        <span class="hljs-string">"run"</span>,
        <span class="hljs-string">"--with"</span>, <span class="hljs-string">"fastmcp"</span>,
        <span class="hljs-string">"python"</span>,
        <span class="hljs-string">"/path/to/mcp-server/server.py"</span>
      ],
      <span class="hljs-string">"cwd"</span>: <span class="hljs-string">"/path/to/mcp-server"</span>
    }
  }
}
</code></pre>
<p>UV automatically manages Python versions and dependencies, reducing the likelihood of environment-related errors.</p>
<h2 id="heading-how-to-prevent-future-enoent-errors">How to Prevent Future ENOENT Errors</h2>
<p>To avoid this issue in the future, follow these best practices:</p>
<h3 id="heading-1-use-virtual-environment-copies-instead-of-symlinks">1. Use Virtual Environment Copies Instead of Symlinks</h3>
<p>When creating virtual environments, use the <code>--copies</code> flag:</p>
<pre><code class="lang-bash">python3 -m venv venv --copies
</code></pre>
<p>This creates actual copies of files instead of symlinks, making your environment more resilient to Python upgrades.</p>
<h3 id="heading-2-pin-your-homebrew-python-version">2. Pin Your Homebrew Python Version</h3>
<p>Prevent automatic Python upgrades that break environments:</p>
<pre><code class="lang-bash">brew pin python@3.11
</code></pre>
<p>Remember to unpin when you're ready to upgrade intentionally.</p>
<h3 id="heading-3-create-a-health-check-script">3. Create a Health Check Script</h3>
<p>Save this script as <code>health_check.sh</code> in your MCP server directory:</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>
<span class="hljs-comment"># health_check.sh</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"Checking Python virtual environment..."</span>
<span class="hljs-built_in">source</span> venv/bin/activate

python -c <span class="hljs-string">"import sys; print(f'Python: {sys.executable}')"</span>
python -c <span class="hljs-string">"print('✓ Python is working')"</span>

<span class="hljs-comment"># Check for common MCP dependencies</span>
python -c <span class="hljs-string">"import json; print('✓ JSON module available')"</span>
python -c <span class="hljs-string">"import asyncio; print('✓ Asyncio available')"</span>

<span class="hljs-built_in">echo</span> <span class="hljs-string">"Health check complete!"</span>
</code></pre>
<p>Make it executable and run it periodically:</p>
<pre><code class="lang-bash">chmod +x health_check.sh
./health_check.sh
</code></pre>
<h3 id="heading-4-document-your-python-version">4. Document Your Python Version</h3>
<p>Create a <code>.python-version</code> file in your project:</p>
<pre><code class="lang-bash">python --version &gt; .python-version
</code></pre>
<p>This helps you remember which Python version the project was built with.</p>
<h2 id="heading-troubleshooting-common-issues">Troubleshooting Common Issues</h2>
<p>Even with the fix applied, you might encounter these challenges:</p>
<h3 id="heading-import-errors">Import Errors</h3>
<p>If you see import-related errors, ensure all dependencies are installed:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">source</span> venv/bin/activate
pip list  <span class="hljs-comment"># Check installed packages</span>
pip install -r requirements.txt  <span class="hljs-comment"># Reinstall if needed</span>
</code></pre>
<h3 id="heading-permission-denied-errors">Permission Denied Errors</h3>
<p>Make sure your server file is executable:</p>
<pre><code class="lang-bash">chmod +x server.py
</code></pre>
<h3 id="heading-claude-desktop-not-finding-the-server">Claude Desktop Not Finding the Server</h3>
<p>Double-check your configuration paths are absolute, not relative:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Good - absolute path</span>
<span class="hljs-string">"/Users/username/projects/mcp-server/server.py"</span>

<span class="hljs-comment"># Bad - relative path</span>
<span class="hljs-string">"./server.py"</span>
</code></pre>
<h3 id="heading-server-starts-but-claude-cant-connect">Server Starts, But Claude Can't Connect</h3>
<p>Verify that the transport method matches between your server and the configuration. Most MCP servers use STDIO, but some might use HTTP or WebSocket transports.</p>
<h3 id="heading-multiple-python-installations">Multiple Python Installations</h3>
<p>If you have multiple Python versions, be explicit about which one to use:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Check available Python versions</span>
ls -la /usr/<span class="hljs-built_in">local</span>/bin/python*

<span class="hljs-comment"># Use a specific version</span>
/usr/<span class="hljs-built_in">local</span>/bin/python3.11 -m venv venv
</code></pre>
<h2 id="heading-conclusion">Conclusion</h2>
<p>You've successfully fixed the "spawn python ENOENT" error by rebuilding your Python virtual environment and properly configuring your MCP server for Claude Desktop. You've also learned how to prevent future mistakes and troubleshoot common issues.</p>
<p>With your MCP server running smoothly, you can now:</p>
<ul>
<li><p>Build custom tools that extend Claude's capabilities</p>
</li>
<li><p>Create integrations with your favorite services</p>
</li>
<li><p>Develop specialized workflows for your specific needs</p>
</li>
<li><p>Share your MCP servers with the community</p>
</li>
</ul>
<p>The <a target="_blank" href="https://www.anthropic.com/news/model-context-protocol">MCP</a> ecosystem is growing rapidly, with new servers and tools being developed constantly. Whether you're building file system tools, API integrations, or custom utilities, you now have the foundation to create and maintain robust MCP servers.</p>
<p>Happy building, and enjoy your error-free development journey! For more tutorials, follow my work on <a target="_blank" href="https://github.com/Olanetsoft">GitHub</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ A Beginner Developer's Guide to Kanban ]]>
                </title>
                <description>
                    <![CDATA[ First, a confession: When I was learning to code, my “workflow” was a mess. Sticky notes. Google Docs. Random Trello boards I never checked again. And a to-do list that somehow never got any shorter. Then I joined a real team. Suddenly, I was introdu... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/a-beginner-developers-guide-to-kanban/</link>
                <guid isPermaLink="false">68815e6054ad71fa4b3b7bb6</guid>
                
                    <category>
                        <![CDATA[ agile ]]>
                    </category>
                
                    <category>
                        <![CDATA[ agile methodology ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Agile Software Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Career ]]>
                    </category>
                
                    <category>
                        <![CDATA[ interview ]]>
                    </category>
                
                    <category>
                        <![CDATA[ kanban ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Kanban boards ]]>
                    </category>
                
                    <category>
                        <![CDATA[ project management ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Product Management ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Product Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Productivity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Beginner Developers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Developer ]]>
                    </category>
                
                    <category>
                        <![CDATA[ workflow ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Aditya Vikram Kashyap ]]>
                </dc:creator>
                <pubDate>Wed, 23 Jul 2025 22:12:48 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1753300952223/508231c9-f0bc-4aa8-9c97-5ad4157891b9.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>First, a confession<strong>:</strong> When I was learning to code, my “workflow” was a mess. Sticky notes. Google Docs. Random Trello boards I never checked again. And a to-do list that somehow never got any shorter.</p>
<p>Then I joined a real team.</p>
<p>Suddenly, I was introduced to this thing called <strong>Kanban</strong> – and I realized I’d been treating software like a solo art project, not a process.</p>
<p>If that sounds familiar, you’re in the right place.</p>
<p>This guide will walk you through <strong>how Kanban actually works</strong>, how developers use it to track and prioritize work, and how it can help you stay sane when juggling bugs, features, and real-world deadlines.</p>
<p>Without further delay, lets get into it.</p>
<h3 id="heading-heres-what-well-cover">Here’s what we’ll cover:</h3>
<ul>
<li><p><a class="post-section-overview" href="#heading-so-what-is-kanban">So… What Is Kanban?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-classic-kanban-board-three-simple-columns">The Classic Kanban Board: Three Simple Columns</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-developers-use-kanban-in-real-life">How Developers Use Kanban in Real Life</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-kanban-vs-scrum-whats-the-difference">Kanban vs Scrum: What’s the Difference?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-so-which-one-should-you-use-scrum-or-kanban">So which one should you use Scrum or Kanban?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-tools-do-teams-use-for-kanban">What Tools Do Teams Use for Kanban?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-use-kanban-to-manage-your-own-coding-projects">How to Use Kanban to Manage Your Own Coding Projects</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-final-thoughts-why-kanban-isnt-just-a-board">Final Thoughts: Why Kanban Isn’t Just a Board</a></p>
</li>
</ul>
<h2 id="heading-so-what-is-kanban">So… What Is Kanban?</h2>
<p>At its core, Kanban is a <strong>visual way to manage work</strong>. It helps teams (or team members) see:</p>
<ul>
<li><p>What needs to get done</p>
</li>
<li><p>What’s in progress</p>
</li>
<li><p>What’s finished</p>
</li>
<li><p>Where things are getting stuck</p>
</li>
</ul>
<p>The concept comes from lean manufacturing, but in tech, it’s often used in Agile teams that need flexibility without the structure of Scrum sprints.</p>
<p>Think of Kanban like a whiteboard that tells a story. Not just what’s done, but how work flows.</p>
<h2 id="heading-the-classic-kanban-board-three-simple-columns">The Classic Kanban Board: Three Simple Columns</h2>
<p>So what exactly is a Kanban board? At its core, it’s a visual representation of your workflow – a board that shows all the work your team (or you, solo warrior) are juggling, and where each task stands.</p>
<p>It can be physical, like an actual whiteboard with sticky notes that move from one column to the next. Or digital, using tools like Trello, Jira, GitHub Projects, or Notion. The key is that it’s visual and up-to-date. You can walk into a room or open a tab and instantly understand: What’s being worked on? What’s ready to go? Where are things stuck?</p>
<p>It’s like having your brain on a wall, but organized. And slightly less chaotic.</p>
<p>The beauty of Kanban is how dead simple it is to get started. At minimum, your board has three columns:</p>
<table><tbody><tr><td><p><strong>&nbsp;To Do</strong></p></td><td><p><strong>In Progress</strong></p></td><td><p><strong>Done</strong></p></td></tr></tbody></table>

<p>Each task – or <strong>card</strong> – moves from left to right as it gets worked on.</p>
<p>Let’s say your team is building a blog platform. Your Kanban board might have cards like:</p>
<ul>
<li><p>“Create signup form”</p>
</li>
<li><p>“Fix image upload bug”</p>
</li>
<li><p>“Deploy staging build”</p>
</li>
</ul>
<p>Now, while Kanban is flexible, it can absolutely be taken too far.</p>
<p>I’ve seen boards with more columns than a Greek temple: “Needs Review,” “Pending Client Feedback,” “QA Rework Round 2,” “Blocked but Still Hopeful,” “In Existential Limbo,” and so on. Every card had six tags, three owners, two checklists, and one migraine.</p>
<p>The lesson? Don’t turn your board into a bureaucratic jungle.</p>
<p>You don’t need to account for every edge case. Start simple: “To Do,” “In Progress,” “Review,” “Done.” These basic stages cover most workflows. If you discover a real need for something more – like a dedicated “QA” column or “Blocked” column – add it intentionally, not because you feel like your board needs to look fancy.</p>
<p>Remember: A Kanban board should be helpful, not overwhelming. If you spend more time managing the board than doing the work on it… it’s doing the opposite of what it’s meant to do.</p>
<h2 id="heading-how-developers-use-kanban-in-real-life">How Developers Use Kanban in Real Life</h2>
<p>Here’s how you might interact with a Kanban board on a dev team:</p>
<ol>
<li><p>You pick up a card from “To Do” – let’s say, “Add dark mode toggle.”</p>
</li>
<li><p>You move it to “In Progress.”</p>
</li>
<li><p>When it’s ready for review, you might move it to a temporary “Review” or “Testing” column.</p>
</li>
<li><p>Once it’s merged, tested, and deployed, you move it to “Done.”</p>
</li>
<li><p>You smile, drink some coffee, and grab the next card.</p>
</li>
</ol>
<p>That’s it. But over time, this process helps the whole team:</p>
<ul>
<li><p>Spot bottlenecks</p>
</li>
<li><p>Prevent duplicate work</p>
</li>
<li><p>Reduce context switching</p>
</li>
<li><p>Keep everyone aligned</p>
</li>
</ul>
<h3 id="heading-whats-a-wip-limit-and-why-should-you-care">What’s a WIP Limit — And Why Should You Care?</h3>
<p>WIP = <strong>Work In Progress</strong>. This is the most important concept to keep us in check.</p>
<p>One of Kanban’s key principles is <strong>limiting how many things you’re working on at once</strong>. Because guess what? Multitasking kills momentum.</p>
<p>A typical WIP limit might look like:</p>
<ul>
<li><p>No more than 2–3 cards per person in “In Progress” Again this is best practice, but folks do pick up a lot and then they end up being the bottleneck.</p>
</li>
<li><p>No more than 5 tasks waiting on QA.</p>
</li>
</ul>
<p>Why? Because when everything’s urgent, nothing gets done. WIP limits force you to finish one thing before you start more – and that’s how real velocity happens.</p>
<p>If there are more than 5 tasks in the “To Do” column, the team doesn’t take up new ones. Instead, everyone chips in to see how they can help unclog the bottleneck. A bottleneck is your worst enemy in Kanban, and you want to resolve it so items move smoothly on time and on target.</p>
<p><a target="_blank" href="https://youtu.be/R8dYLbJiTUE?si=Hh00XXI4_1urv4Mp">Here’s a video</a> recapping key concepts.</p>
<h2 id="heading-kanban-vs-scrum-whats-the-difference"><strong>Kanban vs Scrum: What’s the Difference?</strong></h2>
<p>You’ve probably heard Scrum and Kanban mentioned in the same breath – and both are popular Agile frameworks. But they’re not interchangeable.</p>
<p>Scrum is structured, with roles like Product Owner and Scrum Master, and work gets organized into time-boxed sprints. It’s perfect for teams that benefit from rhythm and rituals – like sprint planning, daily standups, and retrospectives.</p>
<p>Kanban, on the other hand, is a little looser. No official roles, no set sprint timelines. Work flows continuously, and change can happen anytime. It’s perfect for teams who need more flexibility and fewer ceremonies.</p>
<p>So how do they compare in practice? Let’s break it down:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Key Differentiating Factors</strong></td><td><strong>Scrum</strong></td><td><strong>Kanban</strong></td></tr>
</thead>
<tbody>
<tr>
<td>Time-based</td><td>Yes – 1–2 week sprints</td><td>No – continuous flow</td></tr>
<tr>
<td>Roles</td><td>PO, SM, Developers</td><td>No specific roles required</td></tr>
<tr>
<td>Planning</td><td>Sprint planning, retros, and so on</td><td>On-demand, just-in-time</td></tr>
<tr>
<td>Cadence</td><td>Fixed sprint cycle</td><td>Flexible, ongoing</td></tr>
<tr>
<td>Use case</td><td>Complex, structured teams</td><td>Continuous delivery teams</td></tr>
</tbody>
</table>
</div><p><strong>Bottom line:</strong></p>
<ul>
<li><p>Scrum is a scheduled loop. Kanban is a living flow.</p>
</li>
<li><p>One’s a playbook. The other’s a status window.</p>
</li>
</ul>
<p><a target="_blank" href="https://youtu.be/F5QIqFEDv2k?si=jvNoAiHmrv_iq-Lx">Here’s a video</a> on the main differences between Scrum and Kanban you can watch if you want more detail.</p>
<h2 id="heading-so-which-one-should-you-use-scrum-or-kanban"><strong>So which one should you use Scrum or Kanban?</strong></h2>
<p>So… which one should you use?</p>
<p>It really depends on your team, your product, and your pain points.</p>
<p>✔️ If you’re working on a brand-new product where requirements shift a lot, and your team thrives with structure and routines – Scrum is likely the better fit. Sprints give you a sense of pacing, and ceremonies help ensure alignment.</p>
<p>✔️ If you’re managing ongoing work like bug triage, tech debt, infrastructure tasks, or anything that’s more “whenever it comes in” than “we need to ship this in two weeks” – Kanban gives you flexibility and visibility without the overhead.</p>
<p>And yes, there’s such a thing as <strong>Scrumban</strong> – a hybrid approach where teams use visual boards and WIP limits from Kanban, but keep some of Scrum’s structure like standups and retros. It’s like Agile tapas: you get the flavors that work best for your appetite.</p>
<p><a target="_blank" href="https://youtu.be/kiI3IweyAeQ?si=M1mtS5HCCcGcT78J">Here is a detailed video</a> that’'ll teach you more about how Scrumban works in practice.</p>
<p>Watch the Scrumban video only when you are familiar and comfortable with both Scrum and Kanban – otherwise, you might get confused from the cross-pollination of ideas and frameworks.</p>
<p>I personally have never seen a Scrumban implementation thats scaled well – too many folks trying too many things and none of them work. But thats just based on my experience – it may work for you and your team. I’ll let you be the judge.</p>
<h2 id="heading-what-tools-do-teams-use-for-kanban"><strong>What Tools Do Teams Use for Kanban?</strong></h2>
<p>You’ve probably seen (or used) one already:</p>
<ul>
<li><p><strong>Trello</strong> – Simple and great for solo or small teams</p>
</li>
<li><p><strong>Jira</strong> – Enterprise-level, customizable workflows</p>
</li>
<li><p><strong>GitHub Projects</strong> – Lightweight but powerful for devs</p>
</li>
<li><p><strong>ClickUp / Asana / Notion</strong> – Integrated with docs/tasks</p>
</li>
</ul>
<p>Kanban isn’t tied to any one tool – you can use an app, a browser tab, or a whiteboard and a pack of sticky notes from the office supply closet. What matters is how you use it. But let’s walk through some of the most common tools and what they offer in a Kanban context:</p>
<h3 id="heading-trello">🟩 <strong>Trello</strong></h3>
<p>Trello is probably the easiest way to start with Kanban. It gives you a simple digital board with columns and cards you can drag and drop. It’s great for devs or small teams who don’t need tons of automation – just a clean place to track work visually.</p>
<h3 id="heading-jira">🟨 <strong>Jira</strong></h3>
<p>Jira is a heavyweight – and while it’s built for Scrum, it also supports robust Kanban boards. You can define custom workflows, use built-in reports like cumulative flow diagrams, enforce WIP limits, and manage team velocity. Ideal for large teams that need traceability, integrations, and permissions.</p>
<h3 id="heading-github-projects">🟦 <strong>GitHub Projects</strong></h3>
<p>If your code lives in GitHub, GitHub Projects is a clean way to stay close to your codebase. It lets you create Kanban-style boards with issues and pull requests as cards, so you’re never toggling between tools just to track what’s in progress.</p>
<h3 id="heading-clickup-asana-notion">🟧 <strong>ClickUp / Asana / Notion</strong></h3>
<p>These are all-in-one productivity platforms. They combine Kanban boards with documentation, team chat, calendars, and reporting. If your team needs more than just “move card left to right,” these tools let you manage projects, meetings, notes, and workflows in one place.</p>
<h3 id="heading-whiteboard-sticky-notes">🟪 <strong>Whiteboard + Sticky Notes</strong></h3>
<p>Don’t underestimate the analog approach. It’s fast. It’s visible. It’s tactile. Physically moving a task from “Doing” to “Done” gives you a sense of progress no digital tool can match. And when something’s blocked? Slap a red sticky on it and call it a day.</p>
<p>Bottom line: The best tool is the one your team will <em>actually</em> use. Fancy doesn’t beat consistent. And the actual tool doesn’t matter as much as the <strong>discipline</strong> your team has to actually use it.</p>
<h2 id="heading-how-to-use-kanban-to-manage-your-own-coding-projects"><strong>How to Use Kanban to Manage Your Own Coding Projects</strong></h2>
<p>Even if you're not on a team yet, Kanban is great for your own workflow. Here’s how you can use it to help yourself out:</p>
<ol>
<li><p>Create a basic 3-column board (To Do, In Progress, Done)</p>
</li>
<li><p>Write out every task, big or small</p>
</li>
<li><p>Set a WIP limit (for example, no more than 2 tasks at once)</p>
</li>
<li><p>Update it daily. Make it a ritual.</p>
</li>
<li><p>Review your flow weekly – What got stuck? What moved fast?</p>
</li>
</ol>
<p> Example:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>To-Do</strong></td><td><strong>In Progress</strong></td><td><strong>Done</strong></td></tr>
</thead>
<tbody>
<tr>
<td>Fix CSS Layout</td><td>Add blog search bar</td><td>Set up Netlify</td></tr>
<tr>
<td>Write README</td><td></td><td>Deploy v1</td></tr>
</tbody>
</table>
</div><p>You’ll be shocked how much clearer your thinking gets when you can <em>see</em> your work. It’s simple but super powerful to visualize your work it in this way.</p>
<h2 id="heading-final-thoughts-why-kanban-isnt-just-a-board"><strong>Final Thoughts: Why Kanban Isn’t Just a Board</strong></h2>
<p>Kanban isn’t just a tool – it’s a mindset.</p>
<p>It helps you focus. It helps your team collaborate. And it gives everyone – even non-technical folks – visibility into what’s going on.</p>
<p>If you’re learning to code and want to feel more confident working with others, <strong>learning Kanban is low-effort, high-impact</strong>.</p>
<p>So don’t wait until your first job. Start using it now – and show up to that standup with confidence.</p>
<p>I hope this small 101 Guide to Kanban was helpful to you all. My sole purpose to write this was to help beginner developers understand Kanban as a practical workflow system – especially for those transitioning from solo coding to collaborative, real-world development environments. It aims to demystify the methodology in a casual, beginner-friendly tone while still offering actionable guidance.</p>
<p>I hope you enjoyed my beginners guide to Kanban.</p>
<p>Until next time, keep Learning, Unlearning and Relearning, folks….</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Constructors in Java: A Beginner's Guide ]]>
                </title>
                <description>
                    <![CDATA[ Java is an object-oriented programming language that is centred around the concept of objects. Objects are like real-world entities that are created with the new keyword and occupy memory. But all this happens in the front-end code – so what about th... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-constructors-in-java-a-beginners-guide/</link>
                <guid isPermaLink="false">686d6044aa83d1a2c46d6160</guid>
                
                    <category>
                        <![CDATA[ Java ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Beginner Developers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ constructors ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ateev Duggal ]]>
                </dc:creator>
                <pubDate>Tue, 08 Jul 2025 18:15:32 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1751998519087/7808c004-c8e5-4e63-b293-10fa479a179f.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Java is an object-oriented programming language that is centred around the concept of objects. Objects are like real-world entities that are created with the new keyword and occupy memory. But all this happens in the front-end code – so what about the back-end? How are objects created and initialised with values?</p>
<p>This is where constructors come into play. Constructors are special types of methods with no return type. They are basically used to initialise the object, to set up its internal state, or to assign default values to its attributes.</p>
<p>In this tutorial, we will go deep into the topic of constructors in Java. You’ll learn how they work and why they are essential in object creation and Java programming. By the end, I hope you’ll understand why they’re one of the core concepts of OOP.</p>
<p>Let’s start…</p>
<h3 id="heading-prerequisites">Prerequisites</h3>
<p>You don’t need to know anything too advanced to start learning about constructors in Java. Just a basic understanding of Java syntax, classes, objects, methods, parameters, arguments, and access modifiers is enough to get started.</p>
<h2 id="heading-what-well-cover">What we’ll cover:</h2>
<ul>
<li><p><a class="post-section-overview" href="#heading-what-are-constructors-in-java">What are Constructors in Java?</a></p>
<ul>
<li><a class="post-section-overview" href="#heading-constructor-syntax">Constructor syntax:</a></li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-types-of-constructors">Types of Constructors</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-default-constructor">Default Constructor</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-no-argument-constructor">No Argument constructor</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-parameterised-constructor">Parameterised Constructor</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-copy-constructor">Copy Constructor</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-what-happens-behind-the-scenes-when-a-constructor-is-called-in-java">What Happens Behind the Scenes When a Constructor Is Called in Java?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-use-the-return-keyword-in-constructors">How to Use the return Keyword in Constructors</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-sample-code">Sample Code:</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-example-4">Example:</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-frequently-asked-questions">Frequently Asked Questions</a></p>
</li>
</ul>
<h2 id="heading-what-are-constructors-in-java"><strong>What are Constructors in Java?</strong></h2>
<p>As mentioned above, constructors are special types of methods that:</p>
<ol>
<li><p>do not have a return type (not even void), </p>
</li>
<li><p>have the same name as the class</p>
</li>
<li><p>are called automatically when an object is created using the new keyword. </p>
</li>
</ol>
<p>A constructor’s main purpose is to initialise a newly created object, to set up its internal state, or to assign default values to its attributes.</p>
<p>Constructors can also be understood as a special block of code which is called when an object is created – either automatically or manually by hard-coding it – with the values we want to initialise the object with.</p>
<p>If we’re okay with the object using default values (like 0 for numbers or null for objects), Java will handle that for us automatically. But if we want to give the object specific values when it's created, we need to write a constructor that takes those values as parameters and uses them to set up the object.</p>
<h3 id="heading-constructor-syntax"><strong>Constructor syntax:</strong></h3>
<pre><code class="lang-java"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ClassName</span> </span>{

    <span class="hljs-comment">// Default constructor with access modifier</span>
    [access_modifier] ClassName(parameters...) {
        <span class="hljs-comment">// constructor body</span>
    }

}
</code></pre>
<h3 id="heading-examples">Examples</h3>
<p><strong>When the constructor is not defined explicitly</strong></p>
<pre><code class="lang-java"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Car</span> </span>{

    String brand;
    <span class="hljs-keyword">int</span> year;

    <span class="hljs-comment">// No constructor is defined, so Java provides a default one</span>
}

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Main</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{

        Car car1 = <span class="hljs-keyword">new</span> Car();  <span class="hljs-comment">// Java calls the default constructor</span>

        <span class="hljs-comment">// Default values: brand = null, year = 0</span>
        System.out.println(<span class="hljs-string">"Brand: "</span> + car1.brand);
        System.out.println(<span class="hljs-string">"Year: "</span> + car1.year);
    }
}
</code></pre>
<p>Output:</p>
<p><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcTW6FYYmq8kB1QL_vSBNqbaVBgo7hLXvqmA3l52HBh9Yvq4AN1aLIAKRqqiOz_tDcCFOTWBVoO1bgjWOD2yyt1nykuobAPQTWRayjqK0jDu2COmPxqI5AaapIyFzDbkrvreV-qyw?key=-LGNq3k7xufJJBHkVFXMZw" alt="output of the code in which there is no constructor" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>In the above code, we have a <strong>Car</strong> class with two variables:</p>
<ol>
<li><p>brand of type <code>String</code></p>
</li>
<li><p>year of type <code>int</code></p>
</li>
</ol>
<p>Since a class is just a blueprint, we need to create an object to actually use it. This is done in the <code>Main</code> class. When we create a Car object using <code>new</code> Car(), Java looks for a constructor. Because we didn’t define one, the compiler automatically provides a default constructor (one with no arguments).</p>
<p>This allows us to create the object and print its variables without any errors. The values printed will be the default ones — <code>null</code> <strong>for the</strong> <code>String</code><strong>, and</strong> <code>0</code> <strong>for the</strong> <code>int</code><strong>.</strong></p>
<p>We'll dive deeper into how this works behind the scenes later, step by step, so it becomes easier to understand.</p>
<p><strong>When we have defined a constructor</strong></p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Car</span> </span>{

    String brand;
    <span class="hljs-keyword">int</span> year;

    <span class="hljs-comment">// Constructor with parameters to initialize custom values</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Car</span><span class="hljs-params">(String brandName, <span class="hljs-keyword">int</span> modelYear)</span> </span>{
        brand = brandName;
        year = modelYear;
    }
}

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Main</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{

        Car car2 = <span class="hljs-keyword">new</span> Car(<span class="hljs-string">"Toyota"</span>, <span class="hljs-number">2022</span>);  <span class="hljs-comment">// Custom values</span>

        System.out.println(<span class="hljs-string">"Brand: "</span> + car2.brand);
        System.out.println(<span class="hljs-string">"Year: "</span> + car2.year);
    }
}
</code></pre>
<p><strong>Output</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1751864448284/2cbb8360-1c6d-42b8-811f-b7603625288d.png" alt="Output of the code which has a constructor." class="image--center mx-auto" width="201" height="156" loading="lazy"></p>
<p>This is the same code as before, with one key difference: this time, we’ve explicitly defined a constructor. Because of this, the output we see isn’t the default values (<code>null</code> for <code>String</code>, <code>0</code> for <code>int</code>), but the custom values we provided.</p>
<p>How does that happen? Simple – we pass values as arguments when creating the object:</p>
<p><code>Car car2 = new Car("Toyota", 2022);</code></p>
<p>These values are received by the constructor as parameters and are then used to initialize the object’s variables. As a result, instead of default values, we get the brand and year we specified.</p>
<h2 id="heading-types-of-constructors"><strong>Types of Constructors</strong></h2>
<p>There are mainly four types of constructors:</p>
<ol>
<li><p>Default Constructors</p>
</li>
<li><p>No-Arguments Constructor</p>
</li>
<li><p>Parameterised Constructor</p>
</li>
<li><p>Copy Constructor</p>
</li>
</ol>
<p><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfafO5dDmX5UA0ADQI5Q8DZSU2H_bVlHjmtKdDpMkmWB4Rhui1kR4w_BP_7-mPz6eb9KdGkVmYxYsZHa4HI044mz3O0CXtXJZBhpJr_wCqWgLO6U0BDUNzm_C9piUHfyXr84xEsoQ?key=-LGNq3k7xufJJBHkVFXMZw" alt="Types of constructors" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<h3 id="heading-default-constructor"><strong>Default Constructor</strong></h3>
<p>A type of no-argument constructor that is added by the compiler during the compilation process so that the values of the object can be initialised. It’s only added by the compiler if you don’t add one explicitly.</p>
<h4 id="heading-syntax"><strong>Syntax:</strong></h4>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">MyClass</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-comment">// Constructor body</span>
    }

}
</code></pre>
<h4 id="heading-example"><strong>Example</strong></h4>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Bike</span> </span>{

    <span class="hljs-comment">// No constructor defined here</span>
    <span class="hljs-comment">// Compiler will automatically add a default constructor</span>

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        Bike myBike = <span class="hljs-keyword">new</span> Bike();  <span class="hljs-comment">// Calls the compiler-provided default constructor</span>
        System.out.println(<span class="hljs-string">"Bike object created!"</span>);
    }

}
</code></pre>
<p>The code becomes the following after the compiler adds a default constructor during the compilation process:</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Bike</span> </span>{

    <span class="hljs-comment">// Compiler-added default constructor</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Bike</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">super</span>();  <span class="hljs-comment">// Calls Object class constructor</span>
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        Bike myBike = <span class="hljs-keyword">new</span> Bike();  <span class="hljs-comment">// Now calls this explicit default constructor</span>
        System.out.println(<span class="hljs-string">"Bike object created!"</span>);
    }

}
</code></pre>
<h4 id="heading-output"><strong>Output</strong></h4>
<p>Bike object created!</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1751867033814/3296a90c-3576-4a57-a863-fe0d1acfafa2.png" alt="Default Constructor" class="image--center mx-auto" width="524" height="287" loading="lazy"></p>
<h3 id="heading-no-argument-constructor"><strong>No Argument constructor</strong></h3>
<p>No-argument constructor is a type of constructor that you explicitly write in your code and that does not contain any parameters.</p>
<p>Now, you may be wondering…Isn't it the same as the default constructor? The answer is both yes and no.</p>
<p>There isn’t much difference between the default constructor and the no-argument constructor, as both do not take any parameters. But there is one key difference.</p>
<p>The default constructor, as we have already discussed, is a type of no-argument constructor that is automatically added by the compiler when it doesn’t find one in our code. In contrast, a no-argument constructor is a type of constructor that we write in our code. </p>
<p>In short, if the compiler is the one that is adding a constructor during the compilation process, it's called a default constructor. But if we are the ones adding the constructor, it’s called a no-argument constructor. </p>
<p>The main difference between a default constructor and a user-defined constructor is <strong>how they are created and what they do</strong>.</p>
<ul>
<li><p>A <strong>default constructor</strong> is automatically added by the compiler <strong>if we don’t add one ourselves</strong>. It doesn’t do much – it just calls the parent class (usually the <code>Object class</code>) and sets all variables to their default values. For example, <code>int</code> becomes <code>0</code>and objects become <code>null</code>.</p>
</li>
<li><p>A <strong>user-defined constructor</strong> is one that <strong>we write ourselves</strong>. We can add custom logic inside it, set custom values to variables, and use access modifiers like <code>public</code>, <code>private</code>, or <code>protected</code>. This means we can decide how the object should be set up when it is created.</p>
</li>
</ul>
<p>Note that even if we don’t write <code>super()</code> in our constructor, Java still adds it automatically unless we call another constructor with <code>this()</code> or call a different <code>super(...)</code> with parameters.</p>
<p>We will understand this deeply in the next section.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Aspect</strong></td><td><strong>Default Constructor</strong></td><td><strong>No-Argument Constructor</strong></td></tr>
</thead>
<tbody>
<tr>
<td><strong>Definition</strong></td><td>A constructor is automatically provided by the compiler when no other constructors exist.</td><td>A constructor explicitly written by the programmer that takes no arguments.</td></tr>
<tr>
<td><strong>Defined By</strong></td><td>Compiler</td><td>Programmer</td></tr>
<tr>
<td><strong>Custom Logic</strong></td><td>Not possible – does only basic, default initialization</td><td>Yes – can contain any initialization logic</td></tr>
<tr>
<td><strong>When Available</strong></td><td>Only if the class has no constructors defined at all</td><td>When explicitly written by the programmer</td></tr>
<tr>
<td><strong>Purpose</strong></td><td>To allow object creation with default initialization</td><td>To allow object creation with programmer-defined behavior</td></tr>
</tbody>
</table>
</div><h4 id="heading-syntax-1"><strong>Syntax:</strong></h4>
<pre><code class="lang-java"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ClassName</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">ClassName</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-comment">// Body (optional)</span>
    }

}
</code></pre>
<h4 id="heading-example-1"><strong>Example</strong></h4>
<p>Let's use the same Bike example we used to explain the default constructor.</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Bike</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Bike</span><span class="hljs-params">()</span> </span>{
        System.out.println(<span class="hljs-string">"Bike object created!"</span>);
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        Bike myBike = <span class="hljs-keyword">new</span> Bike();
    }
}
</code></pre>
<h4 id="heading-output-1"><strong>Output:</strong></h4>
<p>Bike object created!</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1751868234945/565ec06d-7e4d-4415-b983-f517c721d0b9.png" alt="No Argument Construment" class="image--center mx-auto" width="650" height="277" loading="lazy"></p>
<p>In the above code, we have defined a constructor in our code while writing it. This means that it is an example of a no-argument constructor.</p>
<p>We know that both types of constructors are defined without any parameters, but what about the body? We haven’t said anything about it. Let’s see what happens if we write code with a no-argument constructor without a body:</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Bike</span> </span>{

    Bike() {
        <span class="hljs-comment">// No body</span>
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        Bike myBike = <span class="hljs-keyword">new</span> Bike(); <span class="hljs-comment">// Calls the user-defined no-argument constructor</span>
        System.out.println(<span class="hljs-string">"Bike object created!"</span>);
    }
}
</code></pre>
<h4 id="heading-output-2"><strong>Output:</strong></h4>
<p>Bike object created!</p>
<p>The code still gets compiled because the compiler adds the <code>super()</code> keyword during the compilation process, which initialises the object using the object class.</p>
<h3 id="heading-parameterised-constructor"><strong>Parameterised Constructor</strong></h3>
<p>A constructor that accepts parameters is called a parameterised constructor and is only used when we have to initialise an object’s attributes with custom values. </p>
<ul>
<li><p>Parameter refers to the variable listed in the constructor or method definition.</p>
</li>
<li><p>Argument is the actual value passed when calling the constructor or method.</p>
</li>
</ul>
<p>It gives us the flexibility of initiating our object with custom values given at the time of object creation.</p>
<h4 id="heading-syntax-2"><strong>Syntax</strong></h4>
<p>Below is the syntax for a parameterised constructor that takes one parameter:</p>
<pre><code class="lang-java"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ClassName</span> </span>{

    <span class="hljs-comment">// Data members (instance variables)</span>
    DataType variable1;

    <span class="hljs-comment">// Parameterized constructor</span>
    ClassName(DataType param1) {
        variable1 = param1;
    }

    <span class="hljs-comment">// Main method to create objects</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        <span class="hljs-comment">// Creating object using parameterized constructor</span>
        ClassName obj = <span class="hljs-keyword">new</span> ClassName(value1);
    }
}
</code></pre>
<h4 id="heading-example-2"><strong>Example</strong></h4>
<p>We will again use the Bike example for this.</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Bike</span> </span>{

    String modelName;  <span class="hljs-comment">// instance variable</span>

    <span class="hljs-comment">// Parameterized constructor</span>
    Bike(String model) {
        modelName = model;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        <span class="hljs-comment">// Pass parameter while creating the Bike object</span>
        Bike myBike = <span class="hljs-keyword">new</span> Bike(<span class="hljs-string">"Mountain Bike"</span>);
        System.out.println(<span class="hljs-string">"Bike object created! Model: "</span> + myBike.modelName);
    }
}
</code></pre>
<h4 id="heading-output-3">Output:</h4>
<p>Bike object created! Model: Mountain Bike</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1751870395133/72bcbe0c-3a7c-4cc1-87d4-1ae9106b21d9.png" alt="Parameterized Constructor" class="image--center mx-auto" width="706" height="349" loading="lazy"></p>
<p>In this example, we’re working with a Bike class that has an instance variable of String data type called modelName, and a constructor to set the value of that variable.</p>
<p>The constructor takes a parameter called model and assigns it to modelName. So, when we create a new Bike object and pass in the string "Mountain Bike", the constructor stores that value in the modelName variable.</p>
<p>Because of this, when we print out the model name, we see "Mountain Bike" instead of null, which is the default value of the String data type, as now the value of the modelName has been updated.</p>
<h3 id="heading-copy-constructor"><strong>Copy Constructor</strong></h3>
<p>A copy constructor is used to create a new object as a copy of the existing object. Unlike C++, Java doesn’t have a default copy constructor. Instead, we have to create our own by creating a constructor that takes an object of the same class as a parameter and copies its fields.</p>
<h4 id="heading-syntax-3"><strong>Syntax</strong></h4>
<pre><code class="lang-java"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ClassName</span> </span>{

    <span class="hljs-comment">// Fields</span>
    DataType1 field1;
    DataType2 field2;
    <span class="hljs-comment">// ... other fields</span>

    <span class="hljs-comment">// Normal constructor</span>
    ClassName(DataType1 f1, DataType2 f2) {
        field1 = f1;
        field2 = f2;
        <span class="hljs-comment">// ... initialize other fields</span>
    }

    <span class="hljs-comment">// Copy constructor </span>
    ClassName(ClassName other) {
        field1 = other.field1;
        field2 = other.field2;
        <span class="hljs-comment">// ... copy other fields</span>
    }
}
</code></pre>
<h4 id="heading-example-3"><strong>Example</strong></h4>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Bike</span> </span>{

    String modelName;  <span class="hljs-comment">// instance variable</span>

    <span class="hljs-comment">// Parameterized constructor</span>
    Bike(String model) {
        modelName = model;
    }

    <span class="hljs-comment">// Copy constructor</span>
    Bike(Bike otherBike) {
        modelName = otherBike.modelName;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        <span class="hljs-comment">// Create a Bike object using the parameterized constructor</span>
        Bike myBike = <span class="hljs-keyword">new</span> Bike(<span class="hljs-string">"Mountain Bike"</span>);
        System.out.println(<span class="hljs-string">"Bike object created! Model: "</span> + myBike.modelName);

        <span class="hljs-comment">// Create a copy of the existing Bike object using the copy constructor</span>
        Bike copiedBike = <span class="hljs-keyword">new</span> Bike(myBike);
        System.out.println(<span class="hljs-string">"Copied Bike object created! Model: "</span> + copiedBike.modelName);
    }
}
</code></pre>
<h4 id="heading-output-4"><strong>Output:</strong></h4>
<p>Bike object created! Model: Mountain Bike</p>
<p>Copied Bike object created! Model: Mountain Bike</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1751874707838/772bdc8a-75d7-437d-a296-7f472fe5c764.png" alt="Copy Constructor" class="image--center mx-auto" width="435" height="289" loading="lazy"></p>
<p>In the above code, we have created a copy constructor to copy the values of the object (myBike) into a new object (copiedBike), which we have defined in the main class.</p>
<p>But the way the new object is called is a little different. Instead of passing arguments for the constructor, we have passed the original object.</p>
<h4 id="heading-why-copy-constructors"><strong>Why Copy Constructors?</strong></h4>
<p>A copy constructor is used to make a copy of the object, but you can also make a copy using the clone() method or the object.clone() method. So why do we use a copy constructor?</p>
<p>The copy constructor makes a deep copy, while the clone method makes a shallow copy of the object. There are various things that you should know before using cloning techniques, like <a target="_blank" href="https://docs.oracle.com/javase/8/docs/api/java/lang/CloneNotSupportedException.html">CloneNotSupportedException</a><strong>.</strong></p>
<p>On the other hand, copy constructors are clear and easy to understand, and work well with final fields. We can control how the copy happens (deep vs. shallow) and especially when we are dealing with mutable objects.</p>
<h2 id="heading-what-happens-behind-the-scenes-when-a-constructor-is-called-in-java"><strong>What Happens Behind the Scenes When a Constructor Is Called in Java?</strong></h2>
<p>So, just to recap: when we create an object using the <code>new</code> keyword, a constructor is automatically called. If we haven't defined any constructors in our class, Java automatically defines a constructor for us. </p>
<p>But while writing and running our code, we mostly focus on what’s visible in our editor, as in what we can see. Let’s dive a little deeper and explore what happens behind the scenes – at the compiler and JVM level – when an object is created and executed.</p>
<ul>
<li><p><strong>Step 1: Memory Allocation</strong> – When we create an object using a new keyword, Java allocates memory for that object in the heap. This memory is where the object’s fields (also called attributes) will be placed.</p>
</li>
<li><p><strong>Step 2: Reference Creation</strong> – A reference to this object is stored on the stack, which lets our program interact with the object that lives in the heap.</p>
</li>
<li><p><strong>Step 3: Constructor Creation</strong> – Java then determines which constructor to call. If no constructor is explicitly defined in our class, the compiler automatically inserts a constructor with no parameters.</p>
</li>
<li><p><strong>Step 4: Superclass Constructor Call</strong> – Before executing the constructor’s body, Java first calls the constructor of the superclass using the <code>super()</code> keyword. This ensures that the fields inherited from the parent class are properly initialised. If you don’t explicitly write <code>super()</code>, the compiler adds it automatically in the first line of the code, but only if the superclass has a no-argument constructor, unless we're already calling another constructor via <code>this()</code>.</p>
</li>
</ul>
<p>But don’t use both the <code>super()</code> and <code>this()</code> keywords in the same constructor (you can use them in separate constructors.</p>
<p>Let’s say that it doesn’t have a super class – then what? </p>
<p>The answer is simple: Java has an in-built Object class that has a no-argument constructor by default.  This is why our classes run smoothly even if we don’t write super() ourselves, as Java calls it in the background. </p>
<p>That means every class we create is a subclass of the object class:</p>
<h4 id="heading-attribute-initialisation">Attribute Initialisation:</h4>
<p>At this point, fields get initialised:</p>
<ul>
<li><p>First, with default values (for example, 0 for int, null for objects),</p>
</li>
<li><p>Then, with any explicit initialisations we've written (for example, int x = 10), the default values will get replaced by them.</p>
</li>
</ul>
<h4 id="heading-constructor-execution">Constructor Execution:</h4>
<p>And finally, the logic runs. This is where all or some of the attributes defined in the class for object creation are initialised by the parameters used during object creation, with the help of constructors. </p>
<p>But not every field may get initialised. Fields that are not updated by the constructor will keep the values they already have (either the default value or the explicitly initialised values). </p>
<p>In short, the constructor gives us the flexibility to customise our object at the time of creation, but it doesn't automatically set every field unless we explicitly write the logic for it.</p>
<p>Check the code below to understand better:</p>
<pre><code class="lang-java"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Example</span> </span>{

    <span class="hljs-keyword">int</span> a;           <span class="hljs-comment">// default 0</span>
    <span class="hljs-keyword">int</span> b = <span class="hljs-number">10</span>;      <span class="hljs-comment">// explicitly initialized to 10</span>
    String name;     <span class="hljs-comment">// default null</span>

    Example(<span class="hljs-keyword">int</span> x) {
        a = x;       <span class="hljs-comment">// only 'a' is set through constructor</span>
        <span class="hljs-comment">// 'b' is not changed, stays 10</span>
        <span class="hljs-comment">// 'name' is not changed, stays null</span>
    }

    <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">display</span><span class="hljs-params">()</span> </span>{
        System.out.println(<span class="hljs-string">"a = "</span> + a);
        System.out.println(<span class="hljs-string">"b = "</span> + b);
        System.out.println(<span class="hljs-string">"name = "</span> + name);
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        Example obj = <span class="hljs-keyword">new</span> Example(<span class="hljs-number">5</span>);
        obj.display();
    }
}
</code></pre>
<p><strong>Output:</strong></p>
<p><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfRr6j8-QeGffPm7DYMImJL5s9X-apEGhLzXAv_cNw2CcwONejKxd4-_xKbmdKGSW1w09lt3Pib_psv7RLkd5LJ1uUxd9LSU2KOcDU9kYeqjYbZWS-qUN1PuLbNV8uF0M373kl7Cw?key=-LGNq3k7xufJJBHkVFXMZw" alt="Output of the code explaining how constructor work." class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>In the above example, we have three data members – a, b, and name. We have already done the declaration and initialisation of the variable b at the beginning and given a value to a at the time of object creation.</p>
<p>So we can see that:</p>
<ol>
<li><p>‘<strong>a</strong>’, whose value has been updated by the constructor with the value given at the time of object creation, has the same value</p>
</li>
<li><p><strong>‘b’,</strong> which already had a value and does not get updated by the constructor, prints the same value </p>
</li>
<li><p>the string <strong>‘name’</strong> didn’t have a value, so null was printed instead, as it is the default value of the String data type.</p>
</li>
</ol>
<h2 id="heading-how-to-use-the-return-keyword-in-constructors"><strong>How to Use the</strong> <code>return</code> <strong>Keyword in Constructors</strong></h2>
<p>We know that constructors are defined without a return type, but we can use the return keyword in the constructor only to exit the constructor early, not to return a value. Check out the code below.</p>
<h3 id="heading-sample-code"><strong>Sample Code:</strong></h3>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Bike</span> </span>{

    String modelName;  <span class="hljs-comment">// instance variable</span>
    <span class="hljs-keyword">int</span> speed;

    <span class="hljs-comment">// Parameterized constructor</span>
    Bike(String model, <span class="hljs-keyword">int</span> sp) {
        modelName = model;
        <span class="hljs-keyword">return</span>;
        speed = sp;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        <span class="hljs-comment">// Pass parameter while creating the Bike object</span>
        Bike myBike = <span class="hljs-keyword">new</span> Bike(<span class="hljs-string">"Mountain Bike"</span>, <span class="hljs-number">20</span>);
        System.out.println(<span class="hljs-string">"Bike object created! Model: "</span> + myBike.modelName);
        System.out.println(<span class="hljs-string">"Speed of the Bike is "</span> + myBike.speed);
    }
}
</code></pre>
<p>Let’s try to understand the above code and the use of the return keyword along with it. We will start with what would happen if the return keyword wasn’t here. The code would have executed without any errors and would have received an output.</p>
<p><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdRpxqN-7mjbNNenChHDcIxtufG5P4LQOG1GXo4L7_kFz955k-YF2HJfy96ZoIbPtxy3flUKiw4Mq6C8qSdZEnw3bzg5rbAy3BR4Q4x7uO2EjZfN7zFGDRlCWbAth_s97TGvoHpCQ?key=-LGNq3k7xufJJBHkVFXMZw" alt="code without the return keyword" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>Now, what will happen if we add the return keyword? As we have discussed above, the return keyword will tell the compiler not to go beyond this point in the constructor. </p>
<p>So whatever we have written in the constructor after the return keyword will not be compiled, and if that had any value and was necessary for the proper execution of our code, the compiler will throw an error.</p>
<p><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXc63VgyWkEdvcPr8x9TkVb-ZJKuPO2Z-ips_sNT70zGwFYRRdzfYYWG1Bfwnjmdypz-Pt8YS6SwQGBKMNrNhz4J27psGuOxz9Fs0gLVpM0oHzn5N1J0w3wgL7HU7rUQlB200qoRoA?key=-LGNq3k7xufJJBHkVFXMZw" alt="code with the return keyword" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>The error says it clearly ‘unreachable statement’, which means that the compiler was not allowed to go beyond the return keyword. </p>
<p>Now that you understand the return keyword, let’s see when you can use it.</p>
<h3 id="heading-example-4"><strong>Example:</strong></h3>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Bike</span> </span>{

    <span class="hljs-comment">// Constructor with a condition to exit early</span>
    Bike(<span class="hljs-keyword">boolean</span> skip) {
        <span class="hljs-keyword">if</span> (skip) {
            System.out.println(<span class="hljs-string">"Constructor exited early"</span>);
            <span class="hljs-keyword">return</span>; <span class="hljs-comment">// Ends constructor execution here</span>
        }

        System.out.println(<span class="hljs-string">"Constructor continues..."</span>);
        <span class="hljs-comment">// More initialization logic can go here</span>
        System.out.println(<span class="hljs-string">"Bike object initialized successfully"</span>);
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        System.out.println(<span class="hljs-string">"Creating first bike (skip = true):"</span>);
        Bike bike1 = <span class="hljs-keyword">new</span> Bike(<span class="hljs-keyword">true</span>);  <span class="hljs-comment">// Constructor will exit early</span>

        System.out.println(<span class="hljs-string">"\nCreating second bike (skip = false):"</span>);
        Bike bike2 = <span class="hljs-keyword">new</span> Bike(<span class="hljs-keyword">false</span>); <span class="hljs-comment">// Constructor will continue</span>
    }
}
</code></pre>
<p>We’ve defined a Bike class that has a constructor with one boolean parameter called skip. Inside the constructor, there's an if statement that checks if skip is true. If it is, the constructor prints a message and uses the return keyword to exit early. This means the rest of the constructor won’t run.</p>
<p>But there is no else block. So what happens when skip is false? In that case, the if condition is not true, then the code inside the if statement is not executed (including the return keyword) and the constructor simply continues to the next lines of code. That’s where we do the actual bike initialisation and print a success message.</p>
<p>In short:</p>
<ol>
<li><p>If skip is true, the constructor exits early.</p>
</li>
<li><p>If skip is false, the constructor continues and finishes the setup.</p>
</li>
</ol>
<p><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeK-1kbbG97wMT_d-zrZ28eCuVsWZEkH6Ve3kuYSyXM1e-pZDsJl8K1S4GVfp54XnxGLOGGH_y_B3lZvmy1GRSvOY5Xp_rqHZd7jdNHHxdVAdVuW5vM__6DU99SdS38b03jXjkj?key=-LGNq3k7xufJJBHkVFXMZw" alt="output of the example explaining return keyword" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>This is a simple way to control how much of the constructor runs, based on a condition.</p>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>In this blog, we have understood many different topics, what a constructor is, its different types, like default constructor, no argument constructor, parameterised constructor and copy constructor, not only with theory but with code examples as well.</p>
<p>Understanding them will not only enhance our understanding but also help us write modular and well-maintained code in Java. While this concept is also important in OOP, as it is centred around the concept of objects and constructors are the ones that are used to initialise them.</p>
<h2 id="heading-frequently-asked-questions"><strong>Frequently Asked Questions</strong></h2>
<p><strong>Q1. Why do we use constructors?</strong></p>
<p><strong>A:</strong> We use constructors because:</p>
<ol>
<li><p>They are created automatically by the compiler and initialise the object with default values.</p>
</li>
<li><p>We can initialise all the attributes of the objects in one go.</p>
</li>
<li><p>They prevent incomplete or incorrect object initialisation by ensuring that important data is provided during object creation.</p>
</li>
<li><p>Code maintainability and modularity increase.</p>
</li>
<li><p>We can use objects as soon as they are created.</p>
</li>
</ol>
<p><strong>Q2. What is the basic difference between Method Overloading and Constructor Overloading?</strong></p>
<p><strong>A:</strong> </p>
<table><tbody><tr><td><p><strong>Feature</strong></p></td><td><p><strong>Method Overloading</strong></p></td><td><p><strong>Constructor Overloading</strong></p></td></tr><tr><td><p><strong>Purpose</strong></p></td><td><p>To perform different operations with the same method name</p></td><td><p>To create objects with different initialisations</p></td></tr><tr><td><p><strong>Return Type</strong></p></td><td><p>Can have a return type</p></td><td><p>Has no return type</p></td></tr><tr><td><p><strong>Name</strong></p></td><td><p>Can be any valid method name</p></td><td><p>Always has the same name as the class</p></td></tr><tr><td><p><strong>Usage Context</strong></p></td><td><p>Called on existing objects</p></td><td><p>Called when creating objects</p></td></tr></tbody></table>

<p>You can check out some of my other beginner-friendly articles on my blog:</p>
<ol>
<li><p><a target="_blank" href="https://tekolio.com/what-is-abstraction-in-java-and-how-to-achieve-it/">Understanding abstraction in Java</a></p>
</li>
<li><p><a target="_blank" href="https://tekolio.com/how-to-build-a-movie-app-in-react-using-tmdb-api/">How to build a Movie App in React using TMDB API?</a></p>
</li>
<li><p><a target="_blank" href="https://tekolio.com/how-to-merge-two-sorted-arrays/">How to merge two sorted arrays</a></p>
</li>
</ol>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ An Animated Introduction to Programming with Python ]]>
                </title>
                <description>
                    <![CDATA[ Python is a high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python is known for its design philosophy that emphasizes code readability, notably using significant indentation. It supports multi... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/an-animated-introduction-to-programming-with-python/</link>
                <guid isPermaLink="false">685052f79796239b8044baeb</guid>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Beginner Developers ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Mark Mahoney ]]>
                </dc:creator>
                <pubDate>Mon, 16 Jun 2025 17:23:03 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1750082209046/ed07548b-e859-47a0-8372-6e9b04cb51bc.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p><a target="_blank" href="https://www.python.org/downloads/">Python</a> is a high-level, general-purpose programming language. Created by <a target="_blank" href="https://en.wikipedia.org/wiki/Guido_van_Rossum">Guido van Rossum</a> and first released in 1991, Python is known for its design philosophy that emphasizes code readability, notably using significant indentation. It supports multiple programming paradigms, including object-oriented, imperative, and functional programming.</p>
<p>Python's popularity stems from its versatility and ease of use, making it an excellent choice for a broad range of applications. Its extensive standard library provides tools for numerous tasks, from web development and data analysis to artificial intelligence and scientific computing.</p>
<p>The language's clear syntax and active, supportive community also contribute to its widespread adoption among both beginners and experienced developers.</p>
<p>Python is employed across a wide array of domains, including:</p>
<ul>
<li><p>Data Analysis and Visualization: Processing, analyzing, and visualizing large datasets using libraries such as Pandas, NumPy, and Matplotlib.</p>
</li>
<li><p>Artificial Intelligence and Machine Learning: Developing AI models, machine learning algorithms, and deep learning applications with frameworks like TensorFlow and PyTorch.</p>
</li>
<li><p>Scientific and Numeric Computing: Performing complex calculations and simulations in fields like physics, engineering, and mathematics.</p>
</li>
<li><p>Web Development: Building server-side web applications with frameworks like Django and Flask.</p>
</li>
<li><p>Automation and Scripting: Automating repetitive tasks, system administration, and network configuration.</p>
</li>
<li><p>Software Testing and Quality Assurance: Writing scripts for automated testing.</p>
</li>
<li><p>Education: Widely used as a first language for teaching programming concepts due to its simplicity and readability.</p>
</li>
</ul>
<h2 id="heading-an-animated-introduction-to-programming-with-python"><strong>An Animated Introduction to Programming with Python</strong></h2>
<p>To make learning about Python programming more accessible, I developed an interactive tutorial called "An Animated Introduction to Programming with Python." This resource utilizes annotated code playbacks to demonstrate key language features step-by-step. From fundamental syntax to media manipulation, each concept is presented through executable code and accompanying visual explanations.</p>
<p>You can access the free 'book' of code playbacks here: <a target="_blank" href="https://playbackpress.com/books/pybook">https://playbackpress.com/books/pybook</a>.</p>
<p>For more information about code playbacks, you can watch a short demo.</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/uYbHqCNjVDM" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p> </p>
<h2 id="heading-a-focus-on-media-computation-with-jes"><strong>A Focus on Media Computation with JES</strong></h2>
<p>A portion of this book utilizes Mark Guzdial's pioneering "Media Computation" approach, which teaches programming concepts through the manipulation of digital media (images, sounds, and videos). Some of the examples in the book use the <a target="_blank" href="https://github.com/gatech-csl/jes">Jython Environment for Students</a> (JES).</p>
<h3 id="heading-a-note-on-jes"><strong>A Note on JES:</strong></h3>
<p>JES was developed at Georgia Tech and has been a highly effective pedagogical tool for many years. The main idea is to manipulate pixels in images for understanding fundamental programming concepts like iteration, conditionals, and functions in a visual and tangible way.</p>
<p>Even if JES isn't as widely used today, the lessons learned from manipulating pixels transfers to almost all other areas of computing. In other words, even if you don’t use JES it is still worth going through the playbacks marked with <em>JES.</em>**</p>
<h2 id="heading-table-of-contents"><strong>Table of Contents</strong></h2>
<ol>
<li><p>Flow of Control and Simple Data</p>
<ol>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/1/1">Printing and flow</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/1/2">Arithmetic and comparing numbers</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/1/3">Programming with Data</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/1/4">Distance Between Two Points</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/1/5">More with Strings</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/1/6"><strong>JES:</strong> Prompting the User for Some Information</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/1/7"><strong>JES:</strong> Showing a Picture</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/1/8"><strong>JES:</strong> Accessing Pixels</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/1/9"><strong>JES:</strong> Adding a Caption to a Picture</a></p>
</li>
</ol>
</li>
<li><p>Iterating Over Data</p>
<ol>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/2/1">Iterating Through a String</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/2/2">Lists and Iteration</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/2/3">Splitting Strings</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/2/4">Ranges</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/2/5">Reading from a File</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/2/6">Writing to a File</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/2/7"><strong>JES:</strong> Iterating Through Pixels</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/2/8"><strong>JES:</strong> Graying an Image</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/2/9"><strong>JES:</strong> Copying an Image</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/2/10"><strong>JES:</strong> Enlarging a Picture</a></p>
</li>
</ol>
</li>
<li><p>Conditions with if and while</p>
<ol>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/3/1">Comparisons by the Computer</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/3/2">if, if/else, and if/else if/else Statements</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/3/3">Logical Operators</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/3/4">Loops</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/3/5"><strong>JES:</strong> Adding a Border to a Picture</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/3/6"><strong>JES:</strong> Finding the Predominant Color in a Row</a></p>
</li>
</ol>
</li>
<li><p>Data Containers</p>
<ol>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/4/1">Python Lists</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/4/2">Python Dictionaries</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/4/3">Python Sets</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/4/4"><strong>JES:</strong> Storing User Supplied Data in a Dictionary</a></p>
</li>
</ol>
</li>
<li><p>Functions</p>
<ol>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/5/1">A First Function</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/5/2">Function Return Values</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/5/3">Parameters</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/5/4">Scope of Variables</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/5/5">Pass by Reference or Pass by Value</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/5/6">Sorting with Functions</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/5/7"><strong>JES:</strong> Adding Text (Again) and Saving a File Using Functions</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/5/8"><strong>JES:</strong> Shrinking a Picture</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/5/9"><strong>JES:</strong> Making a Movie with Moving Text</a></p>
</li>
</ol>
</li>
<li><p>Classes</p>
<ol>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/6/1">Classes</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/6/2">Class with Data and Methods</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/6/3">Classes that Interact with Each Other</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/6/4">Inheritance</a></p>
</li>
<li><p><a target="_blank" href="https://playbackpress.com/books/pybook/chapter/6/5"><strong>JES:</strong> Photo Resizing/Rotating Class</a></p>
</li>
</ol>
</li>
</ol>
<p>I hope this animated introduction helps you grasp the fundamental concepts of Python and empowers you to start building your own applications. Dive in, experiment, and let me know what you think! If you have any questions or feedback, I'd love to hear it. Comments and feedback are welcome anytime: <a target="_blank" href="mailto:mark@playbackpress.com">mark@playbackpress.com</a></p>
<p>If you'd like to support my work and help keep Playback Press free for all, consider donating using <a target="_blank" href="https://github.com/sponsors/markm208">GitHub Sponsors</a>. I use all of the donations for hosting costs. Your support helps me continue creating educational content like this. Thank you!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The Open Source LLM Agent Handbook: How to Automate Complex Tasks with LangGraph and CrewAI ]]>
                </title>
                <description>
                    <![CDATA[ Ever feel like your AI tools are a bit...well, passive? Like they just sit there, waiting for your next command? Imagine if they could take initiative, break down big problems, and even work together to get things done. That's exactly what LLM agents... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/the-open-source-llm-agent-handbook/</link>
                <guid isPermaLink="false">683f04aedfb685791a4e8dd2</guid>
                
                    <category>
                        <![CDATA[ llm ]]>
                    </category>
                
                    <category>
                        <![CDATA[ openai ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Open Source ]]>
                    </category>
                
                    <category>
                        <![CDATA[ agentic AI ]]>
                    </category>
                
                    <category>
                        <![CDATA[ #agent ]]>
                    </category>
                
                    <category>
                        <![CDATA[ agents ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Bash ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Beginner Developers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ AI ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Balajee Asish Brahmandam ]]>
                </dc:creator>
                <pubDate>Tue, 03 Jun 2025 14:20:30 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1748956366197/c4dd2bba-430a-4f12-a3d4-becc6707c52e.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Ever feel like your AI tools are a bit...well, passive? Like they just sit there, waiting for your next command? Imagine if they could take initiative, break down big problems, and even work together to get things done.</p>
<p>That's exactly what LLM agents bring to the table. They're changing how we automate complex tasks, and they can help bring our AI ideas to life in a whole new way.</p>
<p>In this article, we'll explore what LLM agents are, how they work, and how you can build your very own using awesome open-source frameworks.</p>
<h3 id="heading-what-well-cover">What we’ll cover:</h3>
<ol>
<li><p><a class="post-section-overview" href="#heading-the-current-state-of-llm-agents">The Current State of LLM Agents</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-from-chatbots-to-autonomous-agents">From Chatbots to Autonomous Agents</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-can-agents-do-today">What Can Agents Do Today?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-whats-available-to-build-with">What's Available to Build With?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-why-now-is-the-best-time-to-learn">Why Now Is the Best Time to Learn</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-what-are-llm-agents-and-why-are-they-a-big-deal">What Are LLM Agents and Why Are They a Big Deal?</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-what-is-an-llm">What Is an LLM?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-so-whats-an-llm-agent">So, What’s an LLM Agent?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-why-does-this-matter">Why Does This Matter?</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-the-rise-of-open-source-agent-frameworks">The Rise of Open-Source Agent Frameworks</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-popular-open-source-agent-frameworks">Popular Open-Source Agent Frameworks</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-these-tools-enable">What These Tools Enable</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-why-use-a-framework-instead-of-building-from-scratch">Why Use a Framework Instead of Building from Scratch?</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-core-concepts-behind-agent-design">Core Concepts Behind Agent Design</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-the-agent-loop">The Agent Loop</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-key-components-of-an-agent">Key Components of an Agent</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-multi-agent-collaboration">Multi-Agent Collaboration</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-project-automate-your-daily-schedule-from-emails">Project: Automate Your Daily Schedule from Emails</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-what-were-automating">What We’re Automating</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-step-1-install-the-required-tools">Step 1: Install the Required Tools</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-step-2-define-the-task">Step 2: Define the Task</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-step-3-build-the-workflow-with-langgraph">Step 3: Build the Workflow with LangGraph</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-multi-agent-collaboration-with-crewai">Multi-Agent Collaboration with CrewAI</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-what-is-crewai">What Is CrewAI?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-sample-roles-for-the-email-summary-task">Sample Roles for the Email Summary Task</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-sample-crewai-code">Sample CrewAI Code</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-what-actually-happens-during-execution">What Actually Happens During Execution?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-are-llm-agents-safe-what-to-know-about-security-and-privacy">Are LLM Agents Safe? What to Know About Security and Privacy</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-troubleshooting-and-tips">Troubleshooting &amp; Tips</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-explore-more-daily-automations">Explore More Daily Automations</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-whats-next-in-agent-technology">What’s Next in Agent Technology?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-final-summary">Final Summary</a></p>
</li>
</ol>
<h2 id="heading-the-current-state-of-llm-agents">The Current State of LLM Agents</h2>
<p>LLM agents are one of the most exciting developments in AI right now. They’re already helping automate real tasks but they’re also still evolving. So where are we today?</p>
<h3 id="heading-from-chatbots-to-autonomous-agents">From Chatbots to Autonomous Agents</h3>
<p>Large Language Models (LLMs) like GPT-4, Claude, Gemini, and LLaMA have evolved from simple chatbots into surprisingly capable reasoning engines. They've gone from answering trivia questions and generating essays to performing complex reasoning, following multi-step instructions, and interacting with tools like web search and code interpreters.</p>
<p>But here’s the catch: these models are <strong>reactive</strong>. They wait for input and give output. They don't retain memory between tasks, plan ahead, or pursue goals on their own. That’s where <strong>LLM agents</strong> come in – they bridge this gap by adding structure, memory, and autonomy.</p>
<h3 id="heading-what-can-agents-do-today">What Can Agents Do Today?</h3>
<p>Right now, LLM agents are already being used for:</p>
<ul>
<li><p>Summarizing emails or documents</p>
</li>
<li><p>Planning daily schedules</p>
</li>
<li><p>Running DevOps scripts</p>
</li>
<li><p>Searching APIs or tools for answers</p>
</li>
<li><p>Collaborating in small “teams” to complete complex tasks</p>
</li>
</ul>
<p>But they’re not perfect yet. Agents can still:</p>
<ul>
<li><p>Get stuck in loops</p>
</li>
<li><p>Misunderstand goals</p>
</li>
<li><p>Require detailed prompts and guardrails</p>
</li>
</ul>
<p>That’s because this technology is still early-stage. Frameworks are getting better fast, but reliability and memory are still works in progress. So just keep that in mind as you experiment.</p>
<h3 id="heading-why-now-is-the-best-time-to-learn">Why Now Is the Best Time to Learn</h3>
<p>The truth is: we’re still early. But not <em>too</em> early.</p>
<p>This is the perfect time to start experimenting with agents:</p>
<ul>
<li><p>The tooling is mature enough to build real projects</p>
</li>
<li><p>The community is growing rapidly</p>
</li>
<li><p>And you don’t need to be an AI expert just comfortable with Python</p>
</li>
</ul>
<h2 id="heading-what-are-llm-agents-and-why-are-they-a-big-deal">What Are LLM Agents and Why Are They a Big Deal?</h2>
<p>Before we dive into the exciting world of agents, let's quickly chat a bit more about the basics.</p>
<h3 id="heading-what-is-an-llm">What Is an LLM?</h3>
<p>An LLM, or Large Language Model, is basically an AI that's learned from a massive amount of text from the internet – think books, articles, code, and tons more. You can picture it as a super-smart autocomplete engine. But it does way more than just finish your sentences. It can also:</p>
<ul>
<li><p>Answer tricky questions</p>
</li>
<li><p>Summarize long articles or documents</p>
</li>
<li><p>Write code, emails, or creative stories</p>
</li>
<li><p>Translate languages instantly</p>
</li>
<li><p>Even solve logic puzzles and have engaging conversations</p>
</li>
</ul>
<p>Chances are you've heard of ChatGPT, which is powered by OpenAI's GPT models. Other popular LLMs you might come across include Claude (from Anthropic), LLaMA (by Meta), Mistral, and Gemini (from Google).</p>
<p>These models work by simply predicting the next word in a sentence based on the context. While that sounds straightforward, when trained on billions of words, LLMs become capable of surprisingly intelligent behavior, understanding your instructions, following step-by-step reasoning, and producing coherent responses across almost any topic you can imagine.</p>
<h3 id="heading-so-whats-an-llm-agent">So, What’s an LLM Agent?</h3>
<p>While LLMs are super powerful, they usually just <em>react –</em> they only respond when you ask them something. An LLM agent, on the other hand, is <em>proactive</em>.</p>
<p>LLM agents can:</p>
<ul>
<li><p>Break down big, complex tasks into smaller, manageable steps</p>
</li>
<li><p>Make smart decisions and figure out what to do next</p>
</li>
<li><p>Use "tools" like web search, calculators, or even other apps</p>
</li>
<li><p>Work towards a goal, even if it takes multiple steps or tries</p>
</li>
<li><p>Team up with other agents to accomplish shared objectives</p>
</li>
</ul>
<p>In short, LLM agents can think, plan, act, and adapt.</p>
<p>Think of an LLM agent like your super-efficient new assistant: you give it a goal, and it figures out how to achieve it all on its own.</p>
<h3 id="heading-why-does-this-matter">Why Does This Matter?</h3>
<p>This shift from just responding to actively pursuing goals opens a ton of exciting possibilities:</p>
<ul>
<li><p>Automating boring IT or DevOps tasks</p>
</li>
<li><p>Generating detailed reports from raw data</p>
</li>
<li><p>Helping you with multi-step research projects</p>
</li>
<li><p>Reading through your daily emails and highlighting key info</p>
</li>
<li><p>Running your internal tools to take real-world actions</p>
</li>
</ul>
<p>Unlike older, rule-based bots, LLM agents can reason, reflect, and learn from their attempts. This makes them a much better fit for real-world tasks that are messy, require flexibility, and depend on understanding context.</p>
<h2 id="heading-the-rise-of-open-source-agent-frameworks">The Rise of Open-Source Agent Frameworks</h2>
<p>Not too long ago, if you wanted to build an AI system that could act autonomously, it meant writing a ton of custom code, painstakingly managing memory, and trying to stitch together dozens of components. It was a complex, delicate, and highly specialized job.</p>
<p>But guess what? That's not the case anymore.</p>
<p>In 2024, a wave of fantastic open-source frameworks hit the scene. These tools have made it dramatically easier to build powerful LLM agents without you having to reinvent the wheel every time.</p>
<h3 id="heading-popular-open-source-agent-frameworks">Popular Open-Source Agent Frameworks</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Framework</strong></td><td><strong>Description</strong></td><td><strong>Maintainer</strong></td></tr>
</thead>
<tbody>
<tr>
<td>LangGraph</td><td>Graph-based framework for agent state and memory</td><td>LangChain</td></tr>
<tr>
<td>CrewAI</td><td>"Role-based, multi-agent collaboration engine"</td><td>Community (CrewAI)</td></tr>
<tr>
<td>AutoGen</td><td>Customizable multi-agent chat orchestration</td><td>Microsoft</td></tr>
<tr>
<td>AgentVerse</td><td>Modular framework for agent simulation and testing</td><td>Open-source project</td></tr>
</tbody>
</table>
</div><h3 id="heading-what-these-tools-enable">What These Tools Enable</h3>
<p>These frameworks give you ready-made building blocks to handle the trickier parts of creating agents:</p>
<ul>
<li><p><strong>Planning</strong> – Letting agents decide their next move</p>
</li>
<li><p><strong>Tool Use</strong> – Easily connecting agents to things like file systems, web browsers, APIs, or databases</p>
</li>
<li><p><strong>Memory</strong> – Storing and retrieving past information or intermediate results for long-term context</p>
</li>
<li><p><strong>Multi-Agent Collaboration</strong> – Setting up teams of agents that work together on shared goals</p>
</li>
</ul>
<h3 id="heading-why-use-a-framework-instead-of-building-from-scratch">Why Use a Framework Instead of Building from Scratch?</h3>
<p>While you <em>could</em> build a custom agent from the ground up, using a framework will save you a huge amount of time and effort. Open-source agent libraries come packed with:</p>
<ul>
<li><p>Built-in support for orchestrating LLMs</p>
</li>
<li><p>Proven patterns for task planning, keeping track of where you are, and getting feedback</p>
</li>
<li><p>Easy integration with popular models like OpenAI, or even models you run locally</p>
</li>
<li><p>The flexibility to grow from a single helpful agent to entire teams of agents</p>
</li>
</ul>
<p>Basically, these frameworks let you focus on <strong>what your agent should do</strong>, rather than getting bogged down in how to build all the internal workings. Plus, choosing open source means you benefit from community contributions, transparency in how they work, and the freedom to tweak them to your exact needs, without getting locked into a single vendor.</p>
<h2 id="heading-core-concepts-behind-agent-design">Core Concepts Behind Agent Design</h2>
<p>To really grasp how LLM agents operate, it helps to think of them as goal-driven systems that constantly cycle through observing, reasoning, and acting. This continuous loop allows them to tackle tasks that go beyond simple questions and answers, moving into true automation, tool usage, and adapting on the fly.</p>
<h3 id="heading-the-agent-loop">The Agent Loop</h3>
<p>Most LLM agents function based on a mental model called the <strong>Agent Loop</strong> a step-by-step cycle that repeats until the job is done. Here’s how it typically works:</p>
<ul>
<li><p><strong>Perceive:</strong> The agent starts by noticing something in its environment or receiving new information. This could be your prompt, a piece of data, or the current state of a system.</p>
</li>
<li><p><strong>Plan:</strong> Based on what it perceives and its overall goal, the agent decides what to do next. It might break the task into smaller sub-goals or figure out the best tool for the job.</p>
</li>
<li><p><strong>Act:</strong> The agent then acts. This could mean running a function, calling an API, searching the web, interacting with a database, or even asking another agent for help.</p>
</li>
<li><p><strong>Reflect:</strong> After acting, the agent looks at the outcome: Did it work? Was the result useful? Should it try a different approach? Based on this, it updates its plan and keeps going until the task is complete.</p>
</li>
</ul>
<p>This loop is what makes agents so dynamic. It allows them to handle ever-changing tasks, learn from partial results, and correct their course qualities that are vital for building truly useful AI assistants.</p>
<h3 id="heading-key-components-of-an-agent">Key Components of an Agent</h3>
<p>To do their job effectively, agents are built around several crucial parts:</p>
<ul>
<li><p><strong>Tools</strong> are how an agent interacts with the real (or digital) world. These can be anything from search engines, code execution environments, file readers, or API clients, to simple calculators or command-line scripts.</p>
</li>
<li><p><strong>Memory</strong> lets agents remember what they've done or seen across different steps. This might include previous things you've said, temporary results, or key decisions. Some frameworks offer short-term memory (just for one session), while others support long-term memory that can span multiple sessions or goals.</p>
</li>
<li><p><strong>Environment</strong> refers to the external data or system context the agent operates within think APIs, documents, databases, files, or sensor inputs. The more information and access an agent have to its environment, the more meaningful actions it can take.</p>
</li>
<li><p><strong>Goal</strong> is the agent's ultimate objective: what it's trying to achieve. Goals should be specific and clear for instance, “generate a daily schedule,” “summarize this document,” or “extract tasks from emails.”</p>
</li>
</ul>
<h3 id="heading-multi-agent-collaboration">Multi-Agent Collaboration</h3>
<p>For more advanced systems, you can even have multiple agents working together to hit a shared target. Each agent can be given a specific <strong>role</strong> that highlights its specialty just like people working on a team.</p>
<p>For example:</p>
<ul>
<li><p>A <strong>researcher agent</strong> might be tasked with gathering information.</p>
</li>
<li><p>A <strong>coder agent</strong> could write Python scripts or automation routines.</p>
</li>
<li><p>A <strong>reviewer agent</strong> might check the results and ensure everything is up to snuff.</p>
</li>
</ul>
<p>These agents can chat with each other, share information, and even debate or vote on decisions. This kind of teamwork allows AI systems to tackle bigger, more complex tasks while keeping things organized and modular.</p>
<h2 id="heading-project-automate-your-daily-schedule-from-emails">Project: Automate Your Daily Schedule from Emails</h2>
<h3 id="heading-what-were-automating">What We’re Automating</h3>
<p>Think about your typical morning routine:</p>
<ul>
<li><p>You open your inbox.</p>
</li>
<li><p>You quickly scan through a bunch of emails.</p>
</li>
<li><p>You try to spot meetings, tasks, and important reminders.</p>
</li>
<li><p>Then, you manually write a to-do list or add things to your calendar.</p>
</li>
</ul>
<p>Let's use an LLM agent to make that process effortless. Our agent will:</p>
<ul>
<li><p>Read a list of your email messages</p>
</li>
<li><p>Pull out time-sensitive items like meetings or deadlines</p>
</li>
<li><p>Summarize everything into a nice, clean daily schedule</p>
</li>
</ul>
<h3 id="heading-step-1-install-the-required-tools">Step 1: Install the Required Tools</h3>
<p>To get started, you'll need three main tools: Python, VSCode, and an OpenAI API key.</p>
<h4 id="heading-1-install-python-39-or-higher">1. Install Python 3.9 or Higher</h4>
<p>Grab the latest version of Python 3.9+ from the official website: <a target="_blank" href="https://www.python.org/downloads/">https://www.python.org/downloads/</a></p>
<p>Once it's installed, double-check it by running <code>python --version</code> in your terminal.</p>
<p>This command simply asks your system to report the Python version currently installed. You'll want to see Python 3.9.x or something higher to ensure compatibility with our project.</p>
<h4 id="heading-2-install-vscode-optional-but-recommended">2. Install VSCode (Optional but Recommended)</h4>
<p>VSCode is a fantastic, user-friendly code editor that works perfectly with Python. You can download it right here: <a target="_blank" href="https://code.visualstudio.com/">https://code.visualstudio.com/</a>.</p>
<h4 id="heading-3-get-your-openai-api-key">3. Get Your OpenAI API Key</h4>
<p>Head over to: https://platform.openai.com</p>
<p>Sign in or create a new account. Navigate to your API Keys page. Click “Create new secret key” and make sure to copy that key somewhere safe for later.</p>
<h4 id="heading-4-install-python-libraries">4. Install Python Libraries</h4>
<p>Open your terminal or command prompt and install these essential packages:</p>
<pre><code class="lang-bash">pip install langgraph langchain openai
</code></pre>
<p>This command uses pip, Python's package manager, to download and install three crucial libraries for our agent:</p>
<ul>
<li><p>langgraph: The core framework we'll use to build our agent's workflow.</p>
</li>
<li><p>langchain: A foundational library for working with large language models, upon which LangGraph is built.</p>
</li>
<li><p>openai: The official Python library for connecting to OpenAI's powerful AI models.</p>
</li>
</ul>
<p>If you're excited to try out multi-agent setups (which we'll cover in Step 5), also install CrewAI:</p>
<pre><code class="lang-bash">pip install crewai
</code></pre>
<p>This command installs CrewAI, a specialized framework that makes it easy to orchestrate multiple AI agents working together as a team.</p>
<p><strong>5. Set Your OpenAI API Key</strong></p>
<p>You need to make sure your Python code can find and use your OpenAI API key. This is typically done by setting it as an environment variable.</p>
<p>On macOS/Linux, run this in your terminal (replace "your-api-key" with your actual key):</p>
<pre><code class="lang-bash"><span class="hljs-built_in">export</span> OPENAI_API_KEY=<span class="hljs-string">"your-api-key"</span>
</code></pre>
<p>This command sets an environment variable named OPENAI_API_KEY. Environment variables are a secure way for applications (like your Python script) to access sensitive information without hardcoding it directly into the code itself.</p>
<p>On Windows (using Command Prompt), do this:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">set</span> OPENAI_API_KEY=<span class="hljs-string">"your-api-key"</span>
</code></pre>
<p>This is the Windows equivalent command to set the <code>OPENAI_API_KEY</code> environment variable.</p>
<p>Now, your Python code will be all set to talk to the OpenAI model!</p>
<h3 id="heading-step-2-define-the-task">Step 2: Define the Task</h3>
<p>We discussed this briefly in the beginning of this section. But to reiterate, this is what we’ll want our agent to do:</p>
<ul>
<li><p>Scan for meetings, events, and important tasks.</p>
</li>
<li><p>Jot them down quickly in a notebook or an app.</p>
</li>
<li><p>Create a rough mental plan for your day.</p>
</li>
</ul>
<p>This routine takes time and mental energy. So having an agent do it for us will be super helpful.</p>
<h3 id="heading-step-3-build-the-workflow-with-langgraph">Step 3: Build the Workflow with LangGraph</h3>
<h4 id="heading-what-is-langgraph">What Is LangGraph?</h4>
<p>LangGraph is a cool framework that helps you build agents using a "graph-based" workflow, kind of like drawing a flowchart. It's powered by LangChain and gives you a lot more control over exactly how each step in your agent's process unfolds.</p>
<p>Each "node" in this graph represents a decision point or a function that:</p>
<ul>
<li><p>Takes some input (its current "state").</p>
</li>
<li><p>Does some reasoning or takes an action (often involving the LLM and its tools).</p>
</li>
<li><p>Returns an updated output (a new "state").</p>
</li>
</ul>
<p>You draw the connections between these nodes, and LangGraph then executes it like a smart, automated state machine.</p>
<h4 id="heading-why-use-langgraph">Why Use LangGraph?</h4>
<ul>
<li><p>You get to control the precise order of execution.</p>
</li>
<li><p>It's fantastic for building workflows that have multiple steps or even branch off into different paths.</p>
</li>
<li><p>It plays nicely with both cloud-based models (like OpenAI) and models you run locally.</p>
</li>
</ul>
<p>Alright – now let’s write the code.</p>
<h5 id="heading-1-simulate-email-input"><strong>1. Simulate Email Input</strong></h5>
<p>In a real application, your agent would probably connect to Gmail or Outlook to fetch your actual emails. For this example, though, we’ll just hardcode some sample messages to keep things simple:</p>
<pre><code class="lang-python">Python

emails = <span class="hljs-string">"""
1. Subject: Standup Call at 10 AM
2. Subject: Client Review due by 5 PM
3. Subject: Lunch with Sarah at noon
4. Subject: AWS Budget Warning – 80% usage
5. Subject: Dentist Appointment - 4 PM
"""</span>
</code></pre>
<p>This multiline Python string, <code>emails</code>, acts as our stand-in for real email content. We're providing a simple, structured list of email subjects to demonstrate how the agent will process text.</p>
<h5 id="heading-2-define-the-agent-logic"><strong>2. Define the Agent Logic</strong></h5>
<p>Now, we'll tell OpenAI’s GPT model how to process this email text and turn it into a summary.</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> langchain_openai <span class="hljs-keyword">import</span> ChatOpenAI
<span class="hljs-keyword">from</span> langgraph.graph <span class="hljs-keyword">import</span> StateGraph, END
<span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> TypedDict, Annotated, List
<span class="hljs-keyword">import</span> operator

<span class="hljs-comment"># Define the state for our graph</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AgentState</span>(<span class="hljs-params">TypedDict</span>):</span>
    emails: str
    result: str

llm = ChatOpenAI(temperature=<span class="hljs-number">0</span>, model=<span class="hljs-string">"gpt-4o"</span>) <span class="hljs-comment"># Using gpt-4o for better performance</span>

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">calendar_summary_agent</span>(<span class="hljs-params">state: AgentState</span>) -&gt; AgentState:</span>
    emails = state[<span class="hljs-string">"emails"</span>]
    prompt = <span class="hljs-string">f"Summarize today's schedule based on these emails, listing time-sensitive items first and then other important notes. Be concise and use bullet points:\n<span class="hljs-subst">{emails}</span>"</span>
    summary = llm.invoke(prompt).content
    <span class="hljs-keyword">return</span> {<span class="hljs-string">"result"</span>: summary, <span class="hljs-string">"emails"</span>: emails} <span class="hljs-comment"># Ensure emails is also returned</span>
</code></pre>
<p>Here’s what’s going on:</p>
<ul>
<li><p><strong>Imports</strong>: We bring in necessary components:</p>
<ul>
<li><p><code>ChatOpenAI</code> to connect to the LLM,</p>
</li>
<li><p><code>StateGraph</code> and <code>END</code> from <code>langgraph.graph</code> to build our agent workflow,</p>
</li>
<li><p><code>TypedDict</code>, <code>Annotated</code>, and <code>List</code> from <code>typing</code> for type checking and structure,</p>
</li>
<li><p><code>operator</code> (though not used in this snippet, it can help with comparisons or logic).</p>
</li>
</ul>
</li>
<li><p><strong>AgentState</strong>: This <code>TypedDict</code> defines the shape of the data our agent will work with. It includes:</p>
<ul>
<li><p><code>emails</code>: the raw input messages.</p>
</li>
<li><p><code>result</code>: the final output (the daily summary).</p>
</li>
</ul>
</li>
<li><p><strong>llm = ChatOpenAI(...)</strong>: Initializes the language model. We're using GPT-4o with <code>temperature=0</code> to ensure consistent, predictable output perfect for structured summarization tasks.</p>
</li>
<li><p><strong>calendar_summary_agent(state: AgentState)</strong>: This function is the "brain" of our agent. It:</p>
<ul>
<li><p>Takes in the current state, which includes a list of emails.</p>
</li>
<li><p>Extracts the emails from that state.</p>
</li>
<li><p>Constructs a prompt that tells the model to generate a concise daily schedule summary using bullet points, prioritizing time-sensitive items.</p>
</li>
<li><p>Sends this prompt to the model with <code>llm.invoke(prompt).content</code>, which returns the LLM’s response as plain text.</p>
</li>
<li><p>Returns a new <code>AgentState</code> dictionary containing:</p>
<ul>
<li><p><code>result</code>: the generated summary,</p>
</li>
<li><p><code>emails</code>: preserved in case we need it downstream.</p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h5 id="heading-3-build-and-run-the-graph"><strong>3. Build and Run the Graph</strong></h5>
<p>Now, let's use LangGraph to map out the flow of our single-agent task and then run it.</p>
<pre><code class="lang-python">builder = StateGraph(AgentState)
builder.add_node(<span class="hljs-string">"calendar"</span>, calendar_summary_agent)
builder.set_entry_point(<span class="hljs-string">"calendar"</span>)
builder.set_finish_point(<span class="hljs-string">"calendar"</span>) <span class="hljs-comment"># END is implicit if not set explicitly</span>

graph = builder.compile()

<span class="hljs-comment"># Run the graph using your simulated email data</span>
result = graph.invoke({<span class="hljs-string">"emails"</span>: emails})
print(result[<span class="hljs-string">"result"</span>])
</code></pre>
<p>Here’s what’s going on:</p>
<ul>
<li><p><strong>builder = StateGraph(AgentState):</strong> We're initiating a StateGraph object. By passing AgentState, we're telling LangGraph the expected data structure for its internal state.</p>
</li>
<li><p><strong>builder.add_node("calendar", calendar_summary_agent):</strong> This line adds a named "node" to our graph. We're calling it "calendar", and we're linking it to our <code>calendar_summary_agent</code> function, meaning that function will be executed when this node is active.</p>
</li>
<li><p><strong>builder.set_entry_point("calendar"):</strong> This sets "calendar" as the very first step in our workflow. When we start the graph, execution will begin here.</p>
</li>
<li><p><strong>builder.set_finish_point("calendar"):</strong> This tells LangGraph that once the "calendar" node finishes its job, the entire graph process is complete.</p>
</li>
<li><p><strong>graph = builder.compile():</strong> This command takes our defined graph blueprint and "compiles" it into an executable workflow.</p>
</li>
<li><p><strong>result = graph.invoke({"emails": emails}):</strong> This is where the magic happens! We're telling our graph to start running. We pass it an initial state that contains our emails data. The graph will then process this data through its nodes until it reaches an end point, returning the final state.</p>
</li>
<li><p><strong>print(result["result"]):</strong> Finally, we grab the summarized schedule from the result (the final state of our graph) and print it to the console.</p>
</li>
</ul>
<h4 id="heading-example-output">Example Output</h4>
<p><code>Your Schedule:</code><br><code>- 10:00 AM – Standup Call</code><br><code>- 12:00 PM – Lunch with Sarah</code><br><code>- 4:00 PM – Dentist Appointment</code><br><code>- Submit client report by 5:00 PM</code><br><code>- AWS Budget Warning – check usage</code></p>
<p>Boom! You've just built an AI agent that can read your emails and whip up your daily schedule. Pretty cool, right? This is a simple yet powerful peek into what LLM agents can do with just a few lines of code.</p>
<h2 id="heading-multi-agent-collaboration-with-crewai">Multi-Agent Collaboration with CrewAI</h2>
<h3 id="heading-what-is-crewai">What Is CrewAI?</h3>
<p>CrewAI is an exciting open-source framework that lets you build <em>teams</em> of agents that work together seamlessly just like a real-world project team! Each agent in a CrewAI setup:</p>
<ul>
<li><p>Has a specific, specialized role.</p>
</li>
<li><p>Can communicate and share information with its teammates.</p>
</li>
<li><p>Collaborates to achieve a shared goal.</p>
</li>
</ul>
<p>This multi-agent approach is super useful when your task is too big or too complex for just one agent, or when breaking it down into specialized parts makes it clearer and more efficient.</p>
<h3 id="heading-sample-roles-for-the-email-summary-task">Sample Roles for the Email Summary Task</h3>
<p>Let's imagine our email summary task being handled by a small team of agents:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Agent Name</strong></td><td><strong>Role</strong></td><td><strong>Responsibility</strong></td></tr>
</thead>
<tbody>
<tr>
<td>Extractor</td><td>Email Scanner</td><td>"Find meetings, reminders, and tasks from emails"</td></tr>
<tr>
<td>Prioritizer</td><td>Schedule Optimizer</td><td>Sort items by urgency and time</td></tr>
<tr>
<td>Formatter</td><td>Output Generator</td><td>"Write a clean, polished daily agenda"</td></tr>
</tbody>
</table>
</div><h3 id="heading-sample-crewai-code">Sample CrewAI Code</h3>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> crewai <span class="hljs-keyword">import</span> Agent, Crew, Task, Process
<span class="hljs-keyword">from</span> langchain_openai <span class="hljs-keyword">import</span> ChatOpenAI
<span class="hljs-keyword">import</span> os

<span class="hljs-comment"># Set your OpenAI API key from environment variables</span>
<span class="hljs-comment"># os.environ["OPENAI_API_KEY"] = "YOUR_API_KEY" # Make sure this is set, or defined directly</span>

<span class="hljs-comment"># Initialize the LLM (using gpt-4o for better performance)</span>
llm = ChatOpenAI(temperature=<span class="hljs-number">0</span>, model=<span class="hljs-string">"gpt-4o"</span>)

<span class="hljs-comment"># Define the agents with specific roles and goals</span>
extractor = Agent(
    role=<span class="hljs-string">"Email Scanner"</span>,
    goal=<span class="hljs-string">"Find all meetings, reminders, and tasks from the given emails, accurately extracting details like time, date, and subject."</span>,
    backstory=<span class="hljs-string">"You are an expert at scanning emails for key information. You meticulously extract every relevant detail."</span>,
    verbose=<span class="hljs-literal">True</span>,
    allow_delegation=<span class="hljs-literal">False</span>,
    llm=llm
)

prioritizer = Agent(
    role=<span class="hljs-string">"Schedule Optimizer"</span>,
    goal=<span class="hljs-string">"Sort extracted items by urgency and time, preparing them for a daily agenda."</span>,
    backstory=<span class="hljs-string">"You are a master of time management, always knowing what needs to be done first. You organize tasks logically."</span>,
    verbose=<span class="hljs-literal">True</span>,
    allow_delegation=<span class="hljs-literal">False</span>,
    llm=llm
)

formatter = Agent(
    role=<span class="hljs-string">"Output Generator"</span>,
    goal=<span class="hljs-string">"Generate a clean, polished, and concise daily agenda in bullet-point format, clearly listing all schedule items."</span>,
    backstory=<span class="hljs-string">"You are a professional secretary, ensuring all outputs are perfectly formatted and easy to read. You prioritize clarity."</span>,
    verbose=<span class="hljs-literal">True</span>,
    allow_delegation=<span class="hljs-literal">False</span>,
    llm=llm
)

<span class="hljs-comment"># Simulate email input</span>
emails = <span class="hljs-string">"""
1. Subject: Standup Call at 10 AM
2. Subject: Client Review due by 5 PM
3. Subject: Lunch with Sarah at noon
4. Subject: AWS Budget Warning – 80% usage
5. Subject: Dentist Appointment - 4 PM
"""</span>

<span class="hljs-comment"># Define the tasks for each agent</span>
extract_task = Task(
    description=<span class="hljs-string">f"Extract all relevant events, meetings, and tasks from these emails: <span class="hljs-subst">{emails}</span>. Focus on precise details."</span>,
    agent=extractor,
    expected_output=<span class="hljs-string">"A list of extracted items with their details (e.g., '- Standup Call at 10 AM', '- Client Review due by 5 PM')."</span>
)

prioritize_task = Task(
    description=<span class="hljs-string">"Prioritize the extracted items by time and urgency. Meetings first, then deadlines, then other notes."</span>,
    agent=prioritizer,
    context=[extract_task], <span class="hljs-comment"># The output of extract_task is the input here</span>
    expected_output=<span class="hljs-string">"A prioritized list of schedule items."</span>
)

format_task = Task(
    description=<span class="hljs-string">"Format the prioritized schedule into a clean, easy-to-read daily agenda using bullet points. Ensure concise language."</span>,
    agent=formatter,
    context=[prioritize_task], <span class="hljs-comment"># The output of prioritize_task is the input here</span>
    expected_output=<span class="hljs-string">"A well-formatted daily agenda with bullet points."</span>
)

<span class="hljs-comment"># Instantiate the crew</span>
crew = Crew(
    agents=[extractor, prioritizer, formatter],
    tasks=[extract_task, prioritize_task, format_task],
    process=Process.sequential, <span class="hljs-comment"># Tasks are executed sequentially</span>
    verbose=<span class="hljs-number">2</span> <span class="hljs-comment"># Outputs more details during execution</span>
)

<span class="hljs-comment"># Run the crew</span>
result = crew.kickoff()
print(<span class="hljs-string">"\n########################"</span>)
print(<span class="hljs-string">"## Final Daily Agenda ##"</span>)
print(<span class="hljs-string">"########################\n"</span>)
print(result)
</code></pre>
<p>Here’s what’s going on:</p>
<ul>
<li><p><strong>Imports:</strong> We bring in key classes from CrewAI: Agent, Crew, Task, and Process. We also import <code>ChatOpenAI</code> for our language model and os to handle environment variables.</p>
</li>
<li><p><strong>llm = ChatOpenAI(...):</strong> Just like in the LangGraph example, this sets up our OpenAI language model, making sure its responses are direct (temperature=0) and using the gpt-4o model.</p>
</li>
<li><p><strong>Agent Definitions (extractor, prioritizer, formatter):</strong></p>
<ul>
<li><p>Each of these variables creates an Agent instance. An agent is defined by its role (what it does), a specific goal it's trying to achieve, and a backstory (a sort of personality or expertise that helps the LLM understand its purpose better).</p>
</li>
<li><p>verbose=True is super helpful for debugging, as it makes the agents print out their "thoughts" as they work.</p>
</li>
<li><p>allow_delegation=False means these agents won't pass their assigned tasks to other agents (though this can be set to True for more complex delegation scenarios).</p>
</li>
<li><p>llm=llm connects each agent to our OpenAI language model.</p>
</li>
</ul>
</li>
<li><p><strong>Simulated emails:</strong> We reuse the same sample email data for this example.</p>
</li>
<li><p><strong>Task Definitions (extract_task, prioritize_task, format_task):</strong></p>
<ul>
<li><p>Each Task defines a specific piece of work that an agent needs to perform.</p>
</li>
<li><p>description clearly tells the agent what the task involves.</p>
</li>
<li><p>agent assigns this task to one of our defined agents (e.g., extractor for extract_task).</p>
</li>
<li><p>context=[...] is a critical part of CrewAI's collaboration. It tells a task to use the <em>output</em> of a previous task as its <em>input</em>. For instance, prioritize_task takes the extract_task's output as its context.</p>
</li>
<li><p>expected_output gives the agent an idea of what its result should look like, helping guide the LLM.</p>
</li>
</ul>
</li>
<li><p><strong>crew = Crew(...):</strong></p>
<ul>
<li><p>This is where we assemble our team! We create a Crew instance, giving it our list of agents and tasks.</p>
</li>
<li><p>process=Process.sequential tells the crew to execute tasks one after another in the order they're defined in the tasks list. CrewAI also supports more advanced processes like hierarchical ones.</p>
</li>
<li><p>verbose=2 will show you a very detailed log of the crew's internal workings and communication.</p>
</li>
</ul>
</li>
<li><p><strong>result = crew.kickoff():</strong> This command officially starts the entire multi-agent workflow. The agents will begin collaborating, passing information, and working through their assigned tasks in sequence.</p>
</li>
<li><p><strong>fprint(result):</strong> Finally, the consolidated output from the entire crew's collaborative effort is printed to your console.</p>
</li>
</ul>
<p>CrewAI cleverly handles all the communication between agents, figures out who needs to work on what and when, and passes the output smoothly from one agent to the next it's like having a mini AI assembly line!</p>
<h2 id="heading-what-actually-happens-during-execution">What Actually Happens During Execution?</h2>
<p>So, whether you're using LangGraph or CrewAI, what's really going on behind the scenes when an agent runs? Let's break down the execution process:</p>
<ul>
<li><p>The system gets an <strong>input state</strong> (for example, your emails).</p>
</li>
<li><p>The first agent or graph node reads this input and uses a <strong>Large Language Model (LLM)</strong> to make sense of it.</p>
</li>
<li><p>Based on its understanding, the agent decides on an <strong>action</strong> like pulling out key events or calling a specific tool.</p>
</li>
<li><p>If needed, the agent might <strong>invoke tools</strong> (like a web search or a file reader) to get more context or perform external operations.</p>
</li>
<li><p>The result of that action is then <strong>passed to the next agent</strong> in the team (if it's a multi-agent setup) or returned directly to you.</p>
</li>
</ul>
<p>Execution keeps going until:</p>
<ul>
<li><p>The task is fully completed.</p>
</li>
<li><p>All agents have finished their assigned roles.</p>
</li>
<li><p>A stopping condition or a designated "END" point in the workflow is reached.</p>
</li>
</ul>
<p>Think of this as a super-smart workflow engine where every single step involves reasoning, making decisions, and remembering previous interactions.</p>
<h2 id="heading-are-llm-agents-safe-what-to-know-about-security-and-privacy">Are LLM Agents Safe? What to Know About Security and Privacy</h2>
<p>As cool as LLM agents are, they raise an important question: <em>can you really trust an AI to run parts of your workflow or interact with your data?</em> It depends. If you’re using services like OpenAI or Anthropic, your data is encrypted in transit and (as of now) isn’t used for training.</p>
<p>But some data might still be temporarily logged to prevent abuse. That’s usually fine for testing and personal projects, but if you’re working with sensitive business info, customer data, or anything private, you’ll want to be careful.</p>
<p>Use anonymized inputs, avoid exposing full datasets, and consider running agents locally using open-source models like LLaMA or Mistral if full control matters to you.</p>
<p>You can also set clear boundaries for your agents so they don’t overstep. Think of it like onboarding a new intern: you wouldn’t give them access to everything on day one.</p>
<p>Give agents only the tools and files they need, keep logs of what they do, and always review the results before letting them make real changes.</p>
<p>As this tech grows, more safety features are coming like better sandboxing, memory limits, and role-based access. But for now, it’s smart to treat your agents like powerful helpers that still need some human supervision.</p>
<h2 id="heading-troubleshooting-amp-tips">Troubleshooting &amp; Tips</h2>
<p>Sometimes, agents can be a bit quirky! Here are some common issues you might run into and how to fix them:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Issue</strong></td><td><strong>Suggested Fix</strong></td></tr>
</thead>
<tbody>
<tr>
<td>Agent seems to loop forever</td><td>Set a maximum number of iterations or define a clearer stopping point.</td></tr>
<tr>
<td>Output is too chatty or verbose</td><td>Use more specific prompts (for example, “Respond in bullet points only”).</td></tr>
<tr>
<td>Input is too long or gets cut off</td><td>Break down large pieces of content into smaller chunks and summarize them individually.</td></tr>
<tr>
<td>Agent runs too slowly</td><td>Try using a faster LLM model like gpt-3.5 or consider running a local model.</td></tr>
</tbody>
</table>
</div><p>A handy tip: You can also add print() statements or logging messages inside your agent functions to see what's happening at each stage and debug state transitions.</p>
<h2 id="heading-explore-more-daily-automations">Explore More Daily Automations</h2>
<p>Once you've built one agent-based task, you'll find it incredibly easy to adapt the pattern for other automations. Here are some cool ideas to get your creative juices flowing:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Task Type</strong></td><td><strong>Example Automation</strong></td></tr>
</thead>
<tbody>
<tr>
<td>DevOps Assistant</td><td>"Read system logs, detect potential issues, and suggest solutions."</td></tr>
<tr>
<td>Finance Tracker</td><td>Read bank statements or CSV files and summarize your spending habits/budgets.</td></tr>
<tr>
<td>Meeting Organizer</td><td>After a meeting, automatically extract action items and assign owners.</td></tr>
<tr>
<td>Inbox Cleaner</td><td>"Automatically label, archive, and delete non-urgent emails."</td></tr>
<tr>
<td>Note Summarizer</td><td>Convert your daily notes into a neatly formatted to-do list or summary.</td></tr>
<tr>
<td>Link Checker</td><td>Extract URLs from documents and automatically test if they're still valid.</td></tr>
<tr>
<td>Resume Formatter</td><td>Score resumes against job descriptions and format them automatically.</td></tr>
</tbody>
</table>
</div><p>Each of these can be built using the very same principles and frameworks we discussed whether that's LangGraph or CrewAI.</p>
<h2 id="heading-whats-next-in-agent-technology">What’s Next in Agent Technology?</h2>
<p>LLM agents are evolving at lightning speed, and the next wave of innovation is already here:</p>
<ul>
<li><p><strong>Smarter memory systems</strong>: Expect agents to have better long-term memory, allowing them to learn over extended periods and remember past conversations and actions.</p>
</li>
<li><p><strong>Multi-modal agents</strong>: Agents won't just handle text anymore! They'll be able to process and understand images, audio, and video, making them much more versatile.</p>
</li>
<li><p><strong>Advanced planning frameworks</strong>: Techniques like ReAct, Toolformer, and AutoGen are constantly improving agents' ability to reason, plan, and reduce those pesky "hallucinations."</p>
</li>
<li><p><strong>Edge deployment</strong>: Imagine agents running entirely offline on your local computer or device using lightweight models like LLaMA 3 or Mistral.</p>
</li>
</ul>
<p>In the very near future, you'll see agents seamlessly integrated into:</p>
<ul>
<li><p>Your DevOps pipelines</p>
</li>
<li><p>Big enterprise workflows</p>
</li>
<li><p>Everyday productivity tools</p>
</li>
<li><p>Mobile apps and smart devices</p>
</li>
<li><p>Games, simulations, and educational platforms</p>
</li>
</ul>
<h2 id="heading-final-summary">Final Summary</h2>
<p>Alright, let's quickly recap all the cool stuff you've just learned and accomplished:</p>
<ul>
<li><p>You've gotten a solid grasp of what LLM agents are and why they're so powerful.</p>
</li>
<li><p>You've seen how open-source frameworks like LangGraph and CrewAI make building agents much easier.</p>
</li>
<li><p>You've built a real LLM agent using LangGraph to automate a common daily task: summarizing your inbox!</p>
</li>
<li><p>You've explored the world of multi-agent collaboration with CrewAI, understanding how teams of AIs can work together.</p>
</li>
<li><p>You've learned how to take these principles and scale them to automate countless other tasks.</p>
</li>
</ul>
<p>So, next time you find yourself stuck doing something repetitive, just ask yourself: "Hey, can I build an agent for that?" The answer is probably yes!</p>
<h3 id="heading-resources-recap">Resources Recap</h3>
<p>Here are some helpful resources if you want to dive deeper into building LLM agents:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Resource</strong></td><td><strong>Link</strong></td></tr>
</thead>
<tbody>
<tr>
<td>LangGraph Docs</td><td><a target="_blank" href="https://docs.langgraph.dev/">https://docs.langgraph.dev/</a></td></tr>
<tr>
<td>CrewAI GitHub</td><td><a target="_blank" href="https://github.com/joaomdmoura/crewAI">https://github.com/joaomdmoura/crewAI</a></td></tr>
<tr>
<td>LangChain Docs</td><td><a target="_blank" href="https://docs.langchain.com/docs/">https://docs.langchain.com/docs/</a></td></tr>
<tr>
<td>OpenAI API Docs</td><td><a target="_blank" href="https://platform.openai.com/docs">https://platform.openai.com/docs</a></td></tr>
<tr>
<td>Python 3.9+</td><td><a target="_blank" href="https://www.python.org/downloads/">https://www.python.org/downloads/</a></td></tr>
<tr>
<td>VSCode</td><td><a target="_blank" href="https://code.visualstudio.com/">https://code.visualstudio.com/</a></td></tr>
</tbody>
</table>
</div> ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
