<?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"><channel><title><![CDATA[Blog of Shubh Agrawal]]></title><description><![CDATA[This is the blog by Shubh Agrawal. ]]></description><link>https://blog.theshubhagrwl.in</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 09:03:00 GMT</lastBuildDate><atom:link href="https://blog.theshubhagrwl.in/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[You might not need a sound library for React]]></title><description><![CDATA[Using audio and video files can sometimes be tricky. To a beginner, it may look like a lot of work but in reality, they are simple to work with.
My project idea was very simple and straightforward. I was trying to make a React app that has multiple a...]]></description><link>https://blog.theshubhagrwl.in/you-might-not-need-a-sound-library-for-react</link><guid isPermaLink="true">https://blog.theshubhagrwl.in/you-might-not-need-a-sound-library-for-react</guid><category><![CDATA[React]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[react sound]]></category><category><![CDATA[sound in react]]></category><category><![CDATA[react sounds]]></category><dc:creator><![CDATA[Shubh Agrawal]]></dc:creator><pubDate>Wed, 19 Jul 2023 13:44:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/PVDWaEhSIAg/upload/9857b5a78a97bb2004e204a67250f9cf.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Using audio and video files can sometimes be tricky. To a beginner, it may look like a lot of work but in reality, they are simple to work with.</p>
<p>My project idea was very simple and straightforward. I was trying to make a React app that has multiple audio files inside it. There are several buttons and when the user clicks on the button a certain audio is played.</p>
<p>My project stack was</p>
<ul>
<li><p>TypeScript</p>
</li>
<li><p>React</p>
</li>
<li><p>Tailwind</p>
</li>
</ul>
<p>JavaScript takes care of the types but with TypeScript you gotta watch your step.</p>
<p>Till now I have only worked with images in React so I googled how to use audio files and two libraries shot up.</p>
<p><a target="_blank" href="https://www.npmjs.com/package/react-sound">https://www.npmjs.com/package/react-sound</a></p>
<p><a target="_blank" href="https://www.npmjs.com/package/use-sound">https://www.npmjs.com/package/use-sound</a></p>
<p><code>use-sound</code> is a relatively new package compared to <code>react-sound</code> so I picked that up.</p>
<p>The work of libraries is to make the implementation simple and these perfectly do that. I implemented as it says in the docs.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> useSound <span class="hljs-keyword">from</span> <span class="hljs-string">'use-sound'</span>;

<span class="hljs-keyword">import</span> boopSfx <span class="hljs-keyword">from</span> <span class="hljs-string">'../../sounds/boop.mp3'</span>;

