<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Martin Kobimbo</title>
    <description>The latest articles on DEV Community by Martin Kobimbo (@mkobimbo).</description>
    <link>https://dev.to/mkobimbo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1198550%2Fb9d7a402-16fa-4fc8-87c5-63885c2feb2d.jpg</url>
      <title>DEV Community: Martin Kobimbo</title>
      <link>https://dev.to/mkobimbo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mkobimbo"/>
    <language>en</language>
    <item>
      <title>Can Django handle 100K+ daily visits?</title>
      <dc:creator>Martin Kobimbo</dc:creator>
      <pubDate>Tue, 23 Jan 2024 19:28:08 +0000</pubDate>
      <link>https://dev.to/mkobimbo/can-django-handle-100k-daily-visits-3600</link>
      <guid>https://dev.to/mkobimbo/can-django-handle-100k-daily-visits-3600</guid>
      <description>&lt;p&gt;The high-level Python web framework Django is well known for its features that are developer-friendly, reliable, and easy to use. It gives developers the ability to swiftly and effectively design web apps. &lt;/p&gt;

&lt;p&gt;But when your application becomes more popular and has a wider user base, you may find yourself wondering if Django can manage the volume that comes from 100,000 visits per day. &lt;/p&gt;

&lt;p&gt;In this blog, we'll look at Django's performance and scalability features and talk about how to make sure your application can handle that kind of volume of daily users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Python Proficiency.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Django Proficiency.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;In this blog...&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Django Basics.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scalability challenges.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Examples of high-traffic Django sites.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Django Basics&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Django follows the Model-View-Controller (MVC) pattern, or the Model-View-Template (MVT) pattern. It is designed to encourage clean and maintainable code by separating the application into distinct layers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Model: Represents the data and database schema.&lt;/li&gt;
&lt;li&gt;View: Handles user interactions, processes requests, and returns responses.&lt;/li&gt;
&lt;li&gt;Template: Defines how the data is shown to users.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Scalability Issues&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When aiming to serve 100,000 daily visits, several scalability challenges need to be addressed:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Database Scalability: Django supports various databases, including PostgreSQL, MySQL, and SQLite. To handle a large number of visitors, you must optimize database queries, use database indexing, and consider database replication or sharding to distribute the load.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Caching: Implementing caching mechanisms can significantly improve performance. Django provides built-in support for caching using various backends like Memcached or Redis. Caching frequently accessed data reduces the load on your application server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Web Server: While Django has a built-in development server, it’s not suitable for production use. Deploying Django behind a robust web server like Nginx or Apache can help handle a higher number of concurrent requests efficiently.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Load Balancing: As traffic grows, distributing incoming requests among multiple application instances using load balancing becomes necessary. Tools like Gunicorn, uWSGI, or ASGI can help you achieve this.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Horizontal Scaling: To handle a substantial number of daily visits, you might need to scale horizontally by adding more application servers. Container orchestration tools like Docker and Kubernetes can simplify this process.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Asynchronous Processing: Django’s synchronous request-response model can become a bottleneck under heavy load. Utilizing asynchronous programming with libraries like Django Channels or FastAPI can improve concurrency and response times.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Content Delivery: Offloading static assets (images, stylesheets, scripts) to Content Delivery Networks (CDNs) reduces the load on your server and accelerates content delivery to users worldwide.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Monitoring and Optimization: Implement robust monitoring and profiling tools to identify performance bottlenecks and optimize your application accordingly. Tools like New Relic, Datadog, or Prometheus can help with it.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;High Traffic Django sites&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Several high-traffic websites and applications use Django as their backend framework, these are sites like;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Instagram: One of the most popular social media platforms, Instagram, initially used Django as its web framework. While they’ve since migrated some parts to other technologies, Django played a crucial role in their early growth.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pinterest: Pinterest, a content-sharing and discovery platform, was built using Django. As the platform scaled, Pinterest engineers have continued to optimize and adapt their Django-based infrastructure.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;NASA, DropBox, Disqus, Spotify, Eventbrite, Mozilla, Bitbucket, The Washington Post etcetera.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Django is a powerful web framework that can handle a substantial number of daily visits, even as high as 100,000 or more. However, achieving this level of scalability requires careful planning, optimization, and the use of various performance-enhancing techniques.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>python</category>
      <category>django</category>
      <category>discuss</category>
    </item>
    <item>
      <title>How to resolve Django migration errors from triggers.</title>
      <dc:creator>Martin Kobimbo</dc:creator>
      <pubDate>Tue, 23 Jan 2024 13:21:03 +0000</pubDate>
      <link>https://dev.to/mkobimbo/how-to-resolve-django-migration-errors-from-triggers-2hi9</link>
      <guid>https://dev.to/mkobimbo/how-to-resolve-django-migration-errors-from-triggers-2hi9</guid>
      <description>&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Intermediate-level Python.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Command line interface knowledge.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Django Framework knowledge.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PostgreSQL and databases.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This error prevents you from executing schema changes on a table with enabled triggers. This post will explore why this error occurs and how to resolve it.&lt;/p&gt;

&lt;p&gt;This is what the error looks like:&lt;br&gt;
&lt;code&gt;django.db.utils.OperationalError: cannot ALTER TABLE "mytable" because it has pending trigger events&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding Django migration errors&lt;/strong&gt;&lt;br&gt;
What's happening when we get this error?&lt;/p&gt;

