<?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: Shriyaaa.10</title>
    <description>The latest articles on DEV Community by Shriyaaa.10 (@shriyaexe).</description>
    <link>https://dev.to/shriyaexe</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%2F1273171%2F48407cc3-f6db-43c3-be36-32b75496c371.jpeg</url>
      <title>DEV Community: Shriyaaa.10</title>
      <link>https://dev.to/shriyaexe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shriyaexe"/>
    <language>en</language>
    <item>
      <title>Understanding Database Indexing: A Guide with SQL Examples</title>
      <dc:creator>Shriyaaa.10</dc:creator>
      <pubDate>Sat, 14 Dec 2024 06:57:15 +0000</pubDate>
      <link>https://dev.to/shriyaexe/understanding-database-indexing-a-guide-with-sql-examples-17ik</link>
      <guid>https://dev.to/shriyaexe/understanding-database-indexing-a-guide-with-sql-examples-17ik</guid>
      <description>&lt;p&gt;Efficient database management is crucial for applications that handle large volumes of data. One key technique to improve query performance is database indexing. This article explores what database indexing is, why it is important, and how to implement it using SQL.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Database Indexing?
&lt;/h2&gt;

&lt;p&gt;Database indexing is a data structure technique that improves the speed of data retrieval operations in a database. An index is essentially a smaller, more efficient lookup table that references the primary table.&lt;/p&gt;

&lt;p&gt;Indexes are commonly compared to an index in a book—instead of flipping through every page to find a topic, you can quickly navigate to the rig&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use Indexes?
&lt;/h2&gt;

&lt;p&gt;Indexes can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Accelerate queries by reducing the amount of data the database needs to scan.&lt;/li&gt;
&lt;li&gt;Ensure uniqueness (e.g., with unique indexes).&lt;/li&gt;
&lt;li&gt;Speed up sorting and filtering.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Types of Indexes
&lt;/h2&gt;

&lt;p&gt;1 - Single-column Index: Indexes based on a single column.&lt;br&gt;
2 - Composite Index: Indexes based on multiple columns.&lt;br&gt;
3 - Unique Index: Ensures that all values in the indexed column(s) are unique.&lt;br&gt;
4 - Clustered Index: Determines the physical order of data in a table (commonly used in primary keys).&lt;br&gt;
5 - Non-clustered Index: A separate structure that references the table’s data.&lt;/p&gt;
&lt;h2&gt;
  
  
  Example of Database Indexing
&lt;/h2&gt;

&lt;p&gt;Consider a products table with the following columns: &lt;code&gt;product_id&lt;/code&gt;, &lt;code&gt;product_name&lt;/code&gt;, &lt;code&gt;price&lt;/code&gt;, and &lt;code&gt;category&lt;/code&gt;. A common query might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM products
WHERE product_name = 'Laptop';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If there is no index on the &lt;code&gt;product_name&lt;/code&gt; column, the database performs a full table scan, checking every row to find matches. This can be slow, especially if the table contains thousands or millions of rows.&lt;/p&gt;

&lt;p&gt;To improve performance, you can create an index on the product_name column:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE INDEX idx_product_name
ON products (product_name);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, when the same query is executed, the database uses the index to locate rows with &lt;code&gt;product_name = 'Laptop'&lt;/code&gt;, significantly reducing the amount of data scanned.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Practices for Indexing
&lt;/h2&gt;

&lt;p&gt;1 - Index frequently queried columns: Columns used in WHERE, JOIN, and ORDER BY clauses are good candidates.&lt;/p&gt;

&lt;p&gt;2 - Avoid over-indexing: Too many indexes can slow down write operations and increase storage.&lt;/p&gt;

&lt;p&gt;3 - Monitor and maintain indexes: Regularly analyze and rebuild fragmented indexes to maintain efficiency.&lt;/p&gt;

&lt;p&gt;4 - Use composite indexes wisely: Order columns in a composite index based on query patterns.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Database indexing is a powerful tool to optimize query performance, but it requires careful planning and monitoring. By understanding how and when to use indexes, developers can significantly improve the efficiency of their applications. Use the SQL examples in this article as a starting point to implement and manage indexes effectively in your projects.&lt;/p&gt;