<span class="hljs-keyword">const</span> BoopButton = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> [play] = useSound(boopSfx);

  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{play}</span>&gt;</span>Boop!<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>;
};
</code></pre>
<p>The implementation was straightforward and I started using it.</p>
<p>After some days when I was making an update to the sound component I was talking to one of my friends about using and storing sound files in React, and he told me to use HTML5 <code>&lt;audio&gt;</code> component. I was like “Will that work in React? 😲”.</p>
<p>Now one thing to note here is that React also uses HTML, and React is just an abstraction of the complex JavaScript functions that convert your JSX into HTML so almost all the HTML tags and stuff work by default in React.</p>
<p>I was skeptical about whether HTML <code>&lt;audio&gt;</code> tag will work on not but then I read about the Tag on <a target="_blank" href="https://developer.mozilla.org/en-US/">MDN</a> (best resource).</p>
<p>The <code>&lt;audio&gt;</code> tag takes in an <code>src</code>and some attributes like <code>controls</code>, <code>muted</code>, etc. The <code>&lt;audio&gt;</code> tag does not have any such visual output, so if you hide the controls, nothing will be visible to you. This is perfect if you want to play audio when clicking on a custom button.</p>
<p>Coming to importing audio files. Many places including <code>use-sound</code> docs suggest to import audio files like</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> boopSfx <span class="hljs-keyword">from</span> <span class="hljs-string">'../../sounds/boop.mp3'</span>;
</code></pre>
<p>Well, this doesn’t work, at least not in my case with TypeScript. 🥲</p>
<p>This answer from StackOverflow worked for me <a target="_blank" href="https://stackoverflow.com/a/59456219/9715289">https://stackoverflow.com/a/59456219/9715289</a></p>
<p>The solution is to use ES5 <code>require()</code></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> mySound = <span class="hljs-built_in">require</span>(<span class="hljs-string">"../assets/file_name.mp3"</span>);
</code></pre>
<p>This imports the file nicely. ✌️</p>
<p>Now the final task was to add a click event to the button to play audio when the button was clicked.</p>
<p>For that my implementation is simple. I used a <code>onClick</code>event to trigger the <code>play</code>and <code>pause</code> function of the audio.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> AudioPlayer = <span class="hljs-function">() =&gt;</span> {

  <span class="hljs-keyword">const</span> audio = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"audio_tag"</span>);
  <span class="hljs-keyword">const</span> [play, setPlay] = useState(<span class="hljs-literal">false</span>);

  <span class="hljs-keyword">return</span>(
     ...
      &lt;button
        onClick={<span class="hljs-function">() =&gt;</span> {
          play ? setPlay(<span class="hljs-literal">false</span>) : setPlay(<span class="hljs-literal">true</span>);
          play ? audio.pause() : audio.play();
        }}
      &gt;
      ...
     &lt;/button&gt;
     <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">audio</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"audio_tag"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">{mySound}</span> /&gt;</span></span>
  )
}
</code></pre>
<p>This sums up the implementation</p>
<h2 id="heading-tldr">TLDR;</h2>
<p>This little incident made me realize that basic things like HTML and CSS are feature-packed and they are very well-suitable for simple tasks. In my case I just wanted to play audio upon clicking so I don’t need to add an external library for that I can just use the built-in tools to achieve what I want.</p>
<p>This in no way means that external libraries are bad. They are excellent at providing you with a simple implementation and provide additional features. But first, we should also look at what the default tools are providing us.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In the current state of the web new libraries are coming up every day and it is tempting to put them into our projects but first, we should try to assess whether that library actually provides some value or that work can be done using the built-in tools only.</p>
<p>That’s it<br />ENJOY and &lt;CODE/&gt;</p>
<blockquote>
<p><strong><em>About me:*</em></strong>I am<em> **</em>Shubh Agrawal<em>**</em>, a Full Stack Developer and I love to code, write, read and click pictures. 😁<br /><em>[</em>https://www.theshubhagrwl.in/*](https://www.theshubhagrwl.in/)</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Infinite Scroll in React - Without External Libraries]]></title><description><![CDATA[Infinite Scroll is an effect we put on websites to create a seamless user experience. This effect is no magic, it is just some clever use of JavaScript to give the website a better overall experience.
This technique is used on many websites, especial...]]></description><link>https://blog.theshubhagrwl.in/infinite-scroll-in-react-without-external-libraries</link><guid isPermaLink="true">https://blog.theshubhagrwl.in/infinite-scroll-in-react-without-external-libraries</guid><category><![CDATA[React]]></category><category><![CDATA[infinite scrolling]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Shubh Agrawal]]></dc:creator><pubDate>Sun, 05 Mar 2023 13:17:21 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/qAjJk-un3BI/upload/74141b8cf2b6512727910dffd51e1113.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Infinite Scroll is an effect we put on websites to create a seamless user experience. This effect is no magic, it is just some clever use of JavaScript to give the website a better overall experience.</p>
<p>This technique is used on many websites, especially those with a feed, e.g. YouTube.</p>
<h2 id="heading-so-how-does-this-thing-works">So how does this thing works?</h2>
<p>Let's discuss the basic idea of Infinite Scrolling.</p>
<p>In an Infinite Scroll, the user is shown a single page with limited results. When the user reaches the end of those results, more content is loaded, and this goes on.</p>
<p><strong>So what actually happens here?</strong></p>
<p>For an Infinite Scroll, we prefer an API that has <strong>pagination</strong> enabled. So first, we simply request the first page from the API. Now when the user reaches the end of the page, a new API call is made with the next page number.</p>
<p>As you might have noticed from the above paragraph, we make the API call when we reach the end of the page. There are two ways to detect the end of the page. Either the page is fully scrolled, or the last element is fully visible on the screen. In this article, we are going to learn how to exactly do this.</p>
<p>We will discuss two methods of implementing Infinite Scroll</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<ul>
<li><p>Knowledge of React Hook: useState, useRef, useEffect</p>
</li>
<li><p>A basic react application setup</p>
</li>
</ul>
<h2 id="heading-implementation-1">Implementation - #1</h2>
<p>In this method, we will use the different values of windows that are provided by the browser.</p>
<p>We need to attach a scroll event listener to the window. This will be done inside <code>useEffect</code> because the listener needs to be attached as soon as the component is mounted.</p>
<pre><code class="lang-javascript">useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-built_in">window</span>.addEventListener(<span class="hljs-string">"scroll"</span>,handleInfiniteScroll);
    <span class="hljs-keyword">return</span> <span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">window</span>.removeEventListener(<span class="hljs-string">"scroll"</span>, handleInfiniteScroll);
},[])
</code></pre>
<p>When the component is loaded, we have attached a Scroll Event listener to the page which will run <code>handleInfiniteScroll</code> the method. Then we remove that event listener in the cleanup method of <code>useEffect</code>.</p>
<blockquote>
<p>Try to remove the cleanup method (return) in the <code>useEffect</code> and run the code. Observer carefully how the requests are being made then.</p>
</blockquote>
<p>Let's define <code>handleInfiniteScroll</code> method</p>
<pre><code class="lang-javascript"><span class="hljs-comment">//states</span>
<span class="hljs-keyword">const</span> [page, setPage] = useState(<span class="hljs-number">1</span>);
<span class="hljs-keyword">const</span> [loading, setLoading] = useState(<span class="hljs-literal">true</span>);

<span class="hljs-comment">//method</span>
<span class="hljs-keyword">const</span> handleInfiniteScroll = <span class="hljs-keyword">async</span> () =&gt; {
    <span class="hljs-keyword">try</span> {
      <span class="hljs-keyword">if</span> (
        <span class="hljs-built_in">window</span>.innerHeight + <span class="hljs-built_in">window</span>.document.documentElement.scrollTop + <span class="hljs-number">1</span> &gt;=
        <span class="hljs-built_in">window</span>.document.documentElement.scrollHeight
      ) {
        setLoading(<span class="hljs-literal">true</span>);
        setPage(<span class="hljs-function">(<span class="hljs-params">prev</span>) =&gt;</span> prev + <span class="hljs-number">1</span>);
      }
    } <span class="hljs-keyword">catch</span> (error) {
      <span class="hljs-built_in">console</span>.error(error);
    }
  };
</code></pre>
<p>We have declared two states here, <code>page</code> keeps track of the page number because our API supports pagination so we need to pass a page number to it.</p>
<p>In the <code>handleInfiniteScroll</code> method, we are checking for the condition that, the sum of <code>window.innerHeight</code> and <code>window.document.documentElement.scrollTop</code> + an additional number of pixels is greater than equal to <code>window.document.scrollHeight.</code></p>
<p><code>window.innerHeight</code>: Returns the interior height of the window in pixels<br /><code>window.document.documentElement.scrollTop</code> : Returns the number of pixels that are scrolled vertically<br /><code>window.document.documentElement.scrollHeight</code>: Returns the total height of content (which is yet not visible on the screen)</p>
<p>So when <code>innerHeight</code> and <code>scrollTop</code> are added together they will always result in <code>scrollHeight</code>. You can verify this by doing a console log of these values and checking them manually.</p>
<p>This method will make changes to the state <strong>page.</strong> So we will add an <code>useEffect</code> which will call our API.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">//state</span>
<span class="hljs-keyword">const</span> [card, setCard] = useState([])

