<?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: Rohit Shakya</title>
    <description>The latest articles on DEV Community by Rohit Shakya (@_rohitshakya).</description>
    <link>https://dev.to/_rohitshakya</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%2F621559%2Ff09ace27-1371-41e2-b883-8faae7e5f01e.jpg</url>
      <title>DEV Community: Rohit Shakya</title>
      <link>https://dev.to/_rohitshakya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/_rohitshakya"/>
    <language>en</language>
    <item>
      <title>Django: The Request-Response Cycle</title>
      <dc:creator>Rohit Shakya</dc:creator>
      <pubDate>Tue, 27 Apr 2021 08:11:10 +0000</pubDate>
      <link>https://dev.to/_rohitshakya/django-the-request-response-cycle-2n6m</link>
      <guid>https://dev.to/_rohitshakya/django-the-request-response-cycle-2n6m</guid>
      <description>&lt;p&gt;Have you ever wondered, things under the hood seems to be more fascinating than the one showcased in front of us.&lt;/p&gt;

&lt;p&gt;It's kind of a Butterfly Effect taking place.&lt;/p&gt;

&lt;p&gt;So let's pull the shades off and unveil the true story of what's happening behind the scene.&lt;/p&gt;

&lt;p&gt;In this bit of a journey, we are going to take a shallow dive in the &lt;strong&gt;Django Request-Response Cycle&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Defining Technical Terms&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Seems to be a tedious task for a newbie I must say, Huh! Unfortunately, these are conventional terms and you just can't skip them over twice.&lt;/p&gt;

&lt;p&gt;Trying to explain in the easy way possible. But if you don't understand in the beginning, it's okay!&lt;br&gt;
The plot of every story doesn't make much sense in the beginning.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619466042369%2Fb3LAaF7TO.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619466042369%2Fb3LAaF7TO.png" alt="Client (2).png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Client&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The one who initiates request for services.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WSGI File - Web Server Gateway Interface&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is used to run python applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Django: Request-Response model&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It contains various elements and files listed below:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Settings.py file&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This file contains all the configurations of your Django Project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Middleware&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Middleware is used to perform a function in the application. The functions can be a security, session, csrf protection, authentication etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Views.py file&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Django views determine what content is displayed on the given page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Urls.py file&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;URLconfs determine where that content is going.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Models.py file&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The model contains the content from the database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Templates&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It provides styling for the data and other stuff to be displayed.&lt;/p&gt;

&lt;p&gt;If it seems overwhelming right now, trust me it's okay! They were just to leave traces of what's coming next.&lt;/p&gt;

&lt;p&gt;Now, let's set the sail of our boat and start off on our little voyage-&lt;/p&gt;

&lt;h3&gt;
  
  
  Django: Request-Response Cycle
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The request from the client reaches the Django Server hosted at (&lt;code&gt;localhost:8000&lt;/code&gt;) in case of hosting locally.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It passes through WSGI and reaches the settings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The very first thing which loads up is settings.py file and in that too Middleware.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then the request tunnels through the listed middleware for various checks like security, authentication etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the request deems to be okay. It then reaches urls.py file where the requested url is matched with the various urls listed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once the url is matched, the request goes to the corresponding view in views.py file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the request requires some information to be rendered from the database, then views talks to the database via models.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Information from database is collected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now the template will be rendered for styling to the views.py file and if the template does not exist, it raises an exception (&lt;code&gt;page not found&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The HTTP response object is rendered into a string as object leaves the Django app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally your web browser render it into a beautiful web page.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This eleven pointer explaination concludes the request-response journey and now it's time to set down the sail and attempt docking.&lt;/p&gt;

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

&lt;p&gt;In a nutshell, that's what happening under Django's Hood!&lt;/p&gt;

&lt;p&gt;Diving deeper is not possible because you and I are in a boat, remember!&lt;/p&gt;

&lt;p&gt;But if you are interested in more technical and detailed stuff. You can refer to  &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/First_steps/Client-Server_overview" rel="noopener noreferrer"&gt;Mozilla&lt;/a&gt;, it has a huge developer community. &lt;/p&gt;

&lt;p&gt;To know about the journey between client and web server, check  &lt;a href="https://dev.to/rohitrana/how-the-web-works-1hd7"&gt;How does the web works.&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If you find my work interesting and worth giving your time. You can nudge me on  &lt;a href="https://twitter.com/_Rohitshakya?s=09" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;  and  &lt;a href="https://www.linkedin.com/in/rohit-shakya-4b171916b/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;You can also share your feedback in the comment section below. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;p.s: what next?&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>django</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
