<?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 Khazaei Amir on Medium]]></title>
        <description><![CDATA[Stories by Khazaei Amir on Medium]]></description>
        <link>https://medium.com/@khazaei.amir110?source=rss-1846f82edd12------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*0bECby5MFOC2mJ2Q</url>
            <title>Stories by Khazaei Amir on Medium</title>
            <link>https://medium.com/@khazaei.amir110?source=rss-1846f82edd12------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 03:05:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@khazaei.amir110/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[ Gitflow: A Powerful Workflow for Managing Your Codebase]]></title>
            <link>https://medium.com/@khazaei.amir110/gitflow-a-powerful-workflow-for-managing-your-codebase-fc1330a04ca9?source=rss-1846f82edd12------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc1330a04ca9</guid>
            <category><![CDATA[gitflow]]></category>
            <dc:creator><![CDATA[Khazaei Amir]]></dc:creator>
            <pubDate>Fri, 03 Oct 2025 06:30:16 GMT</pubDate>
            <atom:updated>2025-10-03T06:30:16.580Z</atom:updated>
            <content:encoded><![CDATA[<p>When teams grow and projects get more complex, managing branches in Git can become… messy. That’s where <strong>Gitflow</strong> comes in.</p><p>🔑 <strong>What is Gitflow?<br></strong> Gitflow is a branching model that gives structure to how teams collaborate on Git. Instead of a chaotic “everyone commits everywhere,” it provides clear rules about <strong>when</strong> and <strong>where</strong> to create branches.</p><h3>🛠️ Core Ideas of Gitflow:</h3><ul><li><strong>Main branches</strong>:</li><li>main → always production-ready code</li><li>develop → the integration branch for features</li><li><strong>Supporting branches</strong>:</li><li>feature/* → for new features</li><li>release/* → for preparing a new version</li><li>hotfix/* → for urgent fixes on production</li></ul><p>⚡ <strong>Why use Gitflow?</strong></p><ul><li>Clear separation of stable vs. in-progress code</li><li>Easier collaboration in large teams</li><li>Predictable release process</li></ul><p>✨ <strong>Takeaway</strong>:<br> Gitflow isn’t perfect for every project (especially smaller teams), but when used right, it brings clarity and discipline to software development.</p><p>❓Have you used Gitflow in your projects?<br> Do you prefer it over simpler workflows like trunk-based development?</p><p>#Git #Gitflow #SoftwareEngineering #VersionControl #DevOps #Teamwork</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc1330a04ca9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[⚠️ Challenge: Making a Django Site SEO-Friendly]]></title>
            <link>https://medium.com/@khazaei.amir110/%EF%B8%8F-challenge-making-a-django-site-seo-friendly-fe261a50266f?source=rss-1846f82edd12------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe261a50266f</guid>
            <dc:creator><![CDATA[Khazaei Amir]]></dc:creator>
            <pubDate>Fri, 03 Oct 2025 06:21:54 GMT</pubDate>
            <atom:updated>2025-10-03T06:21:54.608Z</atom:updated>
            <content:encoded><![CDATA[<p>Our site had great content, but search engines were not indexing some pages properly, and rich results weren’t showing up in Google Search.</p><p>💡 Solution<br>To tackle this, we implemented Sitemaps and Schema.org structured data directly in Django. Here’s what we did:<br>Used Django’s built-in sitemaps framework to generate XML sitemaps automatically for all dynamic pages.<br>Added robots.txt configuration to guide search engine crawlers efficiently.<br>Integrated JSON-LD Schema markup for articles, products, and events, improving how rich results appear in search results.<br>Created reusable templates and helper functions so adding new types of content is straightforward.</p><p>✅ Result<br>The result was immediate and measurable: pages got indexed faster, rich snippets started appearing, and overall SEO visibility improved. Maintaining sitemaps and structured data also became much easier thanks to the reusable Django setup.</p><p>💬 CTA<br>Have you ever implemented Sitemap or Schema in your projects? What’s your go-to approach to improve SEO in Django applications?</p><p>#Django #Python #SEO #WebDevelopment #Schema #Sitemap #BackendDevelopment #SoftwareEngineering #DeveloperTips</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe261a50266f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Draft Article: “Database Transactions in Django: Atomicity, Best Practices, and Real-world Use…]]></title>
            <link>https://medium.com/@khazaei.amir110/draft-article-database-transactions-in-django-atomicity-best-practices-and-real-world-use-073d27ef1039?source=rss-1846f82edd12------2</link>
            <guid isPermaLink="false">https://medium.com/p/073d27ef1039</guid>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Khazaei Amir]]></dc:creator>
            <pubDate>Tue, 30 Sep 2025 12:22:17 GMT</pubDate>
            <atom:updated>2025-09-30T12:22:17.158Z</atom:updated>
            <content:encoded><![CDATA[<h3>Draft Article: “Database Transactions in Django: Atomicity, Best Practices, and Real-world Use Cases”</h3><h3>۱. Introduction</h3><p>In modern web applications, ensuring data integrity is crucial. You want to avoid situations where part of a process succeeds and another part fails, leaving your database in an inconsistent state. Database transactions provide exactly this guarantee — they allow you to group multiple operations so that <strong>either all succeed or none do</strong>. Django supports transactions out of the box, and in this article, we’ll explore how to use them effectively.</p><h3>۲. What is a Transaction?</h3><p>A transaction is a logical unit of work which must be treated in its entirety. The key properties often referred to as <strong>ACID</strong> are:</p><ul><li><strong>Atomicity</strong>: all or nothing</li><li><strong>Consistency</strong>: database moves from one valid state to another</li><li><strong>Isolation</strong>: intermediate states are not visible to others</li><li><strong>Durability</strong>: once committed, changes persist</li></ul><p>In Django, by default, each database query is individually committed (autocommit mode). That means if you do:</p><pre>user = User.objects.create(...)<br>profile = Profile.objects.create(user=user, ...)</pre><p>If the second line fails, the first one will still remain in the DB, possibly leaving inconsistent data.</p><h3>۳. Django’s transaction.atomic</h3><p>Django offers the atomic() function (as a decorator or context manager) to wrap multiple DB operations into one transaction.</p><pre>from django.db import transaction</pre><pre>def my_view(request):<br>    with transaction.atomic():<br>        user = User.objects.create(...)<br>        profile = Profile.objects.create(user=user, ...)<br>        # if an exception occurs here, both creations roll back</pre><p>Or using decorator:</p><pre>@transaction.atomic<br>def my_view(request):<br>    ...</pre><p>If any exception occurs inside the atomic block, Django rolls back all queries executed in that block, maintaining integrity.</p><h3>۴. Savepoints and Nested Transactions</h3><p>You can create <strong>savepoints</strong> inside an atomic block to allow partial rollback:</p><pre>with transaction.atomic():<br>    # do some operations<br>    sid = transaction.savepoint()<br>    try:<br>        # operations that might fail<br>    except Exception:<br>        transaction.savepoint_rollback(sid)<br>    else:<br>        transaction.savepoint_commit(sid)</pre><p>Nested atomic() blocks create savepoints automatically in many backends.</p><h3>۵. select_for_update and Concurrency Control</h3><p>In concurrent systems, you might run into <strong>race conditions</strong>. To prevent that, you can lock rows using:</p><pre>with transaction.atomic():<br>    obj = MyModel.objects.select_for_update().get(pk=...)<br>    obj.some_field += 1<br>    obj.save()</pre><p>This ensures no other transaction can read or write that row until your transaction is completed.</p><h3>۶. Best Practices &amp; Pitfalls</h3><p>Best Practice Why Notes Keep transactions short Long transactions can lead to locks and degraded performance Avoid network calls, external APIs, file IO inside atomic blocks Do not include side-effects Example: sending emails or HTTP requests should be outside the atomic block Because if your atomic rolls back, you might have sent an email for nothing Use on_commit hooks Wrap actions that must run <strong>after</strong> commit transaction.on_commit(lambda: send_email(...)) Test under load / concurrency DB behavior may differ in high-traffic scenarios Use unit tests or integration tests with parallel transactions</p><h3>۷. Real-World Use Case: Transfer Money</h3><pre>@transaction.atomic<br>def transfer_funds(from_account, to_account, amount):<br>    from_acc = Account.objects.select_for_update().get(pk=from_account.pk)<br>    to_acc = Account.objects.select_for_update().get(pk=to_account.pk)</pre><pre>    if from_acc.balance &lt; amount:<br>        raise ValueError(&quot;Insufficient funds&quot;)</pre><pre>    from_acc.balance -= amount<br>    from_acc.save()<br>    to_acc.balance += amount<br>    to_acc.save()</pre><p>If anything fails (insufficient funds, DB error), the entire operation is rolled back.</p><h3>۸. Summary</h3><ul><li>Transactions ensure consistency across multiple DB operations.</li><li>Use transaction.atomic to group operations.</li><li>Use savepoints, locking, and on_commit for advanced control.</li><li>Keep transactions lean — avoid side-effects inside them.</li></ul><h3>References &amp; Further Reading</h3><ul><li>Django Documentation: <em>Database Transactions</em> (<a href="https://docs.djangoproject.com/en/5.2/topics/db/transactions/?utm_source=chatgpt.com">Django Project</a>)</li><li><em>Atomic transactions in Django</em> on Medium (<a href="https://medium.com/rocknnull/atomic-transactionsin-django-142feb44467c?utm_source=chatgpt.com">Medium</a>)</li><li><em>Understanding Django’s Transaction Atomic</em> (PlainEnglish) (<a href="https://plainenglish.io/blog/understanding-djangos-transaction-atomic?utm_source=chatgpt.com">plainenglish.io</a>)</li><li><em>Python: A Deeper Look Into How Django Transactions Work</em> (<a href="https://hackernoon.com/python-a-deeper-look-into-how-django-transactions-work?utm_source=chatgpt.com">Hacker Noon</a>)</li><li><em>Django Transactions: Ensuring Data Integrity</em> (<a href="https://reintech.io/blog/django-transactions-data-integrity?utm_source=chatgpt.com">Reintech</a>)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=073d27ef1039" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[⚙️ Django Middleware — From Confusion to Clarity]]></title>
            <link>https://medium.com/@khazaei.amir110/%EF%B8%8F-django-middleware-from-confusion-to-clarity-99add6c326ed?source=rss-1846f82edd12------2</link>
            <guid isPermaLink="false">https://medium.com/p/99add6c326ed</guid>
            <category><![CDATA[django-framework]]></category>
            <category><![CDATA[middleware]]></category>
            <category><![CDATA[django-rest-framework]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Khazaei Amir]]></dc:creator>
            <pubDate>Sun, 28 Sep 2025 03:25:31 GMT</pubDate>
            <atom:updated>2025-09-28T03:25:31.832Z</atom:updated>
            <content:encoded><![CDATA[<h3>⚙️ Django Middleware — From Confusion to Clarity</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*kuh_u1qnZZTprCPK7dAZVQ.jpeg" /></figure><p>⚙️ Django Middleware — From Confusion to Clarity<br>🚧 Challenge<br>When I first started working with Django, I often heard the question:<br> “How does middleware work, and in what order are they executed?”<br> At first, it felt like a black box — requests went in, responses came out, but I had no clear picture of what happened in between.<br>🔑 Solution<br>Here’s how I broke it down into simple steps:<br>Request flow: Middleware executes top → bottom (as listed in the MIDDLEWARE setting).<br>Response flow: The response travels back in the reverse order.<br>Core examples:<br>SecurityMiddleware → adds security headers<br>AuthenticationMiddleware → attaches user info<br>SessionMiddleware → manages sessions<br>CsrfViewMiddleware → protects against CSRF attacks<br>Handy third-party tools:<br>django-cors-headers → manage CORS<br>WhiteNoiseMiddleware → serve static files<br>django-debug-toolbar → debug queries &amp; performance<br>✅ Result<br>Once I understood middleware as a traffic control system in Django, the execution order made total sense. Suddenly, I had more control over performance, security, and user experience.<br>💬 Your Turn<br>Which third-party middleware do you never start a Django project without?<br> Share your go-to tools in the comments 👇<br><a href="https://www.linkedin.com/search/results/all/?keywords=%23django&amp;origin=HASH_TAG_FROM_FEED">hashtag#Django</a> <a href="https://www.linkedin.com/search/results/all/?keywords=%23python&amp;origin=HASH_TAG_FROM_FEED">hashtag#Python</a> <a href="https://www.linkedin.com/search/results/all/?keywords=%23backenddevelopment&amp;origin=HASH_TAG_FROM_FEED">hashtag#BackendDevelopment</a> <a href="https://www.linkedin.com/search/results/all/?keywords=%23middleware&amp;origin=HASH_TAG_FROM_FEED">hashtag#Middleware</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99add6c326ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>