&lt;p&gt;In Django, makemigrations generates migration files that describe schema changes to your models—for example, adding a new field. migrate then applies these migrations by running ALTER TABLE statements.&lt;/p&gt;

&lt;p&gt;However, PostgreSQL does not allow ALTER TABLE on tables that have enabled triggers. So if your table has triggers, the migrate step fails with the “pending trigger events” error.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do triggers block alters&lt;/strong&gt;&lt;br&gt;
Trigger’s fire in response to events like inserts, updates, or deletes. They allow you to perform actions like validating input or logging history.&lt;/p&gt;

&lt;p&gt;Triggers also introduce some database locking issues. If PostgreSQL allowed an ALTER while triggers were enabled, it could lead to inconsistent data.&lt;/p&gt;

&lt;p&gt;As a result, PostgreSQL completely blocks ALTER TABLE unless you disable or drop existing triggers first. Django migrations obey this constraint and error out.&lt;/p&gt;

&lt;p&gt;Now that we understand the cause, what solutions exist for applying migrations?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Temporarily disabling triggers&lt;/strong&gt;
One option is to temporarily disable existing triggers on the table during the migration.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE mytable DISABLE TRIGGER ALL; 

# Run migrations with python manage.py migrate

ALTER TABLE mytable ENABLE TRIGGER ALL;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This unblocks Django from running ALTER TABLE, allowing the schema changes to apply.&lt;/p&gt;

&lt;p&gt;Directly manipulating triggers can be tedious and error-prone. You need to remember to re-enable the trigger’s after.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Manually drop and recreate triggers&lt;/strong&gt;
You can drop triggers before migrating.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DROP TRIGGER IF EXISTS my_insert_trigger on mytable;

# Run migrations  

CREATE TRIGGER ... 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This also gets Django migrations working. But again, it requires manually rebuilding your trigger logic.&lt;/p&gt;

&lt;p&gt;3.&lt;strong&gt;Use Djangos Schema editor&lt;/strong&gt;&lt;br&gt;
Django offers a higher-level API for managing triggers and migrations cleanly.&lt;/p&gt;

&lt;p&gt;The django.db.backends.base.schema.BaseDatabaseSchemaEditor class allows overriding schema modifying commands. This includes hooks to drop and recreate triggers automatically around a migration.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.db import migrations

class Migration(migrations.Migration):

    operations = [
        migrations.AddField( ... ) 
        ...
    ]

    def drop_triggers(self, schema_editor, schema_migration):
        schema_editor.execute("DROP TRIGGER...") 

    def recreate_triggers(self, schema_editor, schema_migration):
        schema_editor.execute("CREATE TRIGGER...")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now triggers will automatically drop and recreate around the migration operation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A few other solutions&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a replica PostgreSQL database for running migrations, without triggers enabled. Then sync the applied schema changes back to the primary database.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Disable triggers directly in PostgreSQL by setting session_replication_role to replica during migration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ImproperlyConfigured the migration files to temporarily drop triggers by overriding SchemaEditor commands.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In most cases, the Django SchemaEditor hooks provide the best development experience for managing triggers. But in complex deployments, alternate solutions like migrations replicas may be necessary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;PostgreSQL triggers causing Django migration issues can be rather annoying. However, by comprehending the situation, you can identify a workaround that works.&lt;/p&gt;

&lt;p&gt;The remainder of your trigger logic can still function when triggers are temporarily dropped, either manually or with SchemaEditor. Even with triggers enabled, you can continue to work productively on Django schema migrations if you have the correct approach.&lt;/p&gt;

&lt;p&gt;Don't be shy, ask some questions in the comments.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>django</category>
      <category>python</category>
      <category>postgres</category>
    </item>
    <item>
      <title>Using Puppeteer and JavaScript to Automate Form Filling on Any Website</title>
      <dc:creator>Martin Kobimbo</dc:creator>
      <pubDate>Sat, 20 Jan 2024 20:57:22 +0000</pubDate>
      <link>https://dev.to/mkobimbo/using-puppeteer-and-javascript-to-automate-form-filling-on-any-website-5fol</link>
      <guid>https://dev.to/mkobimbo/using-puppeteer-and-javascript-to-automate-form-filling-on-any-website-5fol</guid>
      <description>&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;p&gt;Prerequisites&lt;br&gt;
Basic Methods&lt;br&gt;
Launching Puppeteer&lt;br&gt;
Conclusion&lt;/p&gt;

&lt;p&gt;Puppeteer is a Node.js library that allows you to control a headless Chrome or Chromium browser. This means you can automate tasks typically requiring a human to interact with a web browser, such as filling out forms.&lt;/p&gt;

&lt;p&gt;This tutorial will show you how to use Puppeteer and JavaScript to automate form filling on any website. By the end of this tutorial, you will be able to:&lt;/p&gt;

&lt;p&gt;Launch Puppeteer and create a new browser instance.&lt;/p&gt;

&lt;p&gt;Navigate to a website and find a form.&lt;/p&gt;

&lt;p&gt;Fill out the form with the desired information.&lt;/p&gt;

&lt;p&gt;Submit the form.&lt;/p&gt;

&lt;p&gt;Close the browser.&lt;/p&gt;