<span class="hljs-comment">//method</span>
<span class="hljs-keyword">const</span> getCardData = <span class="hljs-keyword">async</span> () =&gt; {
    <span class="hljs-keyword">const</span> res = <span class="hljs-keyword">await</span> fetch(
      <span class="hljs-string">`https://jsonplaceholder.typicode.com/posts?_limit=9&amp;_page=<span class="hljs-subst">${page}</span>`</span>
    );
    <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> res.json();
    <span class="hljs-comment">//solved: the first page is repeated twice</span>
    <span class="hljs-keyword">if</span> (page !== <span class="hljs-number">1</span>) {
      setCard(<span class="hljs-function">(<span class="hljs-params">prev</span>) =&gt;</span> [...prev, ...data]);
    } <span class="hljs-keyword">else</span> {
      setCard([...data]);
    }
    setLoading(<span class="hljs-literal">false</span>);
  };

<span class="hljs-comment">//useEffect</span>
useEffect(<span class="hljs-function">() =&gt;</span> {
  getCardData();
}, [page]);
</code></pre>
<p>This piece of code is really simple. All we have done here is called the API and stored the data in <code>setCard()</code> (probably not a good name 😅)</p>
<p>Now that we have all the main code setup we can simply pass our data which is in <code>card</code> to a component that will render the items.</p>
<p>And THAT'S IT!!</p>
<p>You get an infinite scroll there.</p>
<p>Here is a live demo of the app that I created: <a target="_blank" href="https://effortless-granita-f1a33d.netlify.app/">https://effortless-granita-f1a33d.netlify.app/</a></p>
<p>And you can get the code here: <a target="_blank" href="https://github.com/theshubhagrwl/infinite-scroll-react-window">https://github.com/theshubhagrwl/infinite-scroll-react-window</a></p>
<h2 id="heading-implementation-2">Implementation - #2</h2>
<p>In this... well let's continue this is next article.</p>
<p>To give you a hint, in the second approach we will use the <code>IntersectionObserver</code> API</p>
<p>Good Day!</p>
]]></content:encoded></item><item><title><![CDATA[How I Read Less Than A Book A Month]]></title><description><![CDATA[The Internet is the place where all smart people spread their fame, but no one cares about setbacks.
“How I read a book a week?” this is one of the many internet glories we see nowadays. This is grown with the fact that people who read books are cons...]]></description><link>https://blog.theshubhagrwl.in/how-i-read-less-than-a-book-a-month</link><guid isPermaLink="true">https://blog.theshubhagrwl.in/how-i-read-less-than-a-book-a-month</guid><category><![CDATA[books]]></category><dc:creator><![CDATA[Shubh Agrawal]]></dc:creator><pubDate>Thu, 10 Jun 2021 13:19:28 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1623336839582/ffHKWaRFe.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The Internet is the place where all smart people spread their fame, but no one cares about setbacks.</p>
<p><em>“How I read a book a week?”</em> this is one of the many internet glories we see nowadays. This is grown with the fact that people who read books are considered smart. Yeah, they are smarter than the average because books provide a different perspective to the individual. So it increases the knowledge of the reader.</p>
<p>But there is one thing made famous by the online <em>“influencers”</em> that you should read plenty of books. This is a good piece of advice. Reading for knowledge is a good thing, but reading for the sake of reading or increasing the count to show off on social media is dumb.</p>
<p>Through a simple YouTube search, you can find a ton of people who will tell you how to read a book per week. These people can be right in their ways of doing things because they have to get views and show others the numbers and be considered <em>“smart”</em>. But learning is not a number game.</p>
<p>I have two main concerns for reading a book a week:</p>
<h2 id="1learning">1.Learning</h2>
<p>Let’s say you read a book per week. I don’t think most books are simple enough to be understood in a single read.</p>
<p>I read a tweet by Kunal Shah where the gist was: Reading a book is not about remembering everything you read. It’s more about acquiring a new perspective.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://twitter.com/kunalb11/status/1385853971424813057?s=20">https://twitter.com/kunalb11/status/1385853971424813057?s=20</a></div>
<p>One read cannot change the perspective. To get the whole about the book you have to go a little slow and deep and think about it.</p>
<p>This takes me to the next point,</p>
<h2 id="2time">2.Time</h2>
<p>Reading is time-consuming. Unless you are reading a short book like <em>“Who moved my cheese?”</em> you can’t just wrap up a book in a week. The majority of the books are decently long and need a focused mind to read.</p>
<p>I don’t think you are free enough to read the whole day.
As a developer and a student, I have to manage time between work, college, and personal things. The people making videos are also taking out time to make videos. Right?</p>
<h2 id="3are-you-a-scanner">3.Are you a Scanner?</h2>
<p>When I started reading books, YouTube suggested videos on how to read a book quickly. These are seductive titles and as Naval said in Joe Rogan Podcast <em>“You have to buy that stupid car to understand it is stupid”.</em></p>
<p>The main point of them(videos) was that you don’t have to read every single line. You just have to SKIM/SCAN the book and read the interesting things.</p>
<p>This may be applied to highly repetitive titles like <em>“The Power of Your Subconscious Mind”</em>, but I don’t get what these smart folks can learn by scanning or skimming <em>“The Psychology of Money”.</em> They’re probably smarter than the writer… I don’t know.</p>
<h2 id="whats-my-way">What's my way?</h2>
<p>I am sharing my way, but I strongly recommend finding your way rather than blindly following someone.
While writing this article I was reading <em>“The Psychology of money”.</em></p>
<p>I sit, read the book without a highlighter or pencil and read for about 30mins. You can do it chapter-wise as well.</p>
<p>The main thing is that you just need to read the book and don’t care too much about understanding everything you are reading. It may sound counterintuitive, but give it a try. It’s like skimming and scanning but at a lot slower pace.</p>
<p>This will give you an idea about what is interesting and what is not. This can take you approx. a week or two depending on the book. Then you can post on social media LOL</p>
<p>After the initial phase, take a break of a day or two and after that,
Take a pencil or highlighter, start reading the book with full focus and start marking the important quotes, lines, ideas, vocab. This will be helpful as you already have an idea of what is important. Also, sometimes you don’t get what the writer is trying to say in the first go but when you re-read with concentration you get the point. You can get that Aha moment.</p>
<p>I do this for around 30mins, again depends on the book and you. This is the part where you extract the most out of a book.</p>
<p>One more thing I do is write the small points I find in the book in the Sticky Notes app, then later tweet them. This increases my understanding and also writing skills, this helps me to understand and write better.</p>
<hr />

