<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Noorzaib Munawar Chohan on Medium]]></title>
        <description><![CDATA[Stories by Noorzaib Munawar Chohan on Medium]]></description>
        <link>https://medium.com/@ytryqzdd?source=rss-88adb894be71------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CkTIoFjFwoLbtlJ0_DkmhQ.jpeg</url>
            <title>Stories by Noorzaib Munawar Chohan on Medium</title>
            <link>https://medium.com/@ytryqzdd?source=rss-88adb894be71------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 02:46:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ytryqzdd/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I Slashed My Django API Response Time by 60% (And Everyone Actually Loved It)]]></title>
            <link>https://medium.com/@ytryqzdd/how-i-slashed-my-django-api-response-time-by-60-and-everyone-actually-loved-it-4631a7737a8c?source=rss-88adb894be71------2</link>
            <guid isPermaLink="false">https://medium.com/p/4631a7737a8c</guid>
            <dc:creator><![CDATA[Noorzaib Munawar Chohan]]></dc:creator>
            <pubDate>Tue, 09 Dec 2025 21:17:45 GMT</pubDate>
            <atom:updated>2025-12-09T21:17:45.413Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*-Q2KdcrnlrGVJQOxTCNqwg.png" /></figure><p>It started as a normal day of testing my Django API. I hit the endpoint in Postman, expecting a quick “here’s your data” response… instead, I stared at the spinner. <strong>1.8 seconds</strong>. My simple book list was taking longer than a coffee break.</p><p>Something was clearly wrong. APIs are supposed to be fast, responsive, almost invisible. But this one felt like it was trudging through molasses. That’s when I went deep and discovered <strong>150+ database queries</strong> for a single request.</p><h3>Yes. <strong>150+</strong>.</h3><blockquote>It was a disaster. But also… a challenge I couldn’t resist.</blockquote><h3>Step 1: Measure Before You Touch Anything</h3><p>You can’t fix what you don’t understand. I installed <strong>Django Debug Toolbar</strong> to peek under the hood:</p><pre>pip install django-debug-toolbar</pre><p>Immediately, the numbers told the story: duplicate queries, redundant lookups, the infamous <strong>N+1 problem</strong>. My database looked like a traffic jam at rush hour.</p><h3>Step 2: Break the N+1 Chain</h3><p>My endpoint needed to return books with their authors. Original approach:</p><pre># N+1 query problem<br>books = Book.objects.all()<br>for book in books:<br>    print(book.author.name)</pre><p>Every iteration triggered a new query. Multiply that by dozens of books, and queries skyrocketed.</p><p><strong>Solution:</strong></p><pre># Optimized query<br>books = Book.objects.select_related(&#39;author&#39;).all()</pre><p><strong>Result:</strong> Query count dropped <strong>from 150 → 12</strong>. My API started breathing again.</p><h3>Step 3: Cache Like a Pro</h3><p>Even with fewer queries, some requests were still sluggish. Enter caching.</p><pre>from django.core.cache import cache<br><br>def get_books():<br>    books = cache.get(&#39;books_list&#39;)<br>    if not books:<br>        books = Book.objects.select_related(&#39;author&#39;).all()<br>        cache.set(&#39;books_list&#39;, books, timeout=300)  # cache for 5 minutes<br>    return books</pre><p>And configure Redis in Django:</p><pre># settings.py<br>CACHES = {<br>    &quot;default&quot;: {<br>        &quot;BACKEND&quot;: &quot;django_redis.cache.RedisCache&quot;,<br>        &quot;LOCATION&quot;: &quot;redis://127.0.0.1:6379/1&quot;,<br>        &quot;OPTIONS&quot;: {&quot;CLIENT_CLASS&quot;: &quot;django_redis.client.DefaultClient&quot;}<br>    }<br>}</pre><p>Repeated API calls went from <strong>seconds → milliseconds</strong>. Small cache, huge impact.</p><h3>Step 4: Optimize Your Database</h3><p>Filtering was a pain point:</p><pre>Book.objects.filter(title__icontains=&quot;Django&quot;)</pre><p>Without an index, every search scanned the whole table. Adding a simple index changed everything:</p><pre>CREATE INDEX idx_book_title ON books(title);</pre><p>Filtering performance improved <strong>30–40%</strong>, even on large datasets.</p><h3>The Outcome</h3><h4>Before Optimization</h4><blockquote>Query Count: 150+</blockquote><blockquote>Response Time: ~1.8s</blockquote><h4>After Optimization</h4><blockquote>Query Count: ~12</blockquote><blockquote>Response Time: ~0.7s</blockquote><p>My API went from crawling to practically instantaneous, ready to impress users and teammates alike.</p><h3>Lessons Learned</h3><ul><li><strong>Profile first.</strong> Always measure before guessing.</li><li><strong>select_related &amp; prefetch_related</strong> are your ORM superpowers.</li><li><strong>Cache wisely.</strong> Even short-term caching can save precious milliseconds.</li><li><strong>Index the right fields.</strong> Don’t let filtering slow your queries.</li><li>Small optimizations add up to huge performance gains.</li></ul><h3>Next Challenges</h3><ul><li>Adding pagination to handle big datasets efficiently.</li><li>Implementing DRF throttling and caching headers.</li><li>Exploring async views for compute-heavy endpoints.</li></ul><p>Optimizing APIs doesn’t have to be painful. With profiling, smart query design, caching, and database tuning, even the slowest Django endpoint can become lightning fast.</p><p>How do you optimize your APIs? Drop your tips in the comments, I’d love to learn from your experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4631a7737a8c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 Django Admin Customizations That Make Your Workflow Faster]]></title>
            <link>https://medium.com/@ytryqzdd/10-django-admin-customizations-that-make-your-workflow-faster-571bbaa12676?source=rss-88adb894be71------2</link>
            <guid isPermaLink="false">https://medium.com/p/571bbaa12676</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[dashboard]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[django-admin]]></category>
            <category><![CDATA[django-rest-framework]]></category>
            <dc:creator><![CDATA[Noorzaib Munawar Chohan]]></dc:creator>
            <pubDate>Wed, 20 Aug 2025 08:34:09 GMT</pubDate>
            <atom:updated>2025-08-20T08:34:09.517Z</atom:updated>
            <content:encoded><![CDATA[<p>When I first started using the Django admin, I found myself clicking endlessly through records, scrolling past hundreds of entries, and repeating the same tasks. The admin was functional, but it felt slow and clunky. Over time, I discovered practical tweaks that transformed it into a productivity powerhouse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u6f58jADG0NC9ob-.png" /></figure><p>In this article, I share ten customizations that drastically improved my workflow, saved hours every week, and made my clients happier. Even if you are a beginner, you can follow these tips to make your Django admin cleaner, faster, and more professional.</p><h3>1. Customize List Display</h3><p>The list_display setting allows you to choose which fields are visible in the model list.</p><pre>class OrderAdmin(admin.ModelAdmin):<br>    list_display = (&#39;id&#39;, &#39;customer&#39;, &#39;status&#39;, &#39;total&#39;, &#39;created_at&#39;)</pre><p><strong>Why it matters:</strong> You can see important details at a glance without opening each record. This saves time and reduces repetitive navigation.</p><h3>2. Add List Filters</h3><p>Filters help you narrow down records quickly. You can filter orders by status, payment method, or date.</p><pre>class OrderAdmin(admin.ModelAdmin):<br>    list_filter = (&#39;status&#39;, &#39;payment_method&#39;, &#39;created_at&#39;)</pre><p><strong>Why it matters:</strong> When managing hundreds of entries, filters prevent endless scrolling and allow you to focus on exactly what you need.</p><h3>3. Enable Search Fields</h3><p>The search_fields option allows you to quickly find records by typing keywords.</p><pre>class CustomerAdmin(admin.ModelAdmin):<br>    search_fields = (&#39;first_name&#39;, &#39;last_name&#39;, &#39;email&#39;)</pre><p><strong>Why it matters:</strong> Searching saves time and helps you locate records without manually scanning the list.</p><h3>4. Use Inline Models</h3><p>Inline models allow you to edit related models directly on the same page. For example, managing orders and their items.</p><pre>class OrderItemInline(admin.TabularInline):<br>    model = OrderItem<br>    extra = 0<br><br>class OrderAdmin(admin.ModelAdmin):<br>    inlines = [OrderItemInline]</pre><p><strong>Why it matters:</strong> You no longer need to switch between models, which makes data entry faster and reduces errors.</p><h3>5. Add Read-Only Fields</h3><p>Sometimes you want fields to be visible but not editable. This is useful for timestamps or calculated values.</p><pre>class OrderAdmin(admin.ModelAdmin):<br>    readonly_fields = (&#39;created_at&#39;, &#39;updated_at&#39;, &#39;total&#39;)</pre><p><strong>Why it matters:</strong> This prevents accidental changes and keeps critical data consistent.</p><h3>6. Group Fields Using Fieldsets</h3><p>Fieldsets organize fields into logical sections for better readability.</p><pre>class CustomerAdmin(admin.ModelAdmin):<br>    fieldsets = (<br>        (&#39;Personal Info&#39;, {&#39;fields&#39;: (&#39;first_name&#39;, &#39;last_name&#39;, &#39;email&#39;)}),<br>        (&#39;Address&#39;, {&#39;fields&#39;: (&#39;city&#39;, &#39;state&#39;, &#39;zip_code&#39;)}),<br>    )</pre><p><strong>Why it matters:</strong> A structured form improves clarity, reduces mistakes, and makes data entry more efficient.</p><h3>7. Use Custom Actions</h3><p>Custom actions allow bulk operations with a single click, such as marking multiple orders as shipped.</p><pre>def mark_shipped(modeladmin, request, queryset):<br>    queryset.update(status=&#39;shipped&#39;)<br><br>class OrderAdmin(admin.ModelAdmin):<br>    actions = [mark_shipped]</pre><p><strong>Why it matters:</strong> Bulk operations save time and reduce repetitive tasks.</p><h3>8. Add Ordering</h3><p>Default ordering helps you navigate lists predictably.</p><pre>class CustomerAdmin(admin.ModelAdmin):<br>    ordering = (&#39;last_name&#39;, &#39;first_name&#39;)</pre><p><strong>Why it matters:</strong> A consistent order reduces the effort needed to locate records and improves workflow efficiency.</p><h3>9. Customize the Admin Site Header and Titles</h3><p>Small branding touches make the admin feel professional and intuitive.</p><pre>admin.site.site_header = &quot;My App Admin&quot;<br>admin.site.site_title = &quot;My App Dashboard&quot;<br>admin.site.index_title = &quot;Welcome to the Admin&quot;</pre><p><strong>Why it matters:</strong> Clients immediately recognize the admin, and it enhances usability and trust.</p><h3>10. Use Autocomplete Fields</h3><p>For models with foreign keys pointing to large datasets, autocomplete fields reduce scrolling and typing.</p><pre>class OrderAdmin(admin.ModelAdmin):<br>    autocomplete_fields = [&#39;customer&#39;]</pre><p><strong>Why it matters:</strong> This is a huge time saver when managing hundreds or thousands of records.</p><h3>Putting It All Together: A Mini Project</h3><p>Imagine managing an online store with products, customers, and orders. By applying all ten customizations:</p><ul><li><strong>You can see order summaries at a glance using </strong><strong>list_display</strong></li><li><strong>Filter orders by status and search for customers quickly</strong></li><li><strong>Edit order items inline without navigating away</strong></li><li><strong>Prevent accidental changes using read-only fields</strong></li><li><strong>Organize customer forms with fieldsets</strong></li><li><strong>Perform bulk updates like shipping multiple orders with custom actions</strong></li><li><strong>Keep your lists predictable using ordering</strong></li><li><strong>Add branding for client clarity with custom site headers</strong></li><li><strong>Make foreign key selection fast with autocomplete fields</strong></li></ul><p>With these tweaks, the Django admin becomes a powerful tool rather than a time-consuming chore.</p><h3>Conclusion</h3><p>Customizing the Django admin is one of the easiest ways to save hours of repetitive work and make your development workflow more efficient. These ten practical tips help beginners get started and give advanced users tools to create a professional, maintainable admin interface.</p><p>Experiment with your own projects. Combine these admin tweaks with Django signals and notifications to make your applications smarter, reactive, and client-ready. A well-configured admin is more than a backend interface. It is a productivity engine.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=571bbaa12676" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Notifications in Django: Keep Your Users Informed Instantly]]></title>
            <link>https://medium.com/@ytryqzdd/implementing-notifications-in-django-keep-your-users-informed-instantly-0523c1226900?source=rss-88adb894be71------2</link>
            <guid isPermaLink="false">https://medium.com/p/0523c1226900</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[push-notification]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Noorzaib Munawar Chohan]]></dc:creator>
            <pubDate>Mon, 18 Aug 2025 21:44:46 GMT</pubDate>
            <atom:updated>2025-08-18T21:44:46.299Z</atom:updated>
            <content:encoded><![CDATA[<p>Every modern web application needs notifications. They keep users informed about important events, such as a new message, a comment, or a status update. Sending notifications manually in each view can quickly clutter your code and make it hard to maintain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*eO2_mafzdJS04gP2AAGD_w.png" /></figure><blockquote><strong>Django provides the tools to implement notifications in a clean, modular, and reusable way. Whether you want to send emails, push notifications, or in-app alerts, you can design a notification system that responds automatically to events in your application.</strong></blockquote><p>In this article, we will explore how to implement notifications in Django, structure your code properly, and create a beginner-friendly, maintainable notification system. We will also build a simple API so your frontend can consume notifications dynamically.</p><h3>Why Notifications Matter</h3><p>Imagine a learning platform where a teacher posts new assignments. Students need to know immediately so they can stay on track. Or a social media application where users receive alerts when someone comments on their posts.</p><p>Without a proper notification system, you would have to manually trigger emails or alerts in multiple views.</p><p>This makes your code repetitive, tightly coupled, and hard to maintain. Notifications allow your app to respond automatically to events, keeping your logic clean and centralized.</p><h3>Designing a Notification System</h3><p>A good notification system has three key components:</p><ol><li><strong>Event Triggers</strong> — Actions in your app that should generate notifications. For example, a new comment, a new user signup, or a completed task.</li><li><strong>Notification Model</strong> — A database model that stores notifications, including the recipient, message, read status, and timestamp.</li><li><strong>Delivery Methods</strong> — The way notifications are delivered, such as email, in-app alerts, or push notifications.</li></ol><h3>Creating a Notification Model</h3><p>Start by creating a simple Notification model:</p><pre>from django.db import models<br>from django.contrib.auth.models import User<br><br>class Notification(models.Model):<br>    recipient = models.ForeignKey(User, on_delete=models.CASCADE, related_name=&#39;notifications&#39;)<br>    message = models.TextField()<br>    is_read = models.BooleanField(default=False)<br>    created_at = models.DateTimeField(auto_now_add=True)<br><br>    def __str__(self):<br>        return f&quot;Notification for {self.recipient.username}: {self.message[:20]}&quot;</pre><p>This model stores who receives the notification, the message content, whether it has been read, and when it was created.</p><h3>Triggering Notifications with Signals</h3><p>Just like Django signals, we can trigger notifications automatically. For example, if a student submits an assignment and the teacher should be notified:</p><pre>from django.db.models.signals import post_save<br>from django.dispatch import receiver<br>from .models import AssignmentSubmission, Notification<br><br>@receiver(post_save, sender=AssignmentSubmission)<br>def notify_teacher_on_submission(sender, instance, created, **kwargs):<br>    if created:<br>        Notification.objects.create(<br>            recipient=instance.assignment.teacher.user,<br>            message=f&quot;{instance.student.user.get_full_name()} submitted {instance.assignment.title}&quot;<br>        )</pre><p>Whenever a new <strong>AssignmentSubmission</strong> is created, the teacher receives a notification automatically.</p><h3>Sending Email Notifications</h3><p>You can also extend your notification system to send emails. Using Django’s built-in email system:</p><pre>from django.core.mail import send_mail<br><br>@receiver(post_save, sender=AssignmentSubmission)<br>def notify_teacher_email(sender, instance, created, **kwargs):<br>    if created:<br>        send_mail(<br>            subject=f&quot;New Submission: {instance.assignment.title}&quot;,<br>            message=f&quot;{instance.student.user.get_full_name()} has submitted their assignment.&quot;,<br>            from_email=&quot;noreply@example.com&quot;,<br>            recipient_list=[instance.assignment.teacher.user.email]<br>        )</pre><p>This allows notifications to appear both in-app and via email without modifying your views.</p><h3>Organizing Notifications in Your Project</h3><p>For a clean, beginner-friendly project structure:</p><pre>myapp/<br>├── models.py        # Notification and related models<br>├── signals.py       # All signal logic for notifications<br>├── views.py<br>├── serializers.py<br>├── apps.py          # Register signals here<br>├── utils.py         # Optional helpers for sending notifications</pre><p>This structure keeps notifications modular and maintainable.</p><h3>Creating an API for Notifications</h3><p>A robust notification system becomes even more useful when your frontend can fetch notifications dynamically. Using Django REST Framework, you can expose an endpoint that returns notifications for the logged-in user.</p><h3>Step One: Create a Serializer</h3><pre>from rest_framework import serializers<br>from .models import Notification<br><br>class NotificationSerializer(serializers.ModelSerializer):<br>    class Meta:<br>        model = Notification<br>        fields = [&#39;id&#39;, &#39;message&#39;, &#39;is_read&#39;, &#39;created_at&#39;]</pre><p>This serializer ensures that only the relevant fields are sent to the frontend.</p><h3>Step Two: Create a View</h3><pre>from rest_framework import generics, permissions<br>from .models import Notification<br>from .serializers import NotificationSerializer<br><br>class NotificationListView(generics.ListAPIView):<br>    serializer_class = NotificationSerializer<br>    permission_classes = [permissions.IsAuthenticated]<br><br>    def get_queryset(self):<br>        return Notification.objects.filter(recipient=self.request.user).order_by(&#39;-created_at&#39;)</pre><p>This view ensures that each user only sees their own notifications, sorted by the most recent first.</p><h3>Step Three: Add a URL Endpoint</h3><pre>from django.urls import path<br>from .views import NotificationListView<br><br>urlpatterns = [<br>    path(&#39;notifications/&#39;, NotificationListView.as_view(), name=&#39;notifications-list&#39;),<br>]</pre><p>Your frontend can now fetch notifications via a simple GET request with an authorization token.</p><h3>Step Four: Mark Notifications as Read</h3><pre>from rest_framework.views import APIView<br>from rest_framework.response import Response<br>from rest_framework import status<br>from .models import Notification<br><br>class MarkNotificationReadView(APIView):<br>    permission_classes = [permissions.IsAuthenticated]<br><br>    def post(self, request, pk):<br>        try:<br>            notification = Notification.objects.get(pk=pk, recipient=request.user)<br>            notification.is_read = True<br>            notification.save()<br>            return Response({&#39;status&#39;: &#39;notification marked as read&#39;}, status=status.HTTP_200_OK)<br><br>        except Notification.DoesNotExist:<br>            return Response({&#39;error&#39;: &#39;notification not found&#39;}, status=status.HTTP_404_NOT_FOUND)</pre><h4>Add it to your urls.py:</h4><pre>from django.urls import path <br><br>path(&#39;notifications/&lt;int:pk&gt;/read/&#39;, MarkNotificationReadView.as_view(), name=&#39;mark-notification-read&#39;),</pre><p>Now the frontend can <strong>mark notifications as read</strong> after displaying them.</p><h3>Frontend Integration</h3><p>The frontend can now:</p><ol><li><strong>Fetch notifications</strong> via the /notifications/ endpoint.</li><li><strong>Display them in a notification panel or dropdown</strong>.</li><li><strong>Mark notifications as read</strong> when the user interacts with them.</li></ol><p>This keeps your notification system fully modular, API-driven, and easy to integrate with React, Vue, Angular, or any other frontend framework.</p><h3>Best Practices</h3><ul><li>Keep signal handlers simple and focused.</li><li>Separate in-app and email notifications using helper functions.</li><li>Test notification flows to ensure they trigger correctly.</li><li>Use a dedicated signals.py file and register them in apps.py for clarity.</li><li>Avoid putting notification logic directly in views.</li></ul><h3>Conclusion</h3><p>A well-structured notification system keeps your application reactive, your users informed, and your code clean. By combining Django models, signals, and APIs, you can automatically trigger notifications for important events without cluttering your views.</p><p>Start simple with in-app notifications, then extend your system with emails, push notifications, or integrations with messaging services. A modular, API-driven notification system not only improves user experience but also makes your code professional, maintainable, and ready for real-world applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0523c1226900" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django Signals Explained: Make Your Application React Automatically]]></title>
            <link>https://medium.com/@ytryqzdd/django-signals-explained-make-your-application-react-automatically-4ad1633e6795?source=rss-88adb894be71------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ad1633e6795</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[django-signals]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Noorzaib Munawar Chohan]]></dc:creator>
            <pubDate>Mon, 18 Aug 2025 16:47:39 GMT</pubDate>
            <atom:updated>2025-08-18T16:52:22.872Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>When building a web application, there are moments when you want your code to respond automatically to certain events. Imagine a blog where every time someone comments, the author gets notified immediately.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*EePybQKHHuK6vmUYGJ2Kdg.png" /></figure><p>Or a school system where teachers are informed the moment a student submits an enrollment request. How can you make this happen without cluttering your views or models with extra logic?</p><blockquote><strong>Django provides a feature called signals that allows different parts of your application to communicate automatically. Signals follow the principle of publish and subscribe.</strong></blockquote><blockquote><strong>One part of your code announces that something has happened, and another part reacts without needing to know the details. This feature makes your code cleaner and more maintainable.</strong></blockquote><p>In this article, you will learn what signals are, the types of signals, how to use them, and how to structure them properly in a project for a beginner-friendly approach.</p><h3>What Are Signals</h3><p>Signals are like notifications within your application. They allow one part of your code to tell another part that an event has occurred. For example, when a user registers, you might want to send a welcome email, create a profile, and log the event. Instead of putting all this logic in the view that handles user registration, you can use signals to respond to the event separately. This keeps your code modular and easy to maintain.</p><h3>Types of Signals</h3><p>Django signals can be categorized into built-in signals and custom signals. Each serves a specific purpose in your application.</p><p><strong>Built-in Signals</strong></p><ul><li><strong>post_save</strong> triggers after a model instance is saved. It is commonly used for sending welcome emails or updating related data.</li><li><strong>pre_save</strong> triggers before a model instance is saved. You can use it to modify or validate data before it is saved to the database.</li><li><strong>post_delete</strong> triggers after a model instance is deleted. It can be used to clean up related data or files.</li><li><strong>pre_delete</strong> triggers before a model instance is deleted. This is useful to check conditions or prevent deletion.</li><li><strong>m2m_changed</strong> triggers when a many-to-many relationship changes, such as adding or removing items.</li></ul><p><strong>Custom Signals</strong></p><p>Sometimes the built-in signals are not enough. Django allows you to create custom signals for specific events such as a payment being processed, a student submitting an enrollment request, or a task being completed. Custom signals give you full control over the event and the data it carries.</p><p>By using the right type of signal, you can keep your application logic modular and clean. Built-in signals handle common events automatically, while custom signals allow you to handle unique workflows.</p><h3>How Signals Work</h3><p><strong>Signals work on the principle of decoupling. The sender announces that an event has happened, and the receiver responds</strong>. The sender does not need to know who is listening. This allows you to add or remove functionality without touching the original code.</p><p>For example, when a new user registers, Django automatically sends a post_save signal. You can listen to this signal to send a welcome email.</p><pre>from django.db.models.signals import post_save<br>from django.dispatch import receiver<br>from django.contrib.auth.models import User<br>from django.core.mail import send_mail<br><br>@receiver(post_save, sender=User)<br>def notify_admin(sender, instance, created, **kwargs):<br>    if created:<br>        send_mail(<br>            subject=f&quot;New User Created: {instance.username}&quot;,<br>            message=&quot;A new user has just registered on the site.&quot;,<br>            from_email=&quot;noreply@example.com&quot;,<br>            recipient_list=[&quot;admin@example.com&quot;]<br>        )</pre><p>Whenever a new user is saved, the <strong>notify_admin</strong> function runs automatically. This keeps your user registration logic clean and focused.</p><h3>A Beginner-Friendly Signal Project: Student Enrollment Notification</h3><p>Let us take a practical example. Imagine a school management system where students can request to join a class. Each time a student submits a request, the teacher should be notified automatically. This is an ideal scenario for using signals.</p><h3>Step One: Where to Write Signals</h3><p>For beginners, it is important to organize your signals properly:</p><ol><li>Create a <strong>signals.py</strong> file in your Django app to store all signal logic.</li><li>Register your signals in the app’s <strong>apps.py</strong> file using the ready method. This ensures that Django loads your signals when the application starts.</li></ol><p>For example, in apps.py:</p><pre>from django.apps import AppConfig<br><br>class SchoolAppConfig(AppConfig):<br>    default_auto_field = &#39;django.db.models.BigAutoField&#39;<br>    name = &#39;school_app&#39;<br>    def ready(self):<br>        import school_app.signals</pre><h3>Step Two: Creating the Models</h3><p>We need three models: <strong>SchoolClass</strong>, <strong>Student</strong>, and <strong>EnrollmentRequest</strong>. The <strong>EnrollmentRequest</strong> model keeps track of which student wants to join which class.</p><pre>from django.db import models<br>from django.contrib.auth.models import User<br><br>class SchoolClass(models.Model):<br>    name = models.CharField(max_length=100)<br>    teacher = models.ForeignKey(User, on_delete=models.CASCADE, related_name=&#39;classes&#39;)<br>class Student(models.Model):<br>    user = models.OneToOneField(User, on_delete=models.CASCADE)<br>    enrolled_classes = models.ManyToManyField(SchoolClass, through=&#39;EnrollmentRequest&#39;)<br>class EnrollmentRequest(models.Model):<br>    student = models.ForeignKey(Student, on_delete=models.CASCADE)<br>    school_class = models.ForeignKey(SchoolClass, on_delete=models.CASCADE)<br>    created_at = models.DateTimeField(auto_now_add=True)</pre><h3>Step Three: Writing the Signal</h3><p>Next, we write a signal that notifies the teacher when a new enrollment request is created. This goes into signals.py:</p><pre>from django.db.models.signals import post_save<br>from django.dispatch import receiver<br>from .models import EnrollmentRequest<br>from django.core.mail import send_mail<br><br>@receiver(post_save, sender=EnrollmentRequest)<br>def notify_teacher_on_enrollment(sender, instance, created, **kwargs):<br>    if created:<br>        teacher_email = instance.school_class.teacher.email<br>        student_name = instance.student.user.get_full_name()<br>        class_name = instance.school_class.name<br>        send_mail(<br>            subject=f&quot;New Enrollment Request for {class_name}&quot;,<br>            message=f&quot;{student_name} has requested to join your class {class_name}.&quot;,<br>            from_email=&quot;noreply@example.com&quot;,<br>            recipient_list=[teacher_email],<br>        )</pre><h3>Step Four: How It Works</h3><ol><li>A student creates an enrollment request.</li><li>Django triggers the <strong>post_save</strong> signal for <strong>EnrollmentRequest.</strong></li><li>The signal handler <strong>notify_teacher_on_enrollment</strong> runs automatically and sends an email to the teacher.</li><li>The view that creates the enrollment request does not handle the email logic, keeping it clean and simple.</li></ol><h3>Step Five: Project Structure for Signals</h3><p>A good beginner-friendly structure is:</p><pre>school_app/<br>├── models.py<br>├── views.py<br>├── serializers.py<br>├── signals.py<br>├── apps.py<br>└── utils.py</pre><p>This organization keeps signals modular, making your code easier to maintain and understand.</p><h3>Best Practices</h3><p>Even though signals are powerful, they should be used wisely. Keep the following in mind:</p><ul><li>Use signals for cross-cutting concerns like notifications, logging, or analytics.</li><li>Keep signal handlers simple and focused.</li><li>Organize signals in a dedicated signals.py file.</li><li>Register signals in apps.py to ensure they are loaded when the app starts.</li><li>Test signals thoroughly to avoid unexpected behavior.</li></ul><h3>Conclusion</h3><blockquote>Django signals are like invisible helpers in your application. They allow your code to react automatically to events without becoming tangled and messy.</blockquote><p>For beginners, start with simple built-in signals like post_save. As you gain experience, explore custom signals for unique workflows. Signals make your Django applications cleaner, modular, and professional. By using them wisely, you can create applications that are both efficient and maintainable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ad1633e6795" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Want to Get Hired as a Django Developer? ‍]]></title>
            <link>https://medium.com/@ytryqzdd/want-to-get-hired-as-a-django-developer-32dc80bb0662?source=rss-88adb894be71------2</link>
            <guid isPermaLink="false">https://medium.com/p/32dc80bb0662</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[career-advice]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Noorzaib Munawar Chohan]]></dc:creator>
            <pubDate>Mon, 18 Aug 2025 16:21:14 GMT</pubDate>
            <atom:updated>2025-08-18T16:21:14.470Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>So you want to land a Django developer role.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*mHvtEJybMq5Y60jo" /></figure><blockquote><strong>The problem is that most advice out there is too generic. People say things like <em>“learn Python first”</em> or <em>“build a portfolio project”</em>. That is true, but it will not set you apart when you are actually applying for jobs.</strong></blockquote><p>Hiring managers look for much more than just the basics. They want developers who can handle real-world systems and challenges.</p><p>Here is a skillset roadmap that separates beginners from professionals who are ready to contribute on day one.</p><h3>Core Django Development</h3><p>A strong grasp of Django’s building blocks is non-negotiable.</p><ul><li><strong>Templates</strong>: inheritance, includes, custom tags and filters</li><li><strong>Views</strong>: CRUD operations, authentication, context handling, rendering</li><li><strong>Forms</strong>: model forms, custom validation, formset</li><li><strong>Authentication</strong>: permissions, groups, single sign-on, custom backends</li><li><strong>ORM</strong>: select_related, annotations, subqueries, transactions, bulk_create, constraints</li></ul><h3>Data Modelling</h3><p>Understanding how to design your database is as important as writing code.</p><ul><li>Relationships and generic foreign keys</li><li>Normalisation and schema versus data</li><li>Safe deletion, data resets, and zero-downtime updates</li></ul><h3>Deployment</h3><p>It is not enough to build an app. You need to ship it.</p><ul><li>Handling static and media files using WhiteNoise and django-storages</li><li>Setting up logging and integrating with Sentry</li><li>Monitoring, observability, and containerised deployment with Docker</li></ul><h3>Debugging and Testing</h3><p>A professional developer knows how to catch bugs before users do.</p><ul><li>Reading tracebacks and writing different types of tests: unit, integration and end-to-end</li><li>Improving test speed and coverage</li><li>Using logs effectively for debugging</li></ul><h3>Background Tasks</h3><p>Real-world systems rely on asynchronous tasks.</p><ul><li>Using Celery for periodic and async jobs</li><li>Managing task chains and handling task failures gracefully</li></ul><h3>Web Features</h3><p>Modern apps need more than static pages.</p><ul><li>Feature flags, user uploads, and webhooks</li><li>Sending notifications and managing cookies, CORS and content security policies</li><li>Working with AJAX, the fetch API and integrating htmx</li></ul><h3>APIs</h3><p>APIs are at the heart of most Django projects today.</p><ul><li>Building robust APIs with Django REST Framework</li><li>Understanding GraphQL and OAuth2</li></ul><h3>Development Tools</h3><p>Good tools make you faster and more reliable.</p><ul><li>Version control with Git and GitHub</li><li>Code quality and automation with Docker, Tox, Ruff, Black, and Flake8</li><li>Debugging and enhancements using Django Debug Toolbar and Extensions</li></ul><h3>Reliability and Continuous Integration</h3><p>Employers love developers who care about uptime.</p><ul><li>Creating CI pipelines for automated testing</li><li>Automating database backups and restores</li><li>Implementing monitoring and alert systems for performance and availability</li></ul><h3>Team Collaboration</h3><p>Being a great developer is not just about code. It is about communication.</p><ul><li>Writing clear pull requests and reviewing code effectively</li><li>Asking meaningful questions and estimating tasks accurately</li><li>Collaborating with teammates and contributing to communities</li></ul><h3>Final Thought</h3><p>Mastering Django is about more than syntax. It is about understanding real-world systems: testing, deployment, observability, scalability, and teamwork.</p><p>If you want to stand out to hiring managers, focus on these skills. They show that you are not just a coder, but a developer ready to solve real problems.</p><p><strong>If you are already working with Django, what would you add to this list?</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32dc80bb0662" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ How Lava Lamps Help Protect the Internet]]></title>
            <link>https://medium.com/@ytryqzdd/how-lava-lamps-help-protect-the-internet-abfc1f703e14?source=rss-88adb894be71------2</link>
            <guid isPermaLink="false">https://medium.com/p/abfc1f703e14</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[data-security]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[cloudflare]]></category>
            <dc:creator><![CDATA[Noorzaib Munawar Chohan]]></dc:creator>
            <pubDate>Sat, 16 Aug 2025 22:57:01 GMT</pubDate>
            <atom:updated>2025-08-16T22:57:01.526Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*LBQ0u1HWCb0-yPeg" /></figure><blockquote><strong>Yes, you read that right. Lava lamps. Those groovy, glowing decorations from the 70s are actually part of one of the most advanced internet security systems in the world.</strong></blockquote><h3>Here’s the story:</h3><p>Computers are incredibly powerful, but they have one big weakness: they are predictable. That’s a problem when it comes to security. Encryption, passwords, and secure connections all depend on randomness, numbers that nobody can guess.</p><p>But a computer, by design, struggles to generate true randomness. Instead, it uses a “seed” (like the exact time you pressed a key) to kick things off.</p><blockquote>The catch? If someone figures out that seed, they can predict the entire sequence of random numbers. That makes security vulnerable.</blockquote><h4>So how do you solve this?</h4><p>Enter Cloudflare, a company that protects millions of websites worldwide. Their engineers realized they needed a source of randomness that was truly unpredictable, something no hacker could model or duplicate. And the solution turned out to be both brilliant and bizarre: a wall covered in <strong>lava lamps</strong>.</p><h4>Here’s how it works:</h4><ul><li>A camera is pointed at a giant wall of constantly shifting lava lamps.</li><li>The chaotic movement of liquid blobs inside the lamps is captured in real time.</li><li>That visual noise is fed into Cloudflare’s systems as a source of randomness.</li><li>This randomness becomes the seed for encryption keys that secure internet traffic.</li></ul><p>Because the motion of lava lamps is natural and impossible to replicate digitally, it generates <strong>true entropy</strong>, the gold standard of randomness. In other words, your data is safer because a wall of psychedelic lamps is bubbling away in San Francisco.</p><p>It’s a perfect reminder that sometimes the most secure technologies come from the most unexpected ideas. In a world of cutting-edge algorithms and AI, part of the internet’s defense still comes from something as quirky as lava lamps.</p><p>Next time you visit a website protected by Cloudflare, you can thank those glowing blobs for keeping your connection private.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abfc1f703e14" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI Is Not Just the Future, It Is Already Here]]></title>
            <link>https://medium.com/@ytryqzdd/ai-is-not-just-the-future-it-is-already-here-e0cd718b5023?source=rss-88adb894be71------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0cd718b5023</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Noorzaib Munawar Chohan]]></dc:creator>
            <pubDate>Sat, 16 Aug 2025 22:47:41 GMT</pubDate>
            <atom:updated>2025-08-16T22:47:41.938Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>From Netflix recommendations to self-learning systems, AI has quietly been shaping our daily lives long before it became a trend.</strong></blockquote><p>What if I told you that AI has been shaping your daily life long before it became a buzzword?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*C2GPznmrIR5R3mcI" /></figure><p>Artificial Intelligence is not only about what is coming tomorrow. It has already been part of our daily lives for years, often working quietly behind the scenes to make things easier.</p><blockquote>Think about how <strong>Netflix</strong> suggests movies you might enjoy, how <strong>Google Maps</strong> finds a faster route to your destination, or how your phone can translate languages in real time. These are all examples of AI tools integrated into everyday experiences.</blockquote><h3><strong>The Role of Machine Learning</strong></h3><p>At the heart of many AI-powered tools is <strong>machine learning</strong>. This is a branch of AI that enables systems to learn from data and make decisions.</p><p>However, these systems do not learn on their own. Developers train them using real-world examples.</p><p>For instance, imagine a factory that uses AI to sort ripe apples. To teach the system, developers feed it thousands of images of ripe and unripe apples. Over time, the system learns to recognize the difference and can sort them accurately, helping the factory operate faster and reduce waste.</p><p>This same process happens in countless industries. Banks use machine learning to detect fraud by analyzing millions of transactions. Healthcare providers use it to help doctors identify diseases earlier. Retailers use it to predict what customers might buy next.</p><h3>Why Data Quality Matters</h3><p>Machine learning is only as good as the data it is trained on. If the training images show only red apples, the system may fail to identify green or yellow ones. This can lead to mistakes, lost money, and wasted food.</p><p>In the real world, this challenge is even bigger. If medical AI systems are trained on data from only one group of patients, they may perform poorly when used with a more diverse population. If a hiring algorithm is trained with biased historical data, it can unintentionally reinforce those same biases.</p><p>This is why <strong>data diversity and fairness</strong> are not just technical concerns but ethical ones. The quality of the data we feed into AI shapes the quality of the decisions it makes.</p><h3>The Human Side of AI</h3><p>AI can feel mysterious, but at the end of the day, it is still built and guided by people. Developers, researchers, and designers make choices about how AI is trained, what data it sees, and how it is used.</p><p>That is why human oversight is critical. AI may be fast, but humans bring context, empathy, and judgment that machines cannot replicate. The best results come from combining both.</p><h3>The Bigger Picture</h3><p>When used thoughtfully, AI and machine learning have the power to improve how we work, make better decisions, and solve complex problems. The real key is not just the technology itself but how we train, guide, and apply it responsibly.</p><p>AI is not a far-off concept. It is already here, changing industries, shaping our experiences, and opening new possibilities every single day.</p><p>But with great potential also comes responsibility. The question is not just <em>what can AI do?</em> but <em>how should we use it?</em></p><h3>What Do You Think?</h3><p>Have you noticed ways AI is already part of your daily life? From streaming apps to workplace tools, AI is quietly everywhere.</p><blockquote>I would love to hear your experiences and thoughts in the comments. How has AI changed the way you live or work?</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0cd718b5023" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advancements in AI Are Reshaping How We Work]]></title>
            <link>https://medium.com/@ytryqzdd/advancements-in-ai-are-reshaping-how-we-work-1625d35d3542?source=rss-88adb894be71------2</link>
            <guid isPermaLink="false">https://medium.com/p/1625d35d3542</guid>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[innovation]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Noorzaib Munawar Chohan]]></dc:creator>
            <pubDate>Sat, 16 Aug 2025 22:39:48 GMT</pubDate>
            <atom:updated>2025-08-16T22:39:48.817Z</atom:updated>
            <content:encoded><![CDATA[<h3>“ Artificial Intelligence is no longer just about automation; it is about creation. ”</h3><blockquote>At the center of this transformation is <strong>Generative AI</strong>, a powerful shift that is redefining how we approach work, creativity, and problem-solving.</blockquote><h3>What Makes Generative AI Different?</h3><p>Unlike traditional AI, which analyzes data and follows set rules, <strong>Generative AI can actually create new content</strong> whether that is text, images, audio, or even video.</p><p>And the best part? It works with natural language. Instead of learning complex commands, you can simply <em>talk</em> to it, just like you would to another person.</p><h3>Real-World Use Cases</h3><p>◉ <strong>Marketing teams</strong> can design engaging posters with just a few prompts.<br> ◉ <strong>Professionals</strong> can draft polished emails faster and with fewer mistakes.<br> ◉ <strong>Teams</strong> can brainstorm creative ideas in minutes instead of hours.</p><p>Tools like <strong>Google Gemini</strong> and other conversational AI models are already demonstrating how powerful this shift can be.</p><h3>Beyond Automation: Augmenting Human Potential</h3><p>Generative AI is not just automating tasks; it is <strong>augmenting creativity, productivity, and decision-making</strong> across industries such as healthcare, finance, education, and retail.</p><p>As a Backend Engineer, I find this shift especially fascinating. The ability to <strong>bridge technical workflows with natural language</strong> opens up an entirely new world of possibilities for product development and user experience.</p><h3>Balancing Capabilities with Human Oversight</h3><p>Of course, with every innovation comes responsibility. Understanding <strong>both the capabilities and limitations</strong> of generative AI is essential. The real opportunity lies in knowing when to rely on AI and when human expertise makes the difference.</p><h3>Looking Ahead</h3><p>Generative AI is still evolving, but it is already clear that it will reshape the future of work. The question is not <em>if</em> we will use it, but <em>how</em> we will integrate it into our daily workflows.</p><p>👉 I am curious to hear from you: <strong>How do you see Generative AI fitting into your work?</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1625d35d3542" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[11 REST API Interview Questions They Don’t Tell You About (Your Secret Weapon for Interviews)]]></title>
            <link>https://medium.com/@ytryqzdd/11-rest-api-interview-questions-they-dont-tell-you-about-your-secret-weapon-for-interviews-1d9172b0b6e3?source=rss-88adb894be71------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d9172b0b6e3</guid>
            <category><![CDATA[technical-interview]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[wev-development]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Noorzaib Munawar Chohan]]></dc:creator>
            <pubDate>Sat, 05 Jul 2025 21:37:55 GMT</pubDate>
            <atom:updated>2025-07-05T21:37:55.739Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>If you are looking for a backend or full-stack position, there’s a 99% chance they will ask you questions about building APIs.</strong></blockquote><p>REST APIs have become a cornerstone of modern software development, and understanding them is essential for acing any interview in this domain.</p><p>Here is a carefully curated list of questions you need to know, along with explanations, to help you stand out.</p><h3>1. Can You Explain CRUD Operations in the Context of REST?</h3><p>CRUD (Create, Read, Update, Delete) operations are fundamental to REST API design and map directly to HTTP methods:</p><ul><li><strong>POST</strong>: Create a new resource.</li><li><strong>GET</strong>: Read or retrieve a resource.</li><li><strong>PUT</strong>: Update an entire resource.</li><li><strong>PATCH</strong>: Partially update a resource.</li><li><strong>DELETE</strong>: Remove a resource.</li></ul><p>There are 4 more you should know (just in case you found a picky interviewer).</p><ul><li><strong>HEAD</strong>: Retrieve headers for a resource without the response body.</li><li><strong>OPTIONS</strong>: Discover the allowed methods and communication options for a resource.</li><li><strong>TRACE</strong>: Echo back the request for debugging purposes.</li><li><strong>CONNECT</strong>: Establish a tunnel to the server, typically for SSL/TLS through a proxy.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wT2wk3OY5o6eD4so.png" /></figure><h3>2. What Is the Difference Between PUT and PATCH?</h3><ul><li><strong>PUT</strong> replaces the entire resource. For instance, updating a user profile with PUT requires sending the full user object, even if only the email is changed.</li><li><strong>PATCH</strong> allows partial updates, making it more efficient for specific field modifications.</li></ul><p>For example, setting OrderStatus to “Shipped” should use <strong>PATCH</strong>, not <strong>PUT</strong>, because it’s a partial update.</p><p>Knowing when to use each method demonstrates your ability to design efficient APIs.</p><h3>3. What Are Common HTTP Status Codes, and What Do They Mean?</h3><p>There are <strong>hundreds of HTTP status codes</strong>, and you can split them into five categories:</p><ul><li>Informational (100–199)</li><li>Successful (200–299)</li><li>Redirection (300–399)</li><li>Client Error (400–499)</li><li>Server Error (500–599)</li></ul><p>But don’t worry, you don’t need to memorize them all. Here are the most common:</p><ul><li><strong>200 OK</strong>: Successful GET request.</li><li><strong>201 Created</strong>: Resource created successfully (POST).</li><li><strong>204 No Content</strong>: DELETE request successful, no response body.</li><li><strong>400 Bad Request</strong>: Client error due to invalid input.</li><li><strong>401 Unauthorized</strong>: Authentication required or invalid.</li><li><strong>403 Forbidden</strong>: User lacks access rights.</li><li><strong>404 Not Found</strong>: Resource does not exist.</li><li><strong>409 Conflict:</strong> The request could not be completed due to a conflict with the current resource state.</li><li><strong>5xx Internal Server Error</strong>: The server encountered an error.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dZDyxzLgA5t9dl6z.png" /></figure><h3>4. What Does It Mean for a REST API to Be Stateless?</h3><p>Statelessness ensures that each API request contains all the information needed to process it. Servers do not store client state between requests, which:</p><ul><li>Simplifies server design.</li><li>Improves scalability.</li><li>Authentication tokens, for example, are included in each request rather than stored server-side.</li></ul><h3>5. How Do You Secure a REST API?</h3><p>Security is a priority for any API. Key techniques include:</p><ul><li><strong>Authentication and Authorization</strong>: You can use API keys, OAuth, and JWT (JSON Web Tokens) to control resource access.</li><li><strong>Rate Limiting</strong>: Prevent abuse by restricting the number of requests a client can make within a given time frame.</li><li><strong>Input Validation</strong>: Protect against common vulnerabilities like SQL injection and XSS by validating all user inputs.</li><li><strong>HTTPS</strong>: Always encrypt data in transit using SSL/TLS to secure communication between clients and servers.</li><li><strong>Encryption at Rest: </strong>Encrypt sensitive data stored on the server (e.g., databases and logs) to protect against unauthorized access or breaches.</li><li>Discussing these practices shows you understand API security concerns.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XSvsgQx9Fz-O6Hfm.png" /></figure><h3>6. How Do You Version a REST API?</h3><p>APIs evolve, and versioning ensures backward compatibility:</p><ul><li><strong>URL Versioning</strong>: Include the version in the URL (e.g., /api/v1/resource or /api/resource?api-version=1).</li><li><strong>Custom Headers</strong>: Use headers like Accept: application/vnd.company.v2+json.</li></ul><h4><strong>Top reasons for versioning APIs:</strong></h4><ul><li><strong>API Evolution with backward compatibility:</strong> As your API evolves, versioning allows you to introduce new features, deprecate outdated functionality, and improve without disrupting existing Consumers.</li><li><strong>Consumer flexibility:</strong> Different Consumers may need different requirements or specific features in a particular API version.</li><li>Versioning strategies help manage transitions for consumers of your API.</li></ul><p>It is important to mention that introducing different versions of APIs will add complexity to API management. You’ll need to plan carefully to retire old versions smoothly and keep clients updated about changes.</p><h3>7. What Is Pagination, and How Is It Implemented in REST APIs?</h3><p>Pagination manages large datasets by splitting them into smaller chunks. It improves scalability and response times.</p><h4>Limit-Offset Pagination</h4><p>This method uses two parameters:</p><ul><li>limit: Specifies the number of items per page</li><li>offset: Indicates the starting position</li><li>GET /items?limit=10&amp;offset=20</li></ul><p>This request retrieves 10 items starting from the 21st item.</p><h4>Cursor-Based Pagination</h4><p>This method uses a cursor (often an encoded string) to keep track of the current position.</p><pre>GET /items?cursor=eyJpZCI6MjB9</pre><h4>Page Number Pagination</h4><p>This approach uses page numbers and page size.</p><pre>GET /items?page=3&amp;size=10</pre><p>This retrieves the 3rd page with 10 items per page.</p><h4>Keyset Pagination</h4><p>This method uses a unique key (e.g., ID or timestamp) to fetch the next set of items.</p><pre>GET /items?after=1627938391&amp;limit=10</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qKRp1Kz87jNgZRUp.png" /></figure><h3>8. Can You Discuss Rate Limits and Their Importance?</h3><p>Rate limiting controls the number of API calls a client can make within a specific time frame. It is essential for:</p><ul><li><strong>Preventing Abuse</strong>: Stops malicious or excessive use of the API that could overwhelm the system.</li><li><strong>Managing Resource Allocation</strong>: Ensures server resources are shared fairly among all clients.</li><li><strong>Ensuring Fair Usage</strong>: Protects against a single client monopolizing API capacity.</li></ul><h4>Rate Limiting Algorithms</h4><p>Several algorithms can be used to implement rate-limiting:</p><ul><li><strong>Fixed Window Counter</strong>: Simple but can lead to uneven traffic distribution.</li><li><strong>Sliding Log</strong>: Offers precise control but may be resource-intensive.</li><li><strong>Sliding Window Counter</strong>: Balances precision and efficiency.</li><li><strong>Token Bucket</strong>: Allows for traffic bursts while maintaining a long-term rate limit.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pH5WfO9cpyVeJ7Yn.png" /></figure><h3>9. What Is Idempotency, and Why Is It Important?</h3><p>Idempotency ensures that multiple identical requests have the same effect as a single request. For example:</p><ul><li><strong>GET, DELETE, PUT, HEAD, OPTIONS</strong>, and <strong>TRACE</strong> are idempotent.</li><li><strong>POST</strong> is indeed not idempotent.</li><li>While <strong>PATCH</strong> is sometimes considered non-idempotent, its idempotency depends on the implementation.</li></ul><p>Idempotency is crucial in distributed systems to handle retries without unintended side effects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/0*g25O2p2X1Kgre7o-.png" /></figure><p>The importance of idempotency extends beyond just handling retries in distributed systems:</p><ol><li><strong>Reliability in Distributed Systems</strong>: Idempotency allows for safe retries in case of network failures or timeouts, ensuring consistency across distributed components.</li><li><strong>Data Consistency</strong>: It prevents unintended side effects from duplicate requests, maintaining data integrity.</li><li><strong>Simplified Error Handling</strong>: Clients can safely resend requests without worrying about adverse effects, simplifying error handling logic.</li><li><strong>Fault Tolerance</strong>: Idempotent operations improve system resilience by allowing automatic retries in case of failures.</li><li><strong>Concurrency Control</strong>: In multi-user environments, idempotency helps minimize conflicts and provides more robust concurrency control.</li><li><strong>Predictability</strong>: Systems built with idempotent operations are often more predictable, simplifying testing and maintenance.</li><li>In conclusion, idempotency is a fundamental concept in designing reliable and scalable distributed systems, especially in the context of RESTful APIs and microservices architectures.</li></ol><p>It provides a safety net against the uncertainties of network communications and helps maintain data consistency in complex, distributed environments.</p><h3>10. How Can You Improve API Performance?</h3><p>Caching is one of the best strategies for improving API performance:</p><ul><li><strong>Client-Side Caching</strong>: Use headers like Cache-Control and ETag to reduce redundant requests.</li><li><strong>Server-Side Caching</strong>: Cache frequently accessed data in-memory with tools like Redis or Memcached.</li><li><strong>CDN Caching</strong>: Distribute cached content geographically to reduce latency.</li><li><strong>Distributed Caching:</strong> Store data across multiple nodes for improved scalability and fault tolerance.</li><li><strong>Database Query Result Caching: </strong>This reduces the load on the database and improves response times.</li><li><strong>Database Query Optimization:</strong> Focus on optimizing database queries through proper indexing, query analysis, and efficient join operations. Sometimes, a lot of performance gets wasted at the persistence layer.</li><li><strong>Connection Pooling</strong>: Reuse database or HTTP connections to avoid the overhead of establishing new connections repeatedly.</li><li><strong>Efficient Data Serialization:</strong> You can consider binary formats like Protocol Buffers for faster serialization and deserialization.</li><li><strong>Content Compression</strong>: Use HTTP compression (e.g., Gzip or Brotli) to reduce payload size, improving response times for large responses.</li><li>Improving API performance is about finding what works best for your system. Use smart caching, reduce extra overhead, and keep things simple where you can.</li></ul><p>These tweaks can make your APIs faster and ready to handle more traffic without breaking a sweat.</p><h3>11. How Do You Document REST APIs?</h3><p>Documentation is critical for API usability and adoption. Best practices include:</p><ul><li>Use <strong>OpenAPI (Swagger)</strong> to create interactive documentation.</li></ul><p><strong>Include:</strong></p><ul><li>Endpoint descriptions.</li><li>Request/response examples.</li><li>Query parameters, headers, and error codes.</li></ul><p>Well-documented APIs save time and, more importantly, reduce friction for developers.</p><blockquote><strong><em>APIs are the glue of modern systems; mastering their concepts is what keeps you at the top of the candidate list.</em></strong></blockquote><blockquote><strong>If you could add one more question, what would it be?</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d9172b0b6e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Building Two User Registration APIs in Django REST Framework: Form Data vs JSON]]></title>
            <link>https://medium.com/@ytryqzdd/building-two-user-registration-apis-in-django-rest-framework-form-data-vs-json-d8a7d60127d9?source=rss-88adb894be71------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8a7d60127d9</guid>
            <category><![CDATA[serialization]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[django-rest-framework]]></category>
            <dc:creator><![CDATA[Noorzaib Munawar Chohan]]></dc:creator>
            <pubDate>Wed, 18 Jun 2025 05:49:07 GMT</pubDate>
            <atom:updated>2025-06-18T05:49:07.535Z</atom:updated>
            <content:encoded><![CDATA[<p>When building RESTful APIs with <strong>Django REST Framework (DRF)</strong>, you’ll likely come across a common question:</p><p><strong>Should your API accept form data or JSON?</strong><br>The answer depends on your use case, but what if you want to support both?</p><p>In this post, we’ll dive deep into creating <strong>two distinct user registration APIs</strong> in DRF:</p><ul><li>One that accepts <strong>form data</strong></li></ul><p>(application/x-www-form-urlencoded or multipart/form-data)</p><ul><li>Another that handles <strong>JSON</strong> (application/json)</li></ul><p><strong>You’ll learn:</strong></p><ul><li>The differences between form data and JSON in APIs</li><li>How DRF parses and handles each</li><li>When to use one over the other</li><li>How to implement both in clean, production-friendly code</li></ul><h3>Why the Difference Matters</h3><p>APIs talk to clients. Some clients (like web browsers and HTML forms) are optimized for form data. Others (like mobile apps or frontend frameworks like React or Vue) communicate using JSON.</p><p>Understanding how DRF handles both makes your API flexible, scalable, and developer-friendly.</p><h3>🎯 The Goal</h3><p>We’ll build two APIs that both:</p><ul><li>Register a user with username, email, and password</li><li>Use Django’s built-in User model</li><li>Differ in <strong>how they accept data</strong></li></ul><h3>📁 Project Setup</h3><p>Assuming you already have Django and DRF installed, let’s get started.</p><ol><li>Install DRF if needed:</li></ol><pre>pip install djangorestframework</pre><ol><li>Add &#39;rest_framework&#39; to INSTALLED_APPS in settings.py.</li><li>Use the default User model for registration.</li></ol><h3>🧩 Step 1: Create the Serializer</h3><p>Let’s write a serializer to handle user creation.</p><pre># accounts/serializers.py<br><br>from django.contrib.auth.models import User<br>from rest_framework import serializers<br><br>class UserRegistrationSerializer(serializers.ModelSerializer):<br>    password = serializers.CharField(write_only=True)<br>    class Meta:<br>        model = User<br>        fields = [&#39;username&#39;, &#39;email&#39;, &#39;password&#39;]<br>    def create(self, validated_data):<br>        return User.objects.create_user(**validated_data)</pre><ul><li>We override create() to use create_user, which hashes the password.</li><li>write_only=True ensures the password is not exposed in responses.</li></ul><h3>📮 Step 2: Form Data Registration API</h3><p>This API will accept form submissions or tools like Postman (in form mode).</p><h3>✅ View:</h3><pre># accounts/views.py<br><br>from rest_framework.views import APIView<br>from rest_framework.response import Response<br>from rest_framework import status<br>from .serializers import UserRegistrationSerializer<br><br>class RegisterFormAPIView(APIView):<br>    def post(self, request):<br>        serializer = UserRegistrationSerializer(data=request.data)<br>        if serializer.is_valid():<br>            serializer.save()<br>            return Response({&quot;message&quot;: &quot;User registered via form&quot;}, status=status.HTTP_201_CREATED)<br>        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)</pre><ul><li>request.data automatically handles form input.</li><li>No need to manually declare parsers unless you want to be explicit.</li></ul><h3>📦 Step 3: JSON Registration API</h3><p>This version is built for JSON-based requests, perfect for frontend or mobile applications.</p><h3>✅ View:</h3><pre># accounts/views.py<br><br>from rest_framework.parsers import JSONParser<br><br>class RegisterJSONAPIView(APIView):<br>    parser_classes = [JSONParser]<br>    def post(self, request):<br>        serializer = UserRegistrationSerializer(data=request.data)<br>        if serializer.is_valid():<br>            serializer.save()<br>            return Response({&quot;message&quot;: &quot;User registered via JSON&quot;}, status=status.HTTP_201_CREATED)<br>        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)</pre><p>We explicitly declare JSONParser here. This ensures the view only processes Content-Type: application/json.</p><h3>🗺️ Step 4: Register the URLs</h3><pre># accounts/urls.py<br><br>from django.urls import path<br>from .views import RegisterFormAPIView, RegisterJSONAPIView<br><br>urlpatterns = [<br>    path(&#39;api/register-form/&#39;, RegisterFormAPIView.as_view(), name=&#39;register_form&#39;),<br>    path(&#39;api/register-json/&#39;, RegisterJSONAPIView.as_view(), name=&#39;register_json&#39;),<br>]</pre><p>Include this urls.py in your project’s root urls.py:</p><pre># project/urls.py<br><br>from django.contrib import admin<br>from django.urls import path, include<br><br>urlpatterns = [<br>    path(&#39;admin/&#39;, admin.site.urls),<br>    path(&#39;&#39;, include(&#39;accounts.urls&#39;)),<br>]</pre><h3>🔍 Testing the APIs</h3><p>Use Postman or curl to test both endpoints.</p><h3>🧪 Form Data</h3><pre>curl -X POST http://localhost:8000/api/register-form/ \<br>  -d &quot;username=john&amp;email=john@example.com&amp;password=1234&quot;</pre><h3>🧪 JSON</h3><pre>curl -X POST http://localhost:8000/api/register-json/ \<br>  -H &quot;Content-Type: application/json&quot; \<br>  -d &#39;{&quot;username&quot;: &quot;john&quot;, &quot;email&quot;: &quot;john@example.com&quot;, &quot;password&quot;: &quot;1234&quot;}&#39;</pre><h3>✅ Recap: Key Takeaways</h3><ul><li>Django REST Framework handles <strong>both JSON and form data</strong> using pluggable <strong>parsers</strong>.</li><li>request.data is unified—whether form or JSON—making serializers easier to work with.</li><li>Use parser_classes when you want to explicitly enforce the content type.</li><li>Form-based APIs are best for traditional HTML forms and browsers.</li><li>JSON-based APIs are ideal for modern frontend apps and mobile clients.</li></ul><h3>🔚 Conclusion</h3><p>By separating APIs based on content type, you can <strong>tailor your backend</strong> to serve multiple clients seamlessly, whether they’re browsers, SPAs, or mobile apps. Django REST Framework makes this incredibly straightforward and powerful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8a7d60127d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>