&lt;p&gt;This tutorial is for beginners who are new to Puppeteer and JavaScript. However, even with experience with these technologies, you may find this tutorial helpful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You will need to have the latest version of Node.js installed on your computer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You will need to have the Puppeteer package installed. You can install it by running the following command in your terminal:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;npm install puppeteer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic methods&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;title()&lt;br&gt;
This command is used to obtain the title of the present page.&lt;br&gt;
Syntax&lt;br&gt;
The syntax is as follows;&lt;br&gt;
&lt;code&gt;await page.title()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;URL()&lt;br&gt;
This command is used to obtain the URL of the application currently launched in the browser.&lt;br&gt;
Syntax&lt;br&gt;
The syntax is as follows;&lt;br&gt;
&lt;code&gt;await page.url()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;content()&lt;br&gt;
This command is used to obtain the page source code.&lt;br&gt;
Syntax&lt;br&gt;
The syntax is as follows;&lt;br&gt;
&lt;code&gt;await page.content()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;goto()&lt;br&gt;
This command is used go to your site.&lt;br&gt;
Syntax&lt;br&gt;
The syntax is as follows;&lt;br&gt;
&lt;code&gt;await page.goto()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;browser()&lt;br&gt;
This command is used to create a page&lt;br&gt;
Syntax&lt;br&gt;
The syntax is as follows;&lt;br&gt;
&lt;code&gt;await browser.newPage()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;type()&lt;br&gt;
This command is used to type into search box&lt;br&gt;
Syntax&lt;br&gt;
The syntax is as follows;&lt;br&gt;
&lt;code&gt;await page.type()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To explore more about the various methods and capabilities of Puppeteer, you can refer to the official Puppeteer documentation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Launching Puppeteer and Navigating to a Web Page&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a new directory for your project and navigate to it in the terminal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a new JavaScript file called index.js, in your project directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open the file in any text editor you choose, but you will use Vscode for this tutorial. Then import Puppeteer by adding the following line at the beginning:&lt;br&gt;
&lt;code&gt;const puppeteer = require('puppeteer');&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a new browser instance&lt;br&gt;
&lt;code&gt;const browser = await puppeteer.launch();&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigate to a website.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const page = await browser.newPage();
 await page.goto('https://example.com/');

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Define an asynchronous function.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;async () =&amp;gt; {}&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Inside the async function, launch Puppeteer, and create a new browser instance
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const browser = await puppeteer.launch({ headless: false });
   const page = await browser.newPage();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to your desired web page using page.goto method&lt;br&gt;
&lt;code&gt;await page.goto("Example.com/login");&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fill the input fields in the browser using page.type method&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await page.type("#selector", "value");
await page.type("#selector", "Egeg545heehew222");

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Use page.select method to fill dropdown menus&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;code&gt;await page.select("#dropwdown selector", "dropdown value");&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use page.click method to click checkboxes and radio buttons&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;code&gt;await page.evaluate(() =&amp;gt; document.querySelector("#selector").click());&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Use page.keyboard.press method to simulate clicking the submit button&lt;br&gt;
&lt;code&gt;await page.keyboard.press("Enter");&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use page.waitForNavigation() method to wait for a page to navigate to a new URL or to reload.&lt;br&gt;
&lt;code&gt;await page.waitForNavigation();&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Complete Code&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const puppeteer = require("puppeteer");

(async () =&amp;gt; {

  const browser = await puppeteer.launch({ headless: false });
  const page = await browser.newPage();

  await page.goto("https://jobs.careeraddict.com/login");

  await page.type("#user_email", "wise4rmgod@yahoo.com");
  await page.type("#user_password", "Egeg545heehew222");

  await page.keyboard.press("Enter");

  await page.waitForNavigation();

  console.log("Successfully signed in!");

  await browser.close();
})();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This tutorial shows you how to use Puppeteer and JavaScript to automate form filling on any website. We have covered the basics of Puppeteer and JavaScript, and we have shown you how to write a script that can fill out a simple form.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>node</category>
    </item>
    <item>
      <title>Resolving requested access to the resource is denied on Dockerhub</title>
      <dc:creator>Martin Kobimbo</dc:creator>
      <pubDate>Sat, 20 Jan 2024 19:20:16 +0000</pubDate>
      <link>https://dev.to/mkobimbo/resolving-requested-access-to-the-resource-is-denied-on-dockerhub-2p2e</link>
      <guid>https://dev.to/mkobimbo/resolving-requested-access-to-the-resource-is-denied-on-dockerhub-2p2e</guid>
      <description>&lt;p&gt;Occasionally, you might encounter an error message stating that Requested access to the resource is denied when attempting to push images on Docker Hub.&lt;/p&gt;

&lt;p&gt;In this article, I will provide steps to resolve it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log in to the Docker Hub account in the command line.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;docker login -u mkobi&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Tag your image build&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;docker tag quotes:latest mkobi/quotes:v2&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;View image locally via the Docker Desktop&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Push the image to your private docker repository&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;docker push mkobi/quotes:v2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The output is similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The push refers to repository [docker.io/wise4rmgod/quotes]
73ba38394181: Pushed 
47f6f066faff: Pushed 
8e09802f4e96: Pushed 
88bb24ab4cf4: Pushed 
7355a3354412: Pushed 
23350eaaee74: Pushed 
df8e43203da9: Pushed 
92a6bff90f79: Pushed 
26cbea5cba74: Pushed 
v2: digest: sha256:78ad6fa8b3091a3d59a0a66bea3885d9c14075f369e48e57b92ef86ae5789385 size: 2204

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Encountering the Requested access to the resource is denied error on Docker Hub can be frustrating, but by following the steps outlined in this article, you can identify and resolve the cause.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>docker</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Creating a simple message board app in django</title>
      <dc:creator>Martin Kobimbo</dc:creator>
      <pubDate>Fri, 29 Dec 2023 17:42:39 +0000</pubDate>
      <link>https://dev.to/mkobimbo/creating-a-simple-message-board-app-in-django-2f2p</link>
      <guid>https://dev.to/mkobimbo/creating-a-simple-message-board-app-in-django-2f2p</guid>
      <description>&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Version Control(Git)&lt;/li&gt;