<p>Whenever you are learning something it is better to follow <em>“Spaced repetition”.</em> The tweets or the small notes you will make will support that. This way you don’t have to read the whole book again, but will be able to get all the useful information out of it whenever you want.</p>
<p>Playing the number game is not always a good idea and people on social media are obsessed with this game.
Reading for fun and learning is what you should look for, not for Social Validation.</p>
<p>A tweet about social validation I wrote after watching a video by Mark Mason.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://twitter.com/theshubhagrwl/status/1395711772867272710">https://twitter.com/theshubhagrwl/status/1395711772867272710</a></div>
<p>Thanks for putting your valuable time on this article.
If you enjoyed this article then consider supporting me. Thanks Again!</p>
<p><a target="_blank" href="https://www.buymeacoffee.com/theshubhagrwl">
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1623336837917/-SSOcSUns.png" alt="https://www.buymeacoffee.com/theshubhagrwl" /></a></p>
]]></content:encoded></item><item><title><![CDATA[Deploying Django App to Heroku: Full Guide]]></title><description><![CDATA[Introduction
You made an app with Django. Great! , and you are excited to show it to everyone on the planet. For that, you need to put it somewhere online so that others can access it.
Okay, you did some research and selected Heroku. Great Choice!👍
...]]></description><link>https://blog.theshubhagrwl.in/deploying-django-app-to-heroku-full-guide</link><guid isPermaLink="true">https://blog.theshubhagrwl.in/deploying-django-app-to-heroku-full-guide</guid><category><![CDATA[Django]]></category><category><![CDATA[Heroku]]></category><category><![CDATA[Web Hosting]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Python]]></category><dc:creator><![CDATA[Shubh Agrawal]]></dc:creator><pubDate>Thu, 28 Jan 2021 16:33:21 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1600618104276/OyExGUSsy.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="introduction">Introduction</h1>
<p>You made an app with Django. Great! , and you are excited to show it to everyone on the planet. For that, you need to put it somewhere online so that others can access it.</p>
<p>Okay, you did some research and selected Heroku. Great Choice!👍</p>
<p>Now you started to deploy your app and did your research online and now you have many different resources to follow which suggest millions of ways to do it.
So you are confused, frustrated and stuck and somehow managed to put host it but after that, to your surprise, you found that your CSS files didn't show up.🤦‍♂️</p>
<p>OK, Now let's solve your problems. This article covers almost everything that you will need.</p>
<h2 id="roadmap">Roadmap</h2>
<ul>
<li>Install Required Tools</li>
<li>Create Required Files</li>
<li>Create a Heroku app</li>
<li>Edit <a target="_blank" href="http://settings.py/">settings.py</a></li>
<li>Make changes for static files</li>
</ul>
<h1 id="install-the-required-tools">Install the required tools</h1>
<p>For deploying to Heroku you need to have Heroku CLI (Command Line Interface) installed.</p>
<p>You can do this by going here: <a target="_blank" href="https://devcenter.heroku.com/articles/heroku-cli">https://devcenter.heroku.com/articles/heroku-cli</a></p>
<p>CLI is required because it will enable us to use features like login, run migrations etc.</p>
<p>Next we will need <strong>gunicorn</strong> and <strong>whitenoise</strong></p>
<pre><code class="lang-bash">pip install gunicorn
pip install whitenoise
</code></pre>
<p>We will use Postgres Heroku so we will also need <strong>dj_database_url 
(</strong><a target="_blank" href="https://pypi.org/project/dj-database-url/">https://pypi.org/project/dj-database-url/</a><strong>)</strong></p>
<pre><code class="lang-bash">pip install dj-database-url
</code></pre>
<p>Add it in MIDDLEWARE in <a target="_blank" href="http://settings.py/">settings.py</a> file</p>
<pre><code class="lang-bash">MIDDLEWARE = [
  <span class="hljs-comment"># 'django.middleware.security.SecurityMiddleware',</span>
  <span class="hljs-string">'whitenoise.middleware.WhiteNoiseMiddleware'</span>,
  <span class="hljs-comment"># ...</span>
]
</code></pre>
<h2 id="use-of-gunicorn">Use of gunicorn?</h2>
<p>The Django and Flask web frameworks feature convenient built-in web servers, but these blocking servers only process a single request at a time. If you deploy with one of these servers on Heroku, your dyno resources will be underutilized and your application will feel unresponsive.</p>
<p><a target="_blank" href="https://gunicorn.org/">Gunicorn</a> is a pure-Python HTTP server for WSGI applications. It allows you to run any Python application concurrently by running multiple Python processes within a single dyno. It provides a perfect balance of performance, flexibility, and configuration simplicity.</p>
<p><a target="_blank" href="https://devcenter.heroku.com/articles/python-gunicorn">https://devcenter.heroku.com/articles/python-gunicorn</a></p>
<h2 id="use-of-whitenoise">Use of WhiteNoise</h2>
<p>With a couple of lines of config WhiteNoise allows your web app to serve its own static files, making it a self-contained unit that can be deployed anywhere without relying on nginx, Amazon S3 or any other external service. (Especially useful on Heroku, OpenShift and other PaaS providers.)</p>
<p><a target="_blank" href="http://whitenoise.evans.io/en/stable/">http://whitenoise.evans.io/en/stable/</a></p>
<h1 id="create-files-required-by-heroku">Create files required by Heroku</h1>
<p>After installing the CLI let's create all the files that Heroku needs.</p>
<p>Files are :</p>
<ol>
<li><p><strong>requirements.txt</strong></p>
<p> Requirements.txt is the simplest to make. Just run the command</p>
<pre><code> pip <span class="hljs-keyword">freeze</span> &gt; requirements.txt
</code></pre><p> This command will make a .txt file which will contain all the packages that are required by your current Django Application.</p>
<p> <strong>Note: If you add any package further then run this command again, this way the file will be updated with the new packages</strong></p>
<p> <strong>What is the use of <em>requirements.txt</em>?</strong>
 As you can see that it contains all the dependencies that your app requires. So when you put your app on Heroku it will tell Heroku which packages to install.</p>
</li>
<li><p><strong>Procfile</strong></p>
<p> After this make a new file name <strong>Procfile</strong> and do not put any extension in it. 
 It is a file required by Heroku</p>
<p> According to Heroku :</p>
<p> Heroku apps include a <strong>Procfile</strong> that specifies the commands that are executed by the app on startup. You can use a Procfile to declare a variety of <strong>process types</strong>, including:</p>
<ul>
<li>Your app’s web server</li>
<li>Multiple types of worker processes</li>
<li>A singleton process, such as a <a target="_blank" href="https://devcenter.heroku.com/articles/scheduled-jobs-custom-clock-processes">clock</a></li>
<li><p>Tasks to run <a target="_blank" href="https://devcenter.heroku.com/articles/release-phase">before a new release is deployed</a></p>
<p>For our app we can write the following command</p>
<pre><code class="lang-jsx">web: gunicorn name_of_your_app.wsgi —log-file -
</code></pre>
<p>If you are confused about your app name, then just go to <strong>wsgi.py</strong> file in your project and you will find your app name there.</p>
</li>
</ul>
</li>
<li><p><strong>runtime.txt</strong></p>
<p> After this make a new text file called runtime.txt and inside it write the python version you are using in the following format</p>
<p> <code>python-3.8.1</code></p>
<p> That's all the files we require. Now we have to start editing our <a target="_blank" href="http://settings.py/">settings.py</a> file.</p>
</li>
</ol>
<h1 id="create-a-heroku-app">Create a Heroku app</h1>
<p>This is a simple step and can be done in 2 ways, either by command line or through the Heroku Website.</p>
<p>Let's use the Heroku Website for now.</p>
<ul>
<li>After making Heroku Account you will see an option to create a new app</li>
<li>It will ask you for a name, the name should be unique. After hit and trials, you will be redirected to your app dashboard.</li>
<li>There are many options to play with here but let's go to the settings tab and there click on Reveal Config Vars</li>
<li>In the <strong>KEY</strong> write <strong>SECRET_KEY</strong> and in <strong>VALUE</strong> paste the secret key from the settings file and you can change it because only this key will be used.</li>
</ul>
<p>That's all for now. We will revisit it soon.</p>
<h1 id="edit-settingspy">Edit settings.py</h1>
<p>There are quite a few changes that should be made in this file.</p>
<p>Lets' start</p>
<p>First change</p>
<pre><code><span class="hljs-attr">DEBUG</span> = <span class="hljs-literal">False</span>
</code></pre><p>In the allowed hosts enter the domain of your Heroku app</p>
<p>eg.</p>
<pre><code><span class="hljs-attr">ALLOWED_HOSTS</span> = [<span class="hljs-string">"your_app_name.herokuapp.com"</span>, <span class="hljs-string">"127.0.0.1"</span>]
</code></pre><p>Replace the <strong>SECRET_KEY</strong> variable with the following (assuming that you have setup the secret key in heroku from the previous step)</p>
<pre><code><span class="hljs-attr">SECRET_KEY</span> = os.environ.get(<span class="hljs-string">'SECRET_KEY'</span>)
</code></pre><p>What this does is, it gets the <strong>SECRET_KEY</strong> from the environment. In our case, we can set the <strong>secret_key</strong> in Heroku and it will provide the key here through environment variables.</p>
<h1 id="setup-static-files">Setup static files</h1>
<p>In settings file, you will find</p>
<pre><code><span class="hljs-attr">STATIC_URL</span> = <span class="hljs-string">'/static/'</span>
</code></pre><p>Replace this with the following code</p>
<pre><code>STATIC_ROOT = os.path.<span class="hljs-keyword">join</span>(BASE_DIR, <span class="hljs-string">'staticfiles'</span>)
STATIC_URL = <span class="hljs-string">'/static/'</span>

STATICFILES_DIRS = (
    os.path.<span class="hljs-keyword">join</span>(BASE_DIR, <span class="hljs-string">'static'</span>),
)
</code></pre><p>Basically this will create a folder named <strong>static</strong> which will hold all the static files (like CSS files).</p>
<p>If your App contains images that you have stored on it or the user has the ability to store then add the following lines</p>
<pre><code><span class="hljs-attr">MEDIA_URL</span> = <span class="hljs-string">"/media/"</span>
<span class="hljs-attr">MEDIA_ROOT</span> = os.path.join(BASE_DIR, <span class="hljs-string">'media'</span>)
</code></pre><p>This is pretty much the same as the above</p>
<p>There is one more thing you need to do.</p>
<p>If you have media files then to allow Django to server them you have to add a line to your <a target="_blank" href="http://urls.py/">urls.py</a> file of the project (top-level urls file)</p>
<pre><code><span class="hljs-keyword">from</span> django.conf import settings
<span class="hljs-keyword">from</span> django.conf.urls.<span class="hljs-built_in">static</span> import <span class="hljs-built_in">static</span>

urlpatterns = [
    <span class="hljs-comment"># ... the rest of your URLconf goes here ...</span>
] + <span class="hljs-built_in">static</span>(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
</code></pre><p>I highly recommend you have a look at this documentation.</p>
<p><a target="_blank" href="https://docs.djangoproject.com/en/3.1/howto/static-files/">https://docs.djangoproject.com/en/3.1/howto/static-files/</a></p>
<p>So we have completed the 2 most important steps for deploying</p>
<h1 id="adding-code-to-github">Adding Code to Github</h1>
<p>Make a new Github Repo and add all of your code in it.
<a target="_blank" href="https://dev.to/ayomide_bajo/pushing-an-existing-repository-to-github-1f68">Use this post a reference</a></p>
<p>After that go to Heroku and under the Deploy tab, you will see an option to connect Github.</p>
<p>Connect your repo and you can hit the deploy button to deploy your app.</p>
<h1 id="using-heroku-postgres">Using Heroku Postgres</h1>
<h2 id="but-what-is-the-need-i-am-using-sqlite-already">But What is the Need? I am using SQLite already!</h2>
<p>The problem is that</p>
<blockquote>
<p>The Heroku filesystem is ephemeral - that means that any changes to the filesystem whilst the dyno is running only last until that dyno is shut down or restarted. Each dyno boots with a clean copy of the filesystem from the most recent deploy. This is similar to how many container-based systems, such as Docker, operate.
In addition, under normal operations, dynos will restart every day in a process known as "Cycling".
(<a target="_blank" href="https://help.heroku.com/K1PPS2WM/why-are-my-file-uploads-missing-deleted">https://help.heroku.com/K1PPS2WM/why-are-my-file-uploads-missing-deleted</a>)</p>
</blockquote>
<p>Basically all the data you will store will get deleted every <strong>24hrs.</strong></p>
<p>To solve Heroku suggest using either AWS or Postgres. Heroku has made it very simple to use Postgres.</p>
<p>Let's do this,</p>
<p>Go to your app dashboard and in the Resources section search for Postgres. Select it and you will get something like this</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1600019180954/gCljPdfDB.png" alt="https://cdn.hashnode.com/res/hashnode/image/upload/v1600019180954/gCljPdfDB.png" /></p>
<p>Now go to the settings tab and reveal the config vars</p>
<p>You will see a <strong>DATABASE_URL</strong> key there. It means that Heroku has added the database and now we have to tell our app to use this database.</p>
<p>For this, we will  need <strong>dj_database_url</strong>. </p>
<p>Now paste the following code below <strong>DATABASES</strong> in settings file</p>
<pre><code>db_from_env = dj_database_url.config(conn_max_age=<span class="hljs-number">600</span>)
DATABASES[<span class="hljs-string">'default'</span>].<span class="hljs-keyword">update</span>(db_from_env)
</code></pre><p>That's it, now your database is setup!</p>
<p>Currently, your database is empty and you might want to fill it.</p>
<ul>
<li>Open terminal</li>
<li>type → <code>heroku login</code></li>
<li>After the login run the following commands</li>
</ul>
<pre><code class="lang-bash">heroku run python manage.py makemigrations
heroku run python manage.py migrate
heroku run python manage.py createsuperuser
</code></pre>
<p>Now your app is ready to be deployed</p>
<p>either use CLI or push it through GitHub</p>
<pre><code>git <span class="hljs-keyword">push</span> heroku master
</code></pre><hr />
<p>OK, so it's finally done. It is a bit long but quite easy to do because you have to make only some minor changes, nothing too big.</p>
<p>If there is any kind of improvement then please tell me in the comments.</p>
<hr />
<h2 id="check-out-my-other-articles">Check Out my other articles</h2>
<p><a target="_blank" href="https://theshubhagrwl.hashnode.dev/the-world-of-css-should-you-write-your-own-css-or-use-any-library">https://theshubhagrwl.hashnode.dev/the-world-of-css-should-you-write-your-own-css-or-use-any-library</a></p>
<p><a target="_blank" href="https://theshubhagrwl.hashnode.dev/custom-user-model-in-django-3">https://theshubhagrwl.hashnode.dev/custom-user-model-in-django-3</a></p>
<h2 id="visit-my-website-and-lets-get-connected-on-social-platforms">Visit my website and let's get connected on Social Platforms :)</h2>
<p><a target="_blank" href="https://theshubhagrwl.vercel.app/">https://theshubhagrwl.vercel.app/</a></p>
]]></content:encoded></item><item><title><![CDATA[The World Of CSS. Should you write your own CSS or use any Library?]]></title><description><![CDATA[Web Development is a booming field, there are thousands of web developers and hundreds of technologies that assist the awesome developers in achieving their goals.
To a newcomer or even an experienced person glancing at the choices available can be t...]]></description><link>https://blog.theshubhagrwl.in/the-world-of-css-should-you-write-your-own-css-or-use-any-library</link><guid isPermaLink="true">https://blog.theshubhagrwl.in/the-world-of-css-should-you-write-your-own-css-or-use-any-library</guid><category><![CDATA[CSS]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Shubh Agrawal]]></dc:creator><pubDate>Tue, 26 Jan 2021 09:56:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1611827933702/H6dTZhda6.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Web Development is a booming field, there are thousands of web developers and hundreds of technologies that assist the awesome developers in achieving their goals.</p>
<p>To a newcomer or even an experienced person glancing at the choices available can be too much confusing and overwhelming. There is literally a framework or library for everything. In JavaScript, you even have one for checking if the number is even and you will be amazed by its popularity <a target="_blank" href="https://github.com/i-voted-for-trump/is-even">Check here</a></p>
<p>Anyways, coming to the topic in the midst of so much pre-written code that can reduce a lot of work for you, writing all the code from scratch can look like a stupid question.</p>
<p>In short, the answer is totally dependent. There is no clear answer to this question. The answer totally depends on you and this is what I have tried to explain in the rest of this post.
I have tried to keep it ASAP (As Short As Possible)</p>
<p>Let's Discuss more.</p>
<h1 id="advantages-of-libraries-and-frameworks">Advantages of Libraries &amp; Frameworks</h1>
<ul>
<li>Pre Written Code → Lot less work to do</li>
<li>Consistency → Styles look the same across the website</li>
</ul>
<p>The biggest and the most obvious advantage of the prewritten code is that it is <strong>"pre-written"</strong> so you have to do a lot less work in writing everything from scratch. Like if you are using React and you use Material UI then you get a ton of subtle animations already in the button styles, the Grid System which is one of the most useful things in MUI and for the most part you don't have to worry about your site being responsive.</p>
<p>Another awesome thing you can achieve is <strong>"consistency"</strong>, i.e. your design looks the same on your whole website. This is because you are mostly referring to the same components.</p>
<h1 id="disadvantages-of-libraries-and-frameworks">Disadvantages of Libraries and Frameworks</h1>
<ul>
<li>Pre-written Code → Can be hard to modify code</li>
<li>Consistency → Code can be consistent across many <em>'other'</em> websites</li>
<li>External Libraries can sometimes be bulky</li>
</ul>
<p>It is a fact that everything has advantages and disadvantages unless it's VSCode (No more bad jokes ahead!) so does this.</p>
<p><em>One thing to note here is that these are the disadvantages according to me, so it is subjective and may or may not apply to you, I have tried to give you a general idea from my experience.</em></p>
<p>The first negative point according to me is the <strong>"pre-written"</strong> code. This is a subjective point as it totally depends on the person doing the thing. For a beginner, it can be difficult for her to make a lot of customizations. I have personally felt this while working with MUI for the first time, it took me a good amount of time to figure out the customizations I wanted to make. But if you are a bit experienced then you can get along with this pretty easily.</p>
<p>The other disadvantage that I think, and is a norm among the people who use Bootstrap is that the sites made with Bootstrap look like <strong>"Bootstrapped Sites"</strong>. What I think is, this is true for a beginner but an experienced person can easily get around this. So again it depends.</p>
<p>Another issue can be that the extra libraries can be <strong>"bulky"</strong>, I guess this was the case with Bootstrap because Bootstrap 4 used jQuery which was quite heavy. I think jQuery is removed in the later version of Bootstrap. Feel free to correct me if I am wrong.</p>
<h1 id="addressing-the-elephant-in-the-room">Addressing the Elephant in the Room</h1>
<p>Personally, I have used both ways to create websites.
I one project I used MUI and tried to customize it a lot (https://github.com/theshubhagrwl/MyMovieTime) while in the other I used only Custom CSS (https://theshubhagrwl.vercel.app/) and as a user, you won't be able to spot the difference but the main difference comes in the <strong>development time</strong> and the <strong>knowledge of CSS you have</strong>.</p>
<p>My advice is, if you are a web developer then you shouldn't be afraid of CSS, actually, I used to hate CSS at one time, but then I met JavaScript (I promise this was the last one). Writing your own CSS can drastically improve your CSS knowledge.</p>
<p>The other and sometimes more important thing is the amount of time you want to spend on a project. If you want to get some project done quickly and not caring a lot about the design then it is better to use some framework or library because it will have a ton of stuff done for you.</p>
<p>So I hope this post proved helpful for you. Give it a like if it helped you and share it with others.</p>
<p>Connect with me on Twitter: https://twitter.com/theshubhagrwl</p>
<p>You can see my work on my website: 
https://theshubhagrwl.vercel.app/</p>
<p>Thanks for spending your valuable time on this post.🙏</p>
]]></content:encoded></item><item><title><![CDATA[Should you Track your Time?]]></title><description><![CDATA[The reason behind this post
About 6 months ago during my college life, I was watching a lot of productivity videos on YouTube and tried to follow the advice in them. Time tracking is one of the most common advice which many YouTubers give. The main r...]]></description><link>https://blog.theshubhagrwl.in/should-you-track-your-time</link><guid isPermaLink="true">https://blog.theshubhagrwl.in/should-you-track-your-time</guid><category><![CDATA[Productivity]]></category><category><![CDATA[General Advice]]></category><category><![CDATA[Experience ]]></category><category><![CDATA[advice]]></category><dc:creator><![CDATA[Shubh Agrawal]]></dc:creator><pubDate>Sun, 06 Sep 2020 18:19:58 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1599416309327/2QSYxpn0r.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[