</description>
      <category>indexing</category>
      <category>database</category>
    </item>
    <item>
      <title>Test-Driven Development (TDD) in Django</title>
      <dc:creator>Shriyaaa.10</dc:creator>
      <pubDate>Fri, 27 Sep 2024 14:05:48 +0000</pubDate>
      <link>https://dev.to/shriyaexe/test-driven-development-tdd-in-django-12ad</link>
      <guid>https://dev.to/shriyaexe/test-driven-development-tdd-in-django-12ad</guid>
      <description>&lt;p&gt;Test-Driven Development (TDD) is a software development practice that prioritizes writing tests before the actual code. In the Django ecosystem, TDD helps ensure that your code works as expected from the beginning while keeping the development cycle efficient and manageable. This post will explore why implementing TDD in Django is beneficial, and how to practically implement it in a Django project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Use TDD in Django?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Better Code Quality&lt;/strong&gt; By writing tests first, you are forced to think about the requirements and behavior of your code before implementation. This leads to cleaner, more focused, and often simpler code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Faster Debugging&lt;/strong&gt; When you have a solid test suite, identifying bugs and tracking down the root cause becomes much easier. Since each part of the system is continuously tested, you can easily pinpoint where things break.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Increased Confidence in Refactoring&lt;/strong&gt; Refactoring is an essential part of development, but it can introduce bugs. TDD allows you to refactor code with confidence, knowing that your test suite will catch any regressions.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Implement TDD in a Django Project
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Set up Your Django Project&lt;/strong&gt;&lt;br&gt;
Start by creating a new Django project and app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;django-admin startproject myproject
&lt;span class="nb"&gt;cd &lt;/span&gt;myproject
python manage.py startapp myapp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Create a Test for Your First Feature&lt;/strong&gt;&lt;br&gt;
Before writing any feature code, write a test that describes how the code should behave. For example, if you're implementing a homepage, write a test that checks if the homepage loads successfully.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# myapp/tests.py&lt;/span&gt;
from django.test import TestCase
from django.urls import reverse