&lt;li&gt;Python&lt;/li&gt;
&lt;li&gt;Command line/Terminal&lt;/li&gt;
&lt;li&gt;Web development concepts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;"Hey there, curious minds! Ever wanted to create your own interactive space online? Get ready to dive into the exciting world of Django as we build a simple message board together.     &lt;/p&gt;

&lt;p&gt;We will use a database to create a basic message board app where users can post or read short messages.&lt;/p&gt;

&lt;p&gt;We will dive into Django's powerful admin interface which provides a visual way to make changes to our data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Initial SetUp&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To give you a picture here is what we are doing first:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;create a new directory on our desktop called mb.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install virtualenv if you haven't already&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install Django in a virtual environment&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a project called mb_project&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create an app called posts&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;update settings.py&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;In your terminal/Command line interface type in the following&lt;/em&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

$ cd Desktop

$ mkdir mb

$ cd mb

$ pip install virtualenv

$ pipenv install django

$ pipenv shell

(mb) $ django-admin startproject mb_project

(mb) $ python manage.py startapp posts



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now let Django know about our app "posts" by adding it to the bottom of the INSTALLED_APPS section inside our settings.py file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'posts.apps.PostsConfig',

]


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now execute a migrate command to create a database.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;(mb) python manage.py migrate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you type in the ls command in your terminal or simply view the files section inside your VScode you will see a db.sqlite3 file. This represents our database.&lt;/p&gt;

&lt;p&gt;We can now spin up our local server to see if everything works correctly.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;(mb) $ python manage.py runserver&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;click on the HTTP link to navigate to see the Django page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating a database model&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's create a database model to store and display posts from our users.&lt;/p&gt;

&lt;p&gt;Open the models.py file inside our posts app&lt;/p&gt;

&lt;p&gt;You will see that Django is importing a module called models which will help us in building database models, which will "model" the characteristics of the data in our database. Now we need to create a model to store the text content of a message board post. &lt;/p&gt;

&lt;p&gt;Here is how we do it:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

from django.db import models

class Post(models.model):

    text = models.TextField()



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;What have we just done here? We just created a database model called Post which has a field of text. We have also specified the type of content it will hold by putting in TextField(). Django provides many model fields which in turn support different types of content like integers, characters emails etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Models Activation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We need to activate our model. Whenever we create or modify an existing model, we must update Django with two steps.&lt;/p&gt;

&lt;p&gt;Initially, we create a migrations file with the makemigrations command. This file will help us track any changes.&lt;/p&gt;

&lt;p&gt;lastly, we build the actual database with the migrate command which will execute instructions inside our file.&lt;/p&gt;

&lt;p&gt;Stop the server by typing ctrl+c in your terminal. then run these two commands:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

(mb) $ python manage.py makemigrations posts

(mb) $ python manage.py migrate


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Working with the Django Admin&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of Django's impressive features is a built-in admin interface that provides a visual way to interact with data. &lt;/p&gt;

&lt;p&gt;To use the Django admin, we first need to create a superuser who can log in. Inside your terminal/command-line console type in:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ python manage.py createsuperuser&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You will then get this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Username:
Email:
Password:
Password(again):
Superuser created sucessfully.


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;note that your password will not appear in the terminal when typed in&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now restart the server with python manage.py runserver command. Click the HTTP link that appears in the terminal, and now you should be able to see the login screen for the admin.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F72w7zg7j6xj1cn8k53i1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F72w7zg7j6xj1cn8k53i1.jpg" alt="Admin Log in"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Log in with your username and password. You will see the admin homepage next.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F69vgz5a8b0zhc4eibga4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F69vgz5a8b0zhc4eibga4.jpg" alt="Admin HomePage"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can immediately see that there is a problem. Our posts app doesn't feature here. For us to see our app inside the Django admin we need to update our admin.py file.&lt;/p&gt;

&lt;p&gt;In your text editor open the admin.py file and type in the following code.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

from django.contrib import admin

from .models import Post

admin.site.register(Post)


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;refresh your browser and you will see that the app now appears.&lt;/p&gt;

&lt;p&gt;Since that's done let's create our first post. Click on the add button opposite &lt;em&gt;Posts&lt;/em&gt; and type any message of choice (could be a quote, instruction, or gibberish) in the &lt;em&gt;Text&lt;/em&gt; field.&lt;/p&gt;

&lt;p&gt;Then click the &lt;em&gt;Save&lt;/em&gt; button. You will be redirected to the main post page.&lt;/p&gt;

&lt;p&gt;You will note that our new entry is called "Post object". Let's change that. Within the models.py file add a new function &lt;strong&gt;str&lt;/strong&gt; like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

from django.db import models