<p><span class="r"></span></p>
<h1 id="the-reason-behind-this-post">The reason behind this post</h1>
<p>About 6 months ago during my college life, I was watching a lot of productivity videos on YouTube and tried to follow the advice in them. Time tracking is one of the most common advice which many YouTubers give. The main reason for this is by doing so we get to know where our time is going and we kind of learn to estimate time more precisely. Humans are very bad at estimating and this is the reason this is a famous approach.</p>
<p>I used Toggl which is an awesome app to start time tracking. There are also several other but this not a place to discuss which one to choose.</p>
<p>I tracked my time for around 6 months. Daily. It was the most consistent thing that I did. LOL</p>
<h1 id="benefits">Benefits</h1>
<p>Whenever you start a new thing you are generally more excited about it but slowly the fun goes away. This is a normal thing.</p>
<p>For analogy you can consider it like a Soda Bottle, it has tremendous energy but once you shake and open it after a few seconds it becomes like normal water. This is the same thing that happens with humans.</p>
<p>When I started tracking the time I was excited and tried to track almost every single task. This was way too much as I am a Human, not a Robot 🤖 , and in the world where the average attention span is 15seconds, it is harder to focus on one thing.</p>
<p>To counter this problem I made a threshold. I started tracking all those tasks that took more than or equal to 30mins. This was helpful and due to this, I was also not in the hurry to make an entry in the app. That was too much.</p>
<p>So I continued this and after I week when I was gazing at my weekly summary I was able to see the tasks which I did the most or in other words where my time went. One more thing that was the time when there was a lockdown due to a pandemic and I had too much time, so it was kind of necessary to keep a track where I am spending my time.</p>
<p>This went well for 3 months, I was motivated to spend more time on a single task so that I can put it on the app and it was working. A kind of habit developed in me.</p>
<h1 id="problems-you-might-face">Problems you might face</h1>
<p>Now if you follow the last paragraph and want to start tracking your time then it is good, go on, give it a try. Don’t read further, Experiment it.</p>
<p>If you are reading this then here I would like to tell you some problems that I faced.</p>
<p>When maintaining a time log becomes your habit and if somehow you are unable to get the hours that you spend the last day or week then there comes an element of frustration. It may sound a little silly but it will happen when you do this consistently for around 3 months. And if this frustration repeats then our mind comes up with the brilliant strategy of cheating. This happened to me, I increased 5–10mintues on tasks just to meet that goal. This can make you less predictive about how much time you need.</p>
<p>Another big disadvantage, what happened to me was that I was racing against the clock and not the work. If I had some side task which I wasn’t tracking but it was necessary then I was delaying it and I know it’s a little hard to explain but it was not doing too good for me.</p>
<p>So I decided to give it a break.</p>
<h1 id="so-what-happened-after-that">So What Happened after that?</h1>
<p>After facing some issues I decided to not track time for a week. This was very helpful for me. After 6 months of consistently marinating a log now, I was free. I did whatever, whenever and for how long I want to do and it was a good feeling. I had one less thing to worry about. I also analyzed that I was even more productive than before.</p>
<h1 id="tldr">TL;DR</h1>
<p>The best advice that I can give is Start Tracking your time. Do it till you don’t face the above-mentioned problems.</p>
<p>Time tracking taught me to give time to a task and not to rush through many things at a time. This was going great but when I found I was cheating with myself I had to do some change. So I quit time tracking and it helped me. Probably after some time, I will start it again.</p>
<p>Thanks for giving your valuable time to this post!</p>
<p>Give it a Like if you liked it.</p>
<h2 id="a-little-about-me">A little about me</h2>
<p><em>I am a Full Stack Developer and a Technology lover. Other than technology I love reading and gaming.</em></p>
<p><em>Checkout my portfolio:</em> <a target="_blank" href="https://theshubhagrwl.netlify.app/"><em>https://theshubhagrwl.netlify.app/</em></a> <em>and let’s connect on social platforms.</em>😉</p>
]]></content:encoded></item><item><title><![CDATA[Custom User Model in Django 3]]></title><description><![CDATA[Introduction
Hi, in this post we will learn to make a Custom User Model in Django 3 and we will also change the default login functionality of the Django Admin. We will use Email and Password to log in.
Motivation
I had to make a Custom User for my a...]]></description><link>https://blog.theshubhagrwl.in/custom-user-model-in-django-3</link><guid isPermaLink="true">https://blog.theshubhagrwl.in/custom-user-model-in-django-3</guid><category><![CDATA[Python]]></category><category><![CDATA[Django]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Shubh Agrawal]]></dc:creator><pubDate>Sun, 16 Aug 2020 04:16:40 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1599020791656/ZpLhcy8iG.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[