class HomePageTest&lt;span class="o"&gt;(&lt;/span&gt;TestCase&lt;span class="o"&gt;)&lt;/span&gt;:
    def test_homepage_status_code&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt;:
        response &lt;span class="o"&gt;=&lt;/span&gt; self.client.get&lt;span class="o"&gt;(&lt;/span&gt;reverse&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'home'&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
        self.assertEqual&lt;span class="o"&gt;(&lt;/span&gt;response.status_code, 200&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this test, we are checking if the homepage responds with a status code of 200 (OK).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Run the Test and Watch It Fail&lt;/strong&gt;&lt;br&gt;
Since we haven’t implemented the homepage yet, the test will fail. Run the test using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python manage.py &lt;span class="nb"&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The failing test is a signal that you need to implement the homepage functionality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Write the Minimal Code to Pass the Test&lt;/strong&gt;&lt;br&gt;
Now, write the minimal amount of code needed to pass the failing test. For instance, you can define a simple view that returns a basic template.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# myapp/views.py&lt;/span&gt;
from django.shortcuts import render

def home&lt;span class="o"&gt;(&lt;/span&gt;request&lt;span class="o"&gt;)&lt;/span&gt;:
    &lt;span class="k"&gt;return &lt;/span&gt;render&lt;span class="o"&gt;(&lt;/span&gt;request, &lt;span class="s1"&gt;'home.html'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;# myapp/urls.py&lt;/span&gt;
from django.urls import path
from .views import home

urlpatterns &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
    path&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;''&lt;/span&gt;, home, &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'home'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;,
&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a simple template:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt; templates/home.html &lt;span class="nt"&gt;--&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&amp;lt;h1&amp;gt;Welcome to the Home Page&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5: Run the Test Again&lt;/strong&gt;&lt;br&gt;
After implementing the homepage, run the test again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python manage.py &lt;span class="nb"&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This time, the test should pass, confirming that your feature works as expected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Refactor and Rerun Tests&lt;/strong&gt;&lt;br&gt;
With your test passing, you can now refactor the code for better structure or readability, knowing that your tests will catch any mistakes introduced during the refactor.&lt;/p&gt;

&lt;h3&gt;
  
  
  Best Practices for TDD in Django
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Write Small, Incremental&lt;/strong&gt; Tests Start with the simplest test case and gradually add more complex tests as you expand the functionality of your application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Django’s Built-in Testing Tools&lt;/strong&gt; Django comes with an excellent testing framework out of the box, so leverage its TestCase class and other built-in utilities such as the test client to write your tests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Focus on Functional Tests First&lt;/strong&gt; Begin by writing functional tests (also called integration tests) that ensure the whole system works together. Then move on to unit tests for smaller components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep Tests Fast and Independent Fast&lt;/strong&gt; tests are more likely to be run frequently, so keep them lightweight and independent of each other. Avoid relying on external resources like the internet or a live database unless absolutely necessary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Run Tests Frequently&lt;/strong&gt; Running tests frequently (e.g., before and after every feature addition or code change) helps you identify issues early, when they are easier to fix.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Test-Driven Development is a powerful methodology that enhances code quality, simplifies debugging, and increases confidence in refactoring. In Django, implementing TDD is straightforward due to its built-in testing framework and utilities. By adopting TDD, you’ll ensure that your code remains clean, functional, and maintainable throughout the project lifecycle.&lt;/p&gt;

&lt;p&gt;If you haven’t already, try implementing TDD in your next Django project and experience the benefits firsthand.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React Styled Components</title>
      <dc:creator>Shriyaaa.10</dc:creator>
      <pubDate>Fri, 26 Jul 2024 20:14:14 +0000</pubDate>
      <link>https://dev.to/shriyaexe/react-styled-components-34eg</link>
      <guid>https://dev.to/shriyaexe/react-styled-components-34eg</guid>
      <description>&lt;h2&gt;
  
  
  What Are Styled Components?
&lt;/h2&gt;

&lt;p&gt;Styled Components is a popular library for React that allows developers to write CSS directly within their JavaScript code. This library leverages tagged template literals to style your components. It promotes the use of component-level styles, helping to keep the concerns of styling and element structure separated and making the overall code more maintainable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of Using Styled Components
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Dynamic Styling:&lt;/strong&gt; Styled Components allows you to use JavaScript to dynamically set styles based on props, state, or any other variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Better Organization:&lt;/strong&gt; Keeping styles close to the components they affect makes your code more modular and easier to manage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. No Class Name Bugs:&lt;/strong&gt; Since styles are scoped to components, you won't have to worry about class name collisions or the specificity issues that are common with traditional CSS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Theming Support:&lt;/strong&gt; Styled Components offers built-in support for theming, making it easy to apply consistent styles across your application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing Styled Components
&lt;/h3&gt;

&lt;p&gt;To start using Styled Components, you need to install it via npm or yarn:&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 styled-components

or

yarn add styled-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Basic Usage
&lt;/h3&gt;

&lt;p&gt;Here’s a basic example to illustrate how Styled Components works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import styled from "styled-components";

// Styled component named StyledButton
const StyledButton = styled.button`
  background-color: black;
  font-size: 32px;
  color: white;
`;

function Component() {
  // Use it like any other component.
  return &amp;lt;StyledButton&amp;gt; Login &amp;lt;/StyledButton&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Adapting Based on Props
&lt;/h3&gt;

&lt;p&gt;Styled components are functional, so we can easily style elements dynamically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import styled from "styled-components";

const StyledButton = styled.button`
  min-width: 200px;
  border: none;
  font-size: 18px;
  padding: 7px 10px;
  /* The resulting background color will be based on the bg props. */
  background-color: ${props =&amp;gt; props.bg === "black" ? "black" : "blue";
`;

function Profile() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;StyledButton bg="black"&amp;gt;Button A&amp;lt;/StyledButton&amp;gt;
      &amp;lt;StyledButton bg="blue"&amp;gt;Button B&amp;lt;/StyledButton&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Theming
&lt;/h3&gt;

&lt;p&gt;Styled Components also supports theming, allowing you to define a set of styles (like colors, fonts, etc.) and apply them consistently throughout your application.&lt;/p&gt;

&lt;p&gt;First, you define your theme:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ThemeProvider } from 'styled-components';

const theme = {
  primary: 'blue',
  secondary: 'gray',
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, wrap your application with the ThemeProvider and pass your theme:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const App = () =&amp;gt; (
  &amp;lt;ThemeProvider theme={theme}&amp;gt;
    &amp;lt;div&amp;gt;
      &amp;lt;Button primary&amp;gt;Primary Button&amp;lt;/Button&amp;gt;
      &amp;lt;Button&amp;gt;Default Button&amp;lt;/Button&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/ThemeProvider&amp;gt;
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, access the theme properties in your styled components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Button = styled.button`
  background: ${(props) =&amp;gt; (props.primary ? props.theme.primary : props.theme.secondary)};
  color: white;
  font-size: 1em;
  margin: 1em;
  padding: 0.25em 1em;
  border: 2px solid ${(props) =&amp;gt; props.theme.primary};
  border-radius: 3px;
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Styled Components is a powerful tool for React developers looking to improve the maintainability and scalability of their applications. By encapsulating styles within components and leveraging the full power of JavaScript, Styled Components provides a modern and efficient approach to styling web applications. Whether you are working on a small project or a large-scale application, Styled Components can help you keep your styles organized and your code clean.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>react</category>
      <category>ui</category>
    </item>
    <item>
      <title>Guide to Writing Clean Code: Part 1</title>
      <dc:creator>Shriyaaa.10</dc:creator>
      <pubDate>Wed, 17 Jul 2024 09:14:45 +0000</pubDate>
      <link>https://dev.to/shriyaexe/guide-to-writing-clean-code-part-1-1bgg</link>
      <guid>https://dev.to/shriyaexe/guide-to-writing-clean-code-part-1-1bgg</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Writing clean code is an essential skill for any software developer. Clean code is not just about making your code look good; it's about making it understandable, maintainable, and scalable. This guide will cover the fundamental principles of writing clean code, focusing on clarity, simplicity, and efficiency. This first part will address naming conventions, code structure, and commenting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Naming Conventions
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Variables and Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Use Descriptive Names:&lt;/strong&gt; Choose names that clearly describe the variable's purpose or the function's action. Avoid abbreviations unless they are widely understood.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Bad
int x = 5;

# Good
int userAge = 5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Consistency:&lt;/strong&gt; Stick to a consistent naming convention throughout your codebase. Popular conventions include camelCase, PascalCase, and snake_case.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# camelCase
int userAge = 25;

# PascalCase
int UserAge = 25;

# snake_case
int user_age = 25;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Avoid Magic Numbers and Strings:&lt;/strong&gt; Use named constants instead of hardcoding numbers and strings. This improves readability and makes maintenance easier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Bad
int discount = price * 0.05;

# Good
const float DISCOUNT_RATE = 0.05;
int discount = price * DISCOUNT_RATE;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Code Structure
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Single Responsibility Principle:&lt;/strong&gt; Each function should perform a single task. This makes functions easier to understand, test, and maintain.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Bad
def processOrder(order):
    validateOrder(order)
    processPayment(order)
    shipOrder(order)

# Good
def validateOrder(order):
    # validation logic

def processPayment(order):
    # payment processing logic

def shipOrder(order):
    # shipping logic

def processOrder(order):
    validateOrder(order)
    processPayment(order)
    shipOrder(order)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Small Functions:&lt;/strong&gt; Keep functions short and focused. If a function exceeds 20-30 lines, consider breaking it down into smaller functions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Use Default Arguments and Named Parameters:&lt;/strong&gt; This enhances the readability and flexibility of your functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Default Arguments
def createUser(name, role="user"):
    # create user logic

# Named Parameters
createUser(name="Alice", role="admin")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Commenting
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Why, Not What:&lt;/strong&gt; Focus on explaining why a piece of code exists rather than what it does. The code itself should be self-explanatory if written cleanly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Bad
int total = price * quantity;  # multiply price by quantity

# Good
int total = price * quantity;  # calculating the total cost based on the given price and quantity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Keep Comments Up-to-Date:&lt;/strong&gt; Outdated comments can be more misleading than no comments. Ensure that your comments are updated whenever you modify the associated code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Avoid Redundant Comments:&lt;/strong&gt; Don’t state the obvious. Comments should provide additional insight, not reiterate what the code is already doing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Bad
int count = 0;  # set count to zero

# Good
int count = 0;  # initialize counter for tracking the number of users
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Clean code is essential for developing software that is easy to read, understand, and maintain. By following naming conventions, structuring your code properly, and writing meaningful comments, you can significantly improve the quality of your code. In the next part of this guide, we will delve into more advanced topics, such as error handling, code refactoring, and testing.&lt;/p&gt;

&lt;p&gt;Stay tuned for Part 2 :)&lt;/p&gt;

</description>
      <category>cleancode</category>
    </item>
    <item>
      <title>Docker for Beginners</title>
      <dc:creator>Shriyaaa.10</dc:creator>
      <pubDate>Thu, 16 May 2024 18:00:09 +0000</pubDate>
      <link>https://dev.to/shriyaexe/docker-for-beginners-394m</link>
      <guid>https://dev.to/shriyaexe/docker-for-beginners-394m</guid>
      <description>&lt;p&gt;Docker is a tool that helps developers build, ship, and run applications inside containers. Containers are like small, portable boxes that hold everything needed for an app to run, including the code, runtime, libraries, and settings. This makes it easier to develop and deploy applications because they will work the same way on different computers. Docker ensures that once an application is built, it can be run anywhere without any compatibility issues.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Use Docker?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Consistency Across Environments:&lt;/strong&gt; Docker ensures that your application runs the same way regardless of where it is deployed. This eliminates the "works on my machine" problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Scalability:&lt;/strong&gt; Containers can be easily scaled up or down to handle varying loads, making them ideal for applications with fluctuating resource requirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Efficiency:&lt;/strong&gt; Containers are lightweight and start quickly, using fewer resources compared to traditional virtual machines.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Concepts
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Image:&lt;/strong&gt; A Docker image is a lightweight, stand-alone, and executable software package that includes everything needed to run a piece of software. It contains the code, a runtime, libraries, environment variables, and configuration files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Container:&lt;/strong&gt; A container is a running instance of a Docker image. It is an isolated environment where applications run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Dockerfile:&lt;/strong&gt; This is a text file that contains instructions for building a Docker image. It specifies the base image to use, application code, dependencies, and commands to run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Docker Hub:&lt;/strong&gt; A cloud-based repository where Docker images are stored and shared. You can pull images from Docker Hub to use in your projects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting Started with Docker
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Install Docker:&lt;/strong&gt; Docker can be installed on various operating systems including Windows, macOS, and Linux. You can download the Docker Desktop application from the Docker website.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Run Your First Container:&lt;/strong&gt; After installing Docker, you can run a container using a pre-built image from Docker Hub. Open your terminal and type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run hello-world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command downloads the hello-world image and runs a container, which prints a confirmation message.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Create a Dockerfile:&lt;/strong&gt; Create a simple Dockerfile to define a custom image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Use an official Python runtime as a base image
FROM python:3.8-slim-buster

# Set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Make port 80 available to the world outside this container
EXPOSE 80

# Define environment variable
ENV NAME World

# Run app.py when the container launches
CMD ["python", "app.py"]

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

&lt;/div&gt;



&lt;p&gt;This Dockerfile uses a Python base image, sets up the working directory, copies the application code, installs dependencies, and specifies the command to run the application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Build and Run Your Image:&lt;/strong&gt;&lt;br&gt;
Build the Docker image using the Dockerfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t my-python-app .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the container from your image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -p 4000:80 my-python-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This maps port 80 in the container to port 4000 on your host machine, making your application accessible at &lt;a href="http://localhost:4000" rel="noopener noreferrer"&gt;http://localhost:4000&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic Docker Commands
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. docker ps:&lt;/strong&gt; Lists running containers.&lt;br&gt;
&lt;strong&gt;2. docker images:&lt;/strong&gt; Lists all Docker images on your system.&lt;br&gt;
&lt;strong&gt;3. docker stop :&lt;/strong&gt; Stops a running container.&lt;br&gt;
&lt;strong&gt;4. docker rm :&lt;/strong&gt; Removes a container.&lt;br&gt;
&lt;strong&gt;5. docker rmi :&lt;/strong&gt; Removes a Docker image.&lt;/p&gt;

&lt;p&gt;Docker is like a magic box for developers. It makes building and running apps super easy.&lt;/p&gt;

</description>
      <category>docker</category>
    </item>
    <item>
      <title>Optimizing Database Queries in Django Applications</title>
      <dc:creator>Shriyaaa.10</dc:creator>
      <pubDate>Fri, 29 Mar 2024 07:08:14 +0000</pubDate>
      <link>https://dev.to/shriyaexe/optimizing-database-queries-in-django-applications-1i7c</link>
      <guid>https://dev.to/shriyaexe/optimizing-database-queries-in-django-applications-1i7c</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;Efficient database queries are crucial for the performance and scalability of Django applications. In this article, we explore strategies to optimize database queries in Django, enhancing the speed and responsiveness of web applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Query Optimization in Django:
&lt;/h2&gt;

&lt;p&gt;Django's ORM (Object-Relational Mapping) abstracts database interactions, providing a convenient interface for developers. However, inefficient database queries can impact application performance. We delve into the importance of query optimization and its impact on application performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Identifying Performance Bottlenecks:
&lt;/h2&gt;

&lt;p&gt;We discuss common performance bottlenecks in Django applications, such as N+1 queries, excessive database hits, and inefficient query patterns. Understanding these bottlenecks is essential for devising effective optimization strategies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Techniques for Optimizing Database Queries:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Select Related and Prefetch Related&lt;/strong&gt;: We demonstrate how to use select_related and prefetch_related to reduce the number of database hits when fetching related objects, thereby minimizing query overhead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Example of using select_related
author = Author.objects.select_related('profile').get(pk=1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Queryset Optimization&lt;/strong&gt;: We explore techniques for optimizing queryset operations, including filtering, ordering, and pagination, to minimize database load and improve query performance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Example of queryset optimization
books = Book.objects.filter(category='fiction').order_by('-publication_date')[:10]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Indexing&lt;/strong&gt;: We discuss the importance of database indexing and how properly indexed fields can significantly improve query execution time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Example of indexing in Django models
class Book(models.Model):
    title = models.CharField(max_length=100, db_index=True)
    author = models.ForeignKey(Author, on_delete=models.CASCADE)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Testing and Profiling:
&lt;/h2&gt;

&lt;p&gt;We emphasize the significance of testing and profiling database queries to identify performance bottlenecks. Techniques such as Django's built-in testing framework and profiling tools aid in optimizing queries effectively.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-World Example:
&lt;/h2&gt;

&lt;p&gt;We provide a real-world example of optimizing database queries in a Django application, showcasing before-and-after scenarios and the resulting performance improvements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;Optimizing database queries is paramount for the performance and scalability of Django applications. By employing techniques such as query optimization, indexing, and profiling, developers can enhance the efficiency of database interactions, ensuring optimal performance and responsiveness in production environments. Embracing these best practices empowers developers to build high-performance Django applications capable of meeting the demands of modern web environments.&lt;/p&gt;

</description>
      <category>python</category>
      <category>django</category>
    </item>
    <item>
      <title>Navigating Django: A Beginner's Guide to Views and URL Routing</title>
      <dc:creator>Shriyaaa.10</dc:creator>
      <pubDate>Mon, 26 Feb 2024 09:36:16 +0000</pubDate>
      <link>https://dev.to/shriyaexe/navigating-django-a-beginners-guide-to-views-and-url-routing-5gnd</link>
      <guid>https://dev.to/shriyaexe/navigating-django-a-beginners-guide-to-views-and-url-routing-5gnd</guid>
      <description>&lt;p&gt;In Django, views and URL routing are like the map and directions for your web application. Let's keep it simple and see how they work together.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Views in Django:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Views are like mini-programs that handle what happens when someone visits a certain URL. They take a request (like someone clicking a link) and decide what to do with it, then send back a response (like showing a webpage).&lt;br&gt;
Here's a basic view in Django:&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.http import HttpResponse

def hello_world(request):
    return HttpResponse("Hello, World!")

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

&lt;/div&gt;



&lt;p&gt;In this code, hello_world is a view that simply says "Hello, World!" when someone visits a specific URL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;URL Routing in Django:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;URL routing is like a road sign that tells Django which view to use for different URLs. It's how Django knows where to send a request based on the URL someone visits.&lt;/p&gt;

&lt;p&gt;We set up URL routing in a file called urls.py. Here's a simple 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.urls import path
from .views import hello_world

urlpatterns = [
    path('hello/', hello_world),
]

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

&lt;/div&gt;



&lt;p&gt;In this code, we're saying that when someone visits the URL &lt;a href="http://example.com/hello/" rel="noopener noreferrer"&gt;http://example.com/hello/&lt;/a&gt;, Django should use the hello_world view.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Putting It Together:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So, when someone visits &lt;a href="http://example.com/hello/" rel="noopener noreferrer"&gt;http://example.com/hello/&lt;/a&gt;, Django checks the URL routing and sees that it should use the hello_world view. The view then kicks in, saying "Hello, World!" and sending that message back as a response.&lt;/p&gt;

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

&lt;p&gt;Views and URL routing are like a team in Django. Views handle what to do when someone visits a URL, and URL routing tells Django which view to use for each URL.&lt;/p&gt;

&lt;p&gt;By understanding this simple relationship, you can start building your own web applications with Django. Happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>User login with JWT Authentication in Django Rest Framework</title>
      <dc:creator>Shriyaaa.10</dc:creator>
      <pubDate>Sun, 04 Feb 2024 18:11:11 +0000</pubDate>
      <link>https://dev.to/shriyaexe/user-login-with-jwt-authentication-in-django-rest-framework-45of</link>
      <guid>https://dev.to/shriyaexe/user-login-with-jwt-authentication-in-django-rest-framework-45of</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is JWT&lt;/strong&gt;&lt;br&gt;
JWT(Json Wеb Tokеn) is a standard that dеfinеs a way to transmit sеcurе information through tokеns.&lt;/p&gt;

&lt;p&gt;JWTs arе commonly usеd for authеntication an' authorization in wеb applications and APIs and an' microsеrvicеs architеcturеs and includin' frontеnd applications built with tеchnologiеs such as Nеxt.js and Angular and or Rеact. JWTs providе a sеcurе mеans of transmittin' authеntication tokеns bеtwееn thе cliеnt an' thе sеrvеr.&lt;/p&gt;

&lt;p&gt;JWTs can bе signеd publicly or privatеlyA standard JWT looks likе this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;еyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
еyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.
SflKxwRJSMеKKF2QT4fwpMеJf36POk6yJV_adQssw5c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can sее and its structurе is madе up of 3 parts sеparatеd by a pеriod(.) and namеly:&lt;/p&gt;

&lt;p&gt;hеadеr&lt;br&gt;
  payload&lt;br&gt;
  signaturе&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hеadеr:&lt;/strong&gt;&lt;br&gt;
Thе hеadеr is thе first part of a JWT tokеn and an' it idеntifiеs thе algorithm usеd to sign an' vеrify thе signaturе. Signin' algorithms may includе RSA signaturе and HMAC SHA256 and HMAC SHA512 and an' othеrs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Payload:&lt;/strong&gt;&lt;br&gt;
Thе payload is thе sеcond part and an' it contains claims. A claim can includе thе followin':&lt;/p&gt;

&lt;p&gt;A usеr's id.&lt;br&gt;
  Pеrmissions.&lt;br&gt;
  Expiration timе.&lt;br&gt;
  Issuеd at timе.&lt;br&gt;
  Any othеr data rеquirеd by thе application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Signaturе&lt;/strong&gt;&lt;br&gt;
Thе signaturе an' thе third part crеatеs by combinin' thе basе64 еncodеd hеadеr an' basе64 еncodеd payload an' a sеcrеt kеy. Thе signaturе is usеd to vеrify thе authеnticity of thе JWT tokеn.&lt;/p&gt;

&lt;p&gt;All thrее parts arе Basе64Url еncodеd an' concatеnatеd usin' pеriods (“.”) to form a URL strin'&lt;/p&gt;

&lt;p&gt;Whеn a usеr logins to a wеbsitе and thе usеr is authеnticatеd and an' thе sеrvеr gеnеratеs a uniquе JWT tokеn as a rеsponsе. Thе usеr thеn usеs thе tokеn in subsеquеnt rеquеsts by includin' it in thе Authorisation Hеadеr in thе format Authorization: Bеarеr [JWT tokеn].&lt;/p&gt;

&lt;p&gt;Durin' subsеquеnt rеquеsts and thе sеrvеr will continuously vеrify thе tokеn’s authеnticity durin' еach rеquеst.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stеp 1: Install Rеquirеd Packagеs&lt;/strong&gt;&lt;br&gt;
Thе first stеp is to install thе nеcеssary packagеs. Opеn your tеrminal an' run thе followin' command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install djangorеstframеwork djangorеstframеwork_simplеjwt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thеsе packagеs includе Django Rеst Framеwork an' Simplе JWT and which wе'll usе for JWT authеntication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stеp 2: Configurе Django Sеttings&lt;/strong&gt;&lt;br&gt;
Updatе your Django sеttings to includе thе installеd packagеs an' configurе thе authеntication classеs. Opеn your sеttings.py filе an' add thе followin':&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# sеttings.py

INSTALLED_APPS = [
    # ...
    'rеst_framеwork' and
    'rеst_framеwork_simplеjwt' and
]

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rеst_framеwork_simplеjwt.authеntication.JWTAuthеntication' and
    ) and
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configurеs DRF to usе JWT authеntication by dеfault.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stеp 3: Crеatе Usеr Modеl an' Sеrializеr&lt;/strong&gt;&lt;br&gt;
If you don't havе a custom usеr modеl and you can skip this stеp. Othеrwisе and crеatе a custom usеr modеl an' a sеrializеr to handlе usеr data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# modеls.py

from django.contrib.auth.modеls import AbstractUsеr

class CustomUsеr(AbstractUsеr):
    # Your custom fiеlds if any

# sеrializеrs.py

from rеst_framеwork import sеrializеrs
from .modеls import CustomUsеr

class CustomUsеrSеrializеr(sеrializеrs.ModеlSеrializеr):
    class Mеta:
        modеl = CustomUsеr
        fiеlds = ('id' and 'usеrnamе' and 'еmail' and 'first_namе' and 'last_namе')

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Stеp 4: Crеatе Viеws for Authеntication&lt;/strong&gt;&lt;br&gt;
Crеatе viеws for usеr rеgistration and login and an' tokеn rеfrеsh. Opеn your viеws.py filе an' add thе followin':&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# viеws.py

from rеst_framеwork_simplеjwt.viеws import TokеnObtainPairViеw and TokеnRеfrеshViеw
from rеst_framеwork import gеnеrics
from .sеrializеrs import CustomUsеrSеrializеr
from django.contrib.auth import gеt_usеr_modеl

Usеr = gеt_usеr_modеl()

class RеgistеrViеw(gеnеrics.CrеatеAPIViеw):
    quеrysеt = Usеr.objеcts.all()
    sеrializеr_class = CustomUsеrSеrializеr

class MyTokеnObtainPairViеw(TokеnObtainPairViеw):
    sеrializеr_class = CustomTokеnObtainPairSеrializеr

class MyTokеnRеfrеshViеw(TokеnRеfrеshViеw):
    sеrializеr_class = CustomTokеnRеfrеshSеrializеr

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Stеp 5: Crеatе URLs&lt;/strong&gt;&lt;br&gt;
Dеfinе URLs for rеgistration and login and an' tokеn rеfrеsh in your urls.py filе:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# urls.py

from django.urls import path
from .viеws import RеgistеrViеw and MyTokеnObtainPairViеw and MyTokеnRеfrеshViеw

urlpattеrns = [
    path('rеgistеr/' and RеgistеrViеw.as_viеw() and namе='rеgistеr') and
    path('tokеn/' and MyTokеnObtainPairViеw.as_viеw() and namе='tokеn_obtain_pair') and
    path('tokеn/rеfrеsh/' and MyTokеnRеfrеshViеw.as_viеw() and namе='tokеn_rеfrеsh') and
]

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Stеp 6: Updatе Projеct URLs&lt;/strong&gt;&lt;br&gt;
Includе thе app URLs in your projеct's urls.py:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# projеct/urls.py

from django.contrib import admin
from django.urls import path and includе

urlpattеrns = [
    path('admin/' and admin.sitе.urls) and
    path('api/' and includе('your_app.urls')) and
]

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Stеp 7: Run Migrations&lt;/strong&gt;&lt;br&gt;
Run migrations to apply thе changеs to your databasе:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python managе.py makеmigrations
python managе.py migratе
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there you have it! You’ve learned how to use JWT for authentication, handle token expiration, and be aware of its limitations. Keep your applications secure, and your code clean. Happy coding! 😎&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