class Post(models.Model):
    text = models.TextField()

    def __str__(self):
        return self.text[:50]


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will display the first 50 characters of our text field.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating Views/Templates/URLs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For us to be able to display database content on our homepage, we have to put our views, templates, and URLs together.&lt;/p&gt;

&lt;p&gt;Lets begin with the view. In the views.py file enter the code below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

from django.views.generic import ListView
from .models import Post


Class HomePageView(ListView):
    model = Post
    template_name = 'home.html'



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the code we first imported ListView then we imported the post model. In the view, we subclass ListView and specify the correct model and template.&lt;/p&gt;

&lt;p&gt;We now need to configure our URLs and make our template. We begin with the template. Within your terminal create a new directory called templates and within the template a home.html file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

$ mkdir templates
$ touch templates/home.html


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now update the DIRS field in our settings.py file like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

TEMPLATES = [
    {
       'DIRS': [os.path.join(BASE_DIR, 'templates')],

},

]


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In our home.html we will create our own variable called post and then access the desired field to be displayed as post.text:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;h1&amp;gt;Message board homepage&amp;lt;/h1&amp;gt;
&amp;lt;ul&amp;gt;
  {% for post in object_list %}
  &amp;lt;li&amp;gt;{{ post.text }}&amp;lt;/li&amp;gt;
{% endfor %}
&amp;lt;/ul&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The name object_list isn't that friendly. Instead, we can provide an explicit name via the context_object_name attribute.&lt;/p&gt;

&lt;p&gt;In our views.py file, add the following:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;context_object_name = 'all_posts_list'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Declaring the name like this helps other members of a team.&lt;/p&gt;

&lt;p&gt;Let's also update our template in home.html so that it references all_posts_list rather than object_list.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;h1&amp;gt;Message board homepage&amp;lt;/h1&amp;gt;
&amp;lt;ul&amp;gt;
  {% for post in all_posts_list %}
  &amp;lt;li&amp;gt;{{ post.text }}&amp;lt;/li&amp;gt;
{% endfor %}
&amp;lt;/ul&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Lastly, let us set up our URL configurations. Do this by adding the code below in our urls.py. We simply add &lt;em&gt;posts&lt;/em&gt; and &lt;em&gt;include&lt;/em&gt; on the second lines.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

from django.urls import path, include

path('' include('posts.urls')),


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then create an app level urls.py file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ touch posts/urls.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;then update it like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

from django.urls import path

from .views import HomePageView

urlpatterns = [
   path('', HomePageView.as_view(), name='home'),
]


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Restart the server with python manage.py runserver and navigate to our homepage using the http link in the terminal.&lt;/p&gt;

&lt;p&gt;WOW! we are all done here, congratulations on making it to the end. You can now add more posts through the Django admin and see how the posts appear. Happy Hacking Ya'll!. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>python</category>
      <category>django</category>
    </item>
    <item>
      <title>WHAT IS HELMETjs?</title>
      <dc:creator>Martin Kobimbo</dc:creator>
      <pubDate>Thu, 28 Dec 2023 13:41:51 +0000</pubDate>
      <link>https://dev.to/mkobimbo/what-is-helmetjs-1nbd</link>
      <guid>https://dev.to/mkobimbo/what-is-helmetjs-1nbd</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In our modern online world, where the creation and launching of websites are on the rise, having strong security measures is not optional, cyber-attacks are a big problem for businesses and the developers that build apps for these businesses, exploiting weaknesses in businesses. &lt;/p&gt;

&lt;p&gt;With this environment in mind, helmetjs a javascript framework has emerged as one of the best frontline defenses—intent on safeguarding express apps from a myriad of attacks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fundamentals of Express.js and middleware concept&lt;/li&gt;
&lt;li&gt;Basic understanding of HTTP headers and their significance in web security&lt;/li&gt;
&lt;li&gt;JavaScript and Node.js familiarity for implementation aspects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;So what exactly is Helmet.js&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's think of helmetjs as a guardian to our web app. Imagine that our app is a house with doors and windows, sometimes we forget to close a window or close a door and this leaves the house vulnerable to would-be thieves and robbers.&lt;/p&gt;

&lt;p&gt;Helmetjs automatically closes these entry points on our web app. Helmetjs implements an array of security measures like ensuring that all windows and doors, and makes sure they are locked tight. This makes it much harder for hackers to have a field day inside our application. &lt;/p&gt;

&lt;p&gt;Helmet.js is like a security guard that protects your application by setting up safety measures automatically, so you don't have to manually secure each part of your app. It makes sure your application is as safe and secure as it can be.&lt;/p&gt;

&lt;p&gt;Helmet.js at its heart is made up of several smaller middleware functions, with each one focusing on a particular part of web security. These middleware functions work by modifying HTTP headers to improve protection against different kinds of attacks. &lt;/p&gt;

&lt;p&gt;The core idea is that Helmet.js bundles together these smaller middleware functions, each targeting a specific web security issue, to provide an overall robust defense through manipulating HTTP headers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;helmetjs middlewares and their role in mitigating attacks&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Content Security Policy (CSP):&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can think of the content security policy as a guest list for a bash party. On the guest list are the only people who can enter. If someone is not on the list they can not get in. &lt;/p&gt;

&lt;p&gt;Conversely, the csp lists where resources can come from your app, keeping out uninvited “code guests” that may cause trouble. &lt;/p&gt;