<h1 id="introduction">Introduction</h1>
<p>Hi, in this post we will learn to make a Custom User Model in Django 3 and we will also change the default login functionality of the Django Admin. We will use Email and Password to log in.</p>
<h1 id="motivation">Motivation</h1>
<p>I had to make a Custom User for my app, I was able to make the model but the problem was <i>createsuperuser</i> command was not working. To debug it I had to do a lot of research and the problem was most of the resources at that time were outdated, so I decided to write this post. </p>
<p>I have made a <a target="_blank" href="https://github.com/theshubhagrwl/django_custom_user_app">GitHub</a> repo, so if you want you can directly use that (instructions are there)</p>
<h1 id="lets-get-started">Let's Get Started</h1>
<p>First of all, make a <b>Django Project</b> and create an app called <b>users</b></p>
<h2 id="now-we-can-start-editing-the-modelspy-file-inside-our-users-app">Now we can start editing the models.py file inside our users app</h2>
<p>Before editing let's do some theory. <br />
What are <strong>managers</strong> in Django?</p>
<blockquote>
<p>A Manager is an interface through which database query operations are provided to Django models. At least one Manager exists for every model in a Django application.- Django Docs</p>
</blockquote>
<p>Simply speaking Managers provide us a way to manage our model. We can implement this by making our model a subclass of the Manager Class. The manager class is the place where commands like <em>createsuperuser</em> can be edited.
Now open up the <strong>models.py</strong> and put the following code in it</p>
<div class="gist-block embed-wrapper" data-gist-show-loading="false" data-id="1b8dd0987c84e820e9fd7befa0d7aecc"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a href="https://gist.github.com/theshubhagrwl/1b8dd0987c84e820e9fd7befa0d7aecc" class="embed-card">https://gist.github.com/theshubhagrwl/1b8dd0987c84e820e9fd7befa0d7aecc</a></div><p>The most important thing to note here is the <em>is_staff</em> and <em>is_superuser</em> attributes. Making a typo in this can cause a hard time debugging. <br /></p>
<h2 id="what-have-we-done-here">What have we done here?</h2>
<p>We have made a <strong>manger</strong> for our user model. 
Inside of this, we have made 2 functions called <strong><em>create_user</em></strong> and <strong><em>create_superuser</em></strong>. 
<em>create_user</em>, as the name suggests, creates a new user, and <em>create_superuser</em> is used to create a superuser by setting <strong><em>is_staff</em></strong> and <strong><em>is_superuser</em></strong> to true. <br />
After the manager, we have our usual model.<br /> 
We have set <strong><em>username</em></strong> to None because we do not want to include a username.<br />
<strong><em>USERNAME_FIELD</em></strong> in it indicated which we declare 'email'. This should be unique.<br />
<em>session_token</em> is an optional field. I have it there because I was making my custom token. <br />
The last line of the models.py indicates that the CustomUser is an object of UserManager.</p>
<h1 id="important-thing">Important Thing</h1>
<p>After you have made the model, Open settings.py file and add a line in it</p>
<pre><code class="lang-python">AUTH_USER_MODEL = <span class="hljs-string">'users.CustomUser'</span>
</code></pre>
<blockquote>
<p>Django allows you to override the default user model by providing a value for the AUTH_USER_MODEL setting that references a custom model. This dotted pair describes the name of the Django app (which must be in your INSTALLED_APPS), and the name of the Django model that you wish to use as your user model. -Django Docs</p>
</blockquote>
<h1 id="last-steps">Last Steps</h1>
<p>Now you can run the migrations commands and create superuser also.</p>
<pre><code class="lang-shell">py manage.py makemigrations
py manage.py migrate
py manage.py createsuperuser
</code></pre>
<p>It will ask for your email and password. Give it the details.</p>
<h2 id="dont-forget-to-register-the-app-in-admin">Don't Forget to register the app in admin</h2>
<pre><code class="lang-python">admin.site.register(CustomUser)
</code></pre>
<p>Now you can run the server and login with your email and password in the admin panel
<br />
Enjoy 😎 <br />
<em>If you have any suggestions then please let me know</em>
<br />
Check out my portfolio: https://theshubhagrwl.netlify.app/</p>
<h4 id="connect-with-me-on-social-platforms">Connect with me on Social Platforms:</h4>
<p>LinkedIn: https://www.linkedin.com/in/theshubhagrwl/</p>
<p>Twitter: https://twitter.com/theshubhagrwl/</p>
<p>GitHub: https://github.com/theshubhagrwl</p>
<p>Instagram: https://www.instagram.com/theshubhagrwl/</p>
<p>This post was originally written on <a target="_blank" href="https://medium.com/@theshubhagrwl/custom-user-model-in-django-3-3750fb5656c4?source=friends_link&amp;sk=003e40175d9f84f9eb6d5ba0c0c7e70d">Medium</a></p>
]]></content:encoded></item></channel></rss>