&lt;p&gt;This helps stop sneaky attacks like Cross-Site Scripting (XSS) where bad code is injected into your site. Helmet.js can easily set up these rules for your app, making sure only trusted sources can be used&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;X-Content-Type-Options:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At times browsers try to guess the kind of content on a page. This guessing can be exploited by hackers. Helmetjs protects against attacks that may come as a result of this by telling the browser not to guess the content type.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Strict-Transport-Security:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Attacks like protocol downgrades and cookie hijacking are mitigated by HTTP strict transport policy or hsts in short. This web security policy ensures browsers do not use insecure HTTP.&lt;/p&gt;

&lt;p&gt;It's like always taking the secure roads and streets to your home and sticking to that path come rain or sunshine. Helmet js makes sure the most unsafe paths for data travel are never used.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;X-Frame-Options:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It is so easy for an attacker to put your page HTML documents inside a , which results in clickjacking attacks. Clickjacking is a way of tricking users into with pages that are different from what the users think they are. &lt;/p&gt;

&lt;p&gt;By iframing attackers can put different layers over your web pages and buttons that you can't see are used to run bad scripts. Imagine your website as a painting. Someone can hide your painting inside a bigger frame and display it without your permission.  &lt;/p&gt;

&lt;p&gt;Helmet.js sets a rule that says, "Don't let anyone put my website in a hidden frame," to prevent these tricks.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Referrer-Policy:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Protecting against data leakage. Clicking links on websites results in data about where you came from being sent out. Helmet.js sets rules to limit how much info about where you were before coming to a page is shared. &lt;/p&gt;

&lt;p&gt;It's like when you recommend a book to a friend but don't want to give away the entire plot. You share just enough for them to get interested but not so much that it spoils the story. &lt;/p&gt;

&lt;p&gt;Referrer-Policy controls how much information about where you've been before visiting a page is shared, protecting your browsing history like a well-kept secret.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Helmet.js is like a superhero for websites, making them safer from bad guys on the internet. It automatically locks doors and windows to stop hackers from sneaking in, protecting against tricks like putting your site in a hidden frame or adding harmful code. &lt;/p&gt;

&lt;p&gt;By doing this, Helmet.js keeps your website safe and secure, so you can focus on making it awesome without worrying about cyber troublemakers.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to create email templates in django</title>
      <dc:creator>Martin Kobimbo</dc:creator>
      <pubDate>Wed, 27 Dec 2023 23:16:18 +0000</pubDate>
      <link>https://dev.to/mkobimbo/how-to-create-email-templates-in-django-3lkl</link>
      <guid>https://dev.to/mkobimbo/how-to-create-email-templates-in-django-3lkl</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
Django is a popular and capable Python web development framework that simplifies building web apps. One of Django's many useful capabilities is its strong tools for sending emails.&lt;/p&gt;

&lt;p&gt;With Django, you can set up email backends and make reusable HTML email templates for your app. In this blog article, we'll go through how to make HTML email templates in Django and send emails using those templates.&lt;/p&gt;

&lt;p&gt;Emailing users is a frequent activity for many web applications. You may need to send emails for account verification, password resets, invoices, and more. &lt;/p&gt;

&lt;p&gt;Creating unique HTML emails from scratch for every situation can be tiresome and time-intensive. This is where templates are useful! With templates, you can make your base email HTML once and reuse it for all emails.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;br&gt;
Terminal/ Command line&lt;br&gt;
Python&lt;br&gt;
Intermediate Django&lt;br&gt;
HTML&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Configuring email settings&lt;/strong&gt;&lt;br&gt;
To begin making templates, we first need to set up Django's email backend configurations. These settings tell Django how to send emails. The most popular method is to use SMTP and connect Django to an external email provider such as Mailgun, SendGrid, Amazon SES, or your own SMTP server.&lt;/p&gt;

&lt;p&gt;The email backend settings can be specified in Django's settings.py file. For example, here is how to configure SMTP with Mailgun:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.mailgun.org'  
EMAIL_HOST_USER = 'your-mailgun-username'
EMAIL_HOST_PASSWORD = 'your-mailgun-password'
EMAIL_PORT = 587 
EMAIL_USE_TLS = True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This connects Django to Mailgun for sending emails. Make sure to use your own Mailgun credentials. You can use a similar approach for other SMTP providers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating templates&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After configuring your email backend, you can start creating templates. Email templates in Django are just normal Django templates that live under a templates/registration/ directory in your app.&lt;/p&gt;

&lt;p&gt;an example email_template.html under templates/registration/:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;title&amp;gt;My Email Template&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;p&amp;gt;Hi {{ name }},&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;This is a test email template from my Django app. Welcome!&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;Thanks,&amp;lt;br&amp;gt;  
The App Team
&amp;lt;/p&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a simple HTML template that we can reuse for all emails.  We can insert variables like &lt;code&gt;{{ name }}&lt;/code&gt; that get replaced dynamically when sending emails.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sending templated emails in django views&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once the template is set up, utilizing it in the views is easy. First, bring in render_to_string to render the template as a string:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.core.mail import EmailMultiAlternatives 
from django.template.loader import render_to_string

# Render template as a string
html_content = render_to_string('registration/email_template.html', {'name': 'John'})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Afterward, make an EmailMultiAlternatives instance, add the rendered template to it, and invoke the .send() method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;msg = EmailMultiAlternatives(
subject='Test Email',
body='This is a test',
from_email='from@example.com',
to=['to@example.com']
)
msg.attach_alternative(html_content, 'text/html')

msg.send()


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All done!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The ability to rapidly generate and send email templates is essential for most web applications built with Django. Thanks to Django's robust email backends and template engine, sending customizable HTML emails is easy. To start, you need to set up your email settings. Next, build reusable templates. &lt;/p&gt;

&lt;p&gt;Then, leverage Django's EmailMultiAlternatives class in your views to send template emails. On top of that, adhere to best practices such as using table layouts and testing across email clients for the most robust emails.&lt;/p&gt;

&lt;p&gt;In summary, with some configuration and planning, sending great emails with Django is straightforward.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
      <category>python</category>
      <category>django</category>
    </item>
    <item>
      <title>Python Generators: The Magic of On-Demand Delivery</title>
      <dc:creator>Martin Kobimbo</dc:creator>
      <pubDate>Fri, 15 Dec 2023 09:40:32 +0000</pubDate>
      <link>https://dev.to/mkobimbo/python-generators-the-magic-of-on-demand-delivery-51d4</link>
      <guid>https://dev.to/mkobimbo/python-generators-the-magic-of-on-demand-delivery-51d4</guid>
      <description>&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before diving into Python generators, understanding Python fundamentals—variables, functions, and iteration—is recommended. Basic concepts like loops, data types, and function calls will aid in grasping how generators operate within Python&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How generators work&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine entering a mystical bakery where the pastry chef prepares every delicious dessert fresh, just for you, instead of prebaking them all. This is similar to how Python generators operate in that each item is generated precisely when needed rather than creating everything at once.&lt;/p&gt;

&lt;p&gt;It's like ordering a set meal in standard Python functions—everything is provided to you at once. Generators, meanwhile, are like being at a buffet where the chef is preparing food as you are pointing to it. A generator function does not execute all of the stages at once when you call it. Instead, it uses the 'yield' keyword to begin creating objects when you ask for them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def infinite_sequence():
    num = 0
    while True:
        yield num
        num += 1

gen = infinite_sequence()

print(next(gen))  # Outputs: 0
print(next(gen))  # Outputs: 1
print(next(gen))  # Outputs: 2
# ...and so on

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code snippet demonstrates a generator function infinite_sequence() that generates an infinite sequence of numbers. Instead of creating a massive list of numbers upfront, it generates them one by one as needed. Each time next() is called on the generator object, it yields the next number in the sequence.&lt;/p&gt;

&lt;p&gt;Generators are indispensable in several programming scenarios, serving as invaluable tools in data-intensive tasks. They find frequent application in:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Working with Large Datasets: Generators are excellent for processing large datasets that can't fit entirely into memory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stream Processing: Real-time data streams from sensors, network connections, or continuous log files can be efficiently handled using generators.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Efficient Iteration: Generators offer memory-efficient iteration when dealing with collections like lists, sets, or dictionaries.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Parallel Processing and Pipelining: They allow the creation of data processing pipelines, ideal for complex workflows.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Memory Optimization: Generators significantly reduce memory usage by generating values on-the-fly.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Generators let you work with enormous volumes of data or infinite sequences without taxing the memory of your system, much like magicians creating objects out of thin air. Programming becomes a bit more magical and a lot more efficient with Python's generators, which provide an amazing way to manage resources efficiently and complete complicated jobs with ease!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>EVENTS AND EVENT LISTENERS EXPLAINED TO A DUCK quack quack!!</title>
      <dc:creator>Martin Kobimbo</dc:creator>
      <pubDate>Wed, 15 Nov 2023 11:53:07 +0000</pubDate>
      <link>https://dev.to/mkobimbo/events-and-event-listeners-explained-to-a-duck-quack-quack-36en</link>
      <guid>https://dev.to/mkobimbo/events-and-event-listeners-explained-to-a-duck-quack-quack-36en</guid>
      <description>&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;br&gt;
Knowledge of HTML&lt;br&gt;
Javascript functions&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
Hello there! my duck friends, imagine floating in the middle of a pond or lake, taking in the cool breeze and enjoying the sunshine. Think of event listeners as your ability to notice things happening to you.&lt;/p&gt;

&lt;p&gt;let's say you are floating close to the shores and someone throws in some tasty pieces of bread. When those pieces of bread hit the water you react by swimming towards them quickly. those pieces of bread hitting the water are events and your reaction toward them is similar to how event listeners work.&lt;/p&gt;

&lt;p&gt;So we can say events are things that happen in your programming system e.g. a user selects, clicks, or hovers the cursor over an element. Either pausing, playing, or ending a video. An event listener is a block of code in JavaScript that waits for an event to occur and then responds to it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Quack-tastic event listeners for ducky ducks.
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Paying Attention&lt;br&gt;
Just like you pay attention to the pieces of bread hitting the water, event listeners focus on specific things happening on a webpage, like a click or a key being pressed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reacting to Events&lt;br&gt;
When someone throws pieces of bread, you immediately swim towards them, right? Similarly, when an event happens on a web page (like a click on a button), the event listener reacts by doing something—like making the page do a fun animation or changing the color of an element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Different Types of Events&lt;br&gt;
Just as there can be different things happening around the pond (like kids playing, birds chirping, etc.), event listeners can listen for various events: clicks, mouse movements, keyboard presses, and more.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Listening Skills&lt;br&gt;
You're not only attentive to just one type of bread; you react to any kind of bread someone tosses your way. Event listeners are flexible—they can listen for different types of events on various elements of a webpage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ready, Set, React!&lt;br&gt;
Imagine someone threw bread near your pond but not directly at you. You'd notice it and swim over, right? That's like event bubbling in JavaScript—events start from a specific element and can affect its parent elements, too.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Event listener example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;in our code below,&lt;br&gt;
The HTML file contains a button element with the ID "myButton".&lt;/p&gt;

&lt;p&gt;In the JavaScript file, we select the button using document.getElementById.&lt;/p&gt;

&lt;p&gt;We define a function changeText() that changes the text content of the button to 'Good ducky!'.&lt;/p&gt;

&lt;p&gt;We attach an event listener to the button using addEventListener. This listener listens for a 'click' event on the button and triggers the changeText() function when the button is clicked.&lt;/p&gt;

&lt;p&gt;When you open this in a web browser, clicking the button will change its text from "Say Quack!" to "Good ducky!".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;

  &amp;lt;button id="myButton"&amp;gt;Say Quack!&amp;lt;/button&amp;gt;

  &amp;lt;script src="script.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const button = document.getElementById('myButton');

function changeText() {
  button.textContent = 'Good ducky!';
}

button.addEventListener('click', changeText);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and there you have it, have a quack-tastic day my duckie friend.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>SETTING UP TAILWINDCSS LIKE A PRO</title>
      <dc:creator>Martin Kobimbo</dc:creator>
      <pubDate>Mon, 13 Nov 2023 19:46:56 +0000</pubDate>
      <link>https://dev.to/mkobimbo/setting-up-tailwindcss-like-a-pro-ag3</link>
      <guid>https://dev.to/mkobimbo/setting-up-tailwindcss-like-a-pro-ag3</guid>
      <description>&lt;h2&gt;
  
  
  THE BEST WAY TO SET UP TAILWIND FOR VARIOUS JAVASCRIPT FRAMEWORKS USING VITE
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;PREREQUISITES&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Basic knowledge of CSS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Knowledge of HTML&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Basic command line interface skills&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Setting up tailwind with a play CDN link tag&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's first explore the basic way of installing tailwind.&lt;/p&gt;

&lt;p&gt;First, let's open up VScode in a blank directory and create an “index.html” file. Inside the file, we can type in the exclamation mark “!” and then click “enter”.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we have a basic scaffolding or boilerplate. For us to observe the changes in our dev server/ live server, let's add an “h1” tag with the text “hello world” to the body.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
&amp;lt;h1&amp;gt;Hello World&amp;lt;/h1&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can now grab this link "&lt;a href="https://cdn.tailwindcss.com"&gt;https://cdn.tailwindcss.com&lt;/a&gt;", which is also available at the tailwindcss.com website. let's paste it inside the head of our HTML in a script tag.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;script src="https://cdn.tailwindcss.com"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To open up the live server in a browser window, at the bottom right of our vscode window there is a text that says "Go live", click it. In our dev server/ live server notice how our font size and font family on the “hello world” text have changed. This shows us that our tailwind is working. You can add a few tailwind utility classes to our h1 tag just as a demo. &lt;/p&gt;

&lt;p&gt;Note that using tailwind via the CDN is not the best choice, since we cannot customize the tailwind default theme, use any directives like @apply, enable additional variants, install third-party plugins, and can't tree shake unused styles. This all means that we can't control the output of this tailwind file. The CDN is mostly used to try tailwindcss as a demo. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting up TailwindCss using react with vite&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Vite is a super fast frontend build tool that will take our index.html file as an entry point, run tailwind through PostCSS, and also give us a dev server that will update every time we make any changes.&lt;/p&gt;

&lt;p&gt;You can create your react project with Vite by typing these two commands in your terminal,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm create vite@latest my-project -- --template react
cd my-project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;type these two commands to install tailwind to your project,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this will also generate a tailwind.config.js file and a postcss.config.js file for you. The tailwind.config file allows you to customize your designs.&lt;/p&gt;

&lt;p&gt;Next, let's configure our template paths. Simply put "Imagine you're building a colorful LEGO castle, and you want to find the perfect pieces in your LEGO box. Configuring template paths in Tailwind CSS is like telling your friend exactly where to look in the box to find the right LEGO pieces for your castle. It helps Tailwind know where to find the styles it needs, making your website look just the way you want it!" To do that let's add this block of code to our tailwind.config file,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;content: [
    "./index.html",
    "./src/**/*.{js,ts,jsx,tsx}",
  ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we will have this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/** @type {import('tailwindcss').Config} */
export default {
  content: [
    "./index.html",
    "./src/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;let's locate an index.css file and these tailwind directives,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@tailwind base;
@tailwind components;
@tailwind utilities;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your terminal, we can then type the command &lt;code&gt;npm run dev&lt;/code&gt; to open up a dev server. Now you can add a few utility classes to your jsx.&lt;/p&gt;

&lt;p&gt;And there you have it, we have successfully installed tailwindcss! You can now practice with any projects of your liking. Make sure to always use tailwindcss with a frontend build tool like Vite in order to get support for postcss. This will allow you to create your customized designs. Happy Coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>css</category>
    </item>
  </channel>
</rss>
