<?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: Shubh Agrawal</title>
    <description>The latest articles on DEV Community by Shubh Agrawal (@theshubhagrwl).</description>
    <link>https://dev.to/theshubhagrwl</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%2F447306%2F2c0bac31-7beb-487a-8f22-d714528f42a9.jpeg</url>
      <title>DEV Community: Shubh Agrawal</title>
      <link>https://dev.to/theshubhagrwl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/theshubhagrwl"/>
    <language>en</language>
    <item>
      <title>How I Read Less Than A Book A Month</title>
      <dc:creator>Shubh Agrawal</dc:creator>
      <pubDate>Thu, 10 Jun 2021 13:19:28 +0000</pubDate>
      <link>https://dev.to/theshubhagrwl/how-i-read-less-than-a-book-a-month-1ga6</link>
      <guid>https://dev.to/theshubhagrwl/how-i-read-less-than-a-book-a-month-1ga6</guid>
      <description>&lt;p&gt;The Internet is the place where all smart people spread their fame, but no one cares about setbacks.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;“How I read a book a week?”&lt;/em&gt; 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.&lt;/p&gt;

&lt;p&gt;But there is one thing made famous by the online &lt;em&gt;“influencers”&lt;/em&gt; 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.&lt;/p&gt;

&lt;p&gt;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 &lt;em&gt;“smart”&lt;/em&gt;. But learning is not a number game.&lt;/p&gt;

&lt;p&gt;I have two main concerns for reading a book a week:&lt;/p&gt;

&lt;h2&gt;
  
  
  1.Learning
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1385853971424813057-209" src="https://platform.twitter.com/embed/Tweet.html?id=1385853971424813057"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1385853971424813057-209');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1385853971424813057&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;This takes me to the next point,&lt;/p&gt;

&lt;h2&gt;
  
  
  2.Time
&lt;/h2&gt;

&lt;p&gt;Reading is time-consuming. Unless you are reading a short book like &lt;em&gt;“Who moved my cheese?”&lt;/em&gt; 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.&lt;/p&gt;

&lt;p&gt;I don’t think you are free enough to read the whole day.&lt;br&gt;
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?&lt;/p&gt;
&lt;h2&gt;
  
  
  3.Are you a Scanner?
&lt;/h2&gt;

&lt;p&gt;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 &lt;em&gt;“You have to buy that stupid car to understand it is stupid”.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;This may be applied to highly repetitive titles like &lt;em&gt;“The Power of Your Subconscious Mind”&lt;/em&gt;, but I don’t get what these smart folks can learn by scanning or skimming &lt;em&gt;“The Psychology of Money”.&lt;/em&gt; They’re probably smarter than the writer… I don’t know.&lt;/p&gt;
&lt;h2&gt;
  
  
  What's my way?
&lt;/h2&gt;

&lt;p&gt;I am sharing my way, but I strongly recommend finding your way rather than blindly following someone.&lt;br&gt;
While writing this article I was reading &lt;em&gt;“The Psychology of money”.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I sit, read the book without a highlighter or pencil and read for about 30mins. You can do it chapter-wise as well.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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&lt;/p&gt;

&lt;p&gt;After the initial phase, take a break of a day or two and after that,&lt;br&gt;
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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;




&lt;p&gt;Whenever you are learning something it is better to follow &lt;em&gt;“Spaced repetition”.&lt;/em&gt; 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.&lt;/p&gt;

&lt;p&gt;Playing the number game is not always a good idea and people on social media are obsessed with this game.&lt;br&gt;
Reading for fun and learning is what you should look for, not for Social Validation.&lt;/p&gt;

&lt;p&gt;A tweet about social validation I wrote after watching a video by Mark Mason.&lt;br&gt;
&lt;iframe class="tweet-embed" id="tweet-1395711772867272710-932" src="https://platform.twitter.com/embed/Tweet.html?id=1395711772867272710"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1395711772867272710-932');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1395711772867272710&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;Thanks for putting your valuable time on this article.&lt;br&gt;
If you enjoyed this article then consider supporting me. Thanks Again!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/theshubhagrwl"&gt;&lt;br&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GgPY6zXL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kp1y1mvlx9b6dd29rf41.png" alt="https://www.buymeacoffee.com/theshubhagrwl" width="170" height="37"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>books</category>
      <category>reading</category>
    </item>
    <item>
      <title>The World Of CSS. Should you write your own CSS or use any Library?</title>
      <dc:creator>Shubh Agrawal</dc:creator>
      <pubDate>Mon, 25 Jan 2021 03:14:37 +0000</pubDate>
      <link>https://dev.to/theshubhagrwl/the-world-of-css-should-you-write-your-own-css-or-use-any-library-4i57</link>
      <guid>https://dev.to/theshubhagrwl/the-world-of-css-should-you-write-your-own-css-or-use-any-library-4i57</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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 &lt;a href="https://github.com/i-voted-for-trump/is-even"&gt;Check here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;br&gt;
I have tried to keep it ASAP (As Short As Possible)&lt;/p&gt;

&lt;p&gt;Let's Discuss more.&lt;/p&gt;

&lt;h1&gt;
  
  
  Advantages of Libraries &amp;amp; Frameworks
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Pre Written Code → Lot less work to do&lt;/li&gt;
&lt;li&gt;Consistency → Styles look the same across the website&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The biggest and the most obvious advantage of the prewritten code is that it is &lt;strong&gt;"pre-written"&lt;/strong&gt; 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.&lt;/p&gt;

&lt;p&gt;Another awesome thing you can achieve is &lt;strong&gt;"consistency"&lt;/strong&gt;, i.e. your design looks the same on your whole website. This is because you are mostly referring to the same components.&lt;/p&gt;

&lt;h1&gt;
  
  
  Disadvantages of Libraries and Frameworks
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Pre-written Code → Can be hard to modify code&lt;/li&gt;
&lt;li&gt;Consistency → Code can be consistent across many &lt;em&gt;'other'&lt;/em&gt; websites&lt;/li&gt;
&lt;li&gt;External Libraries can sometimes be bulky&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is a fact that everything has advantages and disadvantages unless it's VSCode (No more bad jokes ahead!) so does this.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;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.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The first negative point according to me is the &lt;strong&gt;"pre-written"&lt;/strong&gt; 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.&lt;/p&gt;

&lt;p&gt;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 &lt;strong&gt;"Bootstrapped Sites"&lt;/strong&gt;. What I think is, this is true for a beginner but an experienced person can easily get around this. So again it depends.&lt;/p&gt;

&lt;p&gt;Another issue can be that the extra libraries can be &lt;strong&gt;"bulky"&lt;/strong&gt;, 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.&lt;/p&gt;

&lt;h1&gt;
  
  
  Addressing the Elephant in the Room
&lt;/h1&gt;

&lt;p&gt;Personally, I have used both ways to create websites.&lt;br&gt;
I one project I used MUI and tried to customize it a lot (&lt;a href="https://github.com/theshubhagrwl/MyMovieTime"&gt;https://github.com/theshubhagrwl/MyMovieTime&lt;/a&gt;) while in the other I used only Custom CSS (&lt;a href="https://theshubhagrwl.vercel.app/"&gt;https://theshubhagrwl.vercel.app/&lt;/a&gt;) and as a user, you won't be able to spot the difference but the main difference comes in the &lt;strong&gt;development time&lt;/strong&gt; and the &lt;strong&gt;knowledge of CSS you have&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;So I hope this post proved helpful for you. Give it a like if it helped you and share it with others.&lt;/p&gt;

&lt;p&gt;Connect with me on Twitter: &lt;a href="https://twitter.com/theshubhagrwl"&gt;https://twitter.com/theshubhagrwl&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see my work on my website: &lt;br&gt;
Shubh Agrawal (theshubhagrwl.vercel.app)&lt;/p&gt;

&lt;p&gt;Thanks for spending your valuable time on this post.🙏&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Deploying Django App to Heroku: Full Guide</title>
      <dc:creator>Shubh Agrawal</dc:creator>
      <pubDate>Sun, 20 Sep 2020 16:10:19 +0000</pubDate>
      <link>https://dev.to/theshubhagrwl/deploying-django-app-to-heroku-full-guide-4ce0</link>
      <guid>https://dev.to/theshubhagrwl/deploying-django-app-to-heroku-full-guide-4ce0</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;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. &lt;/p&gt;

&lt;p&gt;Okay, you did some research and selected Heroku. Great Choice!👍&lt;/p&gt;

&lt;p&gt;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. &lt;br&gt;
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.🤦‍♂️&lt;/p&gt;

&lt;p&gt;OK, Now let's solve your problems. This article covers almost everything that you will need.&lt;/p&gt;
&lt;h2&gt;
  
  
  Roadmap
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Install Required Tools&lt;/li&gt;
&lt;li&gt;Create Required Files&lt;/li&gt;
&lt;li&gt;Create a Heroku app&lt;/li&gt;
&lt;li&gt;Edit settings.py&lt;/li&gt;
&lt;li&gt;Make changes for static files&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  Install the required tools
&lt;/h1&gt;

&lt;p&gt;For deploying to Heroku you need to have Heroku CLI (Command Line Interface) installed. &lt;/p&gt;

&lt;p&gt;You can do this by going here: &lt;a href="https://devcenter.heroku.com/articles/heroku-cli" rel="noopener noreferrer"&gt;https://devcenter.heroku.com/articles/heroku-cli&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;CLI is required because it will enable us to use features like login, run migrations etc.&lt;/p&gt;
&lt;h1&gt;
  
  
  Create files required by Heroku
&lt;/h1&gt;

&lt;p&gt;After installing the CLI let's create all the files that Heroku needs.&lt;/p&gt;

&lt;p&gt;Files are : &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;requirements.txt&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Requirements.txt is the simplest to make. Just run the command&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip freeze &amp;gt; requirements.txt 
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;This command will make a .txt file which will contain all the packages that are required by your current Django Application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: If you add any package further then run this command again, this way the file will be updated with the new packages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What is the use of &lt;strong&gt;&lt;em&gt;requirements.txt&lt;/em&gt;&lt;/strong&gt;?&lt;br&gt;
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.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Procfile&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After this make a new file name Procfile and do not put any extension in it. It is a file required by Heroku&lt;/p&gt;

&lt;p&gt;According to Heroku :&lt;/p&gt;

&lt;p&gt;Heroku apps include a &lt;strong&gt;Procfile&lt;/strong&gt; that specifies the commands that are executed by the app on startup. You can use a Procfile to declare a variety of &lt;strong&gt;process types&lt;/strong&gt;, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your app’s web server&lt;/li&gt;
&lt;li&gt;Multiple types of worker processes&lt;/li&gt;
&lt;li&gt;A singleton process, such as a &lt;a href="https://devcenter.heroku.com/articles/scheduled-jobs-custom-clock-processes" rel="noopener noreferrer"&gt;clock&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Tasks to run &lt;a href="https://devcenter.heroku.com/articles/release-phase" rel="noopener noreferrer"&gt;before a new release is deployed&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For our app we can write the following command&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;web: gunicorn name_of_your_app.wsgi —log-file -
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;If you are confused about your app name, then just go to wsgi.py file in your project and you will find your app name there.&lt;/p&gt;

&lt;p&gt;For this, you should have gunicorn installed and added to you requirements.txt file&lt;/p&gt;

&lt;p&gt;Installing is super simple. You must have guessed it!&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install gunicorn
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;runtime.txt&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After this make a new text file called runtime.txt and inside it write the python version you are using in the following format&lt;/p&gt;

&lt;p&gt;&lt;code&gt;python-3.8.1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That's all the files we require. Now we have to start editing our settings.py file.&lt;/p&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;h1&gt;
  
  
  Create a Heroku app
&lt;/h1&gt;

&lt;p&gt;This is a simple step and can be done in 2 ways, either by command line or through the Heroku Website. &lt;/p&gt;

&lt;p&gt;Let's use the Heroku Website for now.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After making Heroku Account you will see an option to create a new app&lt;/li&gt;
&lt;li&gt;It will ask you for a name, the name should be unique. After hit and trials, you will be redirected to your app dashboard.&lt;/li&gt;
&lt;li&gt;There are many options to play with here but let's go to the settings tab and there click on Reveal Config Vars&lt;/li&gt;
&lt;li&gt;In the KEY write SECRET_KEY and in VALUE paste the secret key from the settings file and you can change it because only this key will be used.&lt;/li&gt;
&lt;li&gt;That's all for now.&lt;/li&gt;
&lt;li&gt;We will revisit it soon.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Edit settings.py
&lt;/h1&gt;

&lt;p&gt;There are quite a few changes that should be made in this file. &lt;/p&gt;

&lt;p&gt;Lets' start&lt;/p&gt;

&lt;p&gt;First change&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;DEBUG&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the allowed hosts enter the domain of your Heroku app&lt;/p&gt;

&lt;p&gt;eg.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;ALLOWED_HOSTS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;your_app_name.herokuapp.com&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;127.0.0.1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the SECRET_KEY variable with the following (assuming that you have setup the secret key in heroku from the previous step)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;SECRET_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;SECRET_KEY&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What this does is, it gets the SECRET_KEY from the environment. In our case, we can set the secret_key in Heroku and it will provide the key here through environment variables.&lt;/p&gt;

&lt;h1&gt;
  
  
  Setup static files
&lt;/h1&gt;

&lt;p&gt;In settings file, you will find&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;STATIC_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/static/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace this with the following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;STATIC_ROOT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BASE_DIR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;staticfiles&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;STATIC_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/static/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;

&lt;span class="n"&gt;STATICFILES_DIRS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BASE_DIR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;static&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Basically this will create a folder named static which will hold all the static files such as CSS files.&lt;/p&gt;

&lt;p&gt;If your App contains images that you have stored on it or the user has the ability to store then add the following lines&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;MEDIA_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/media/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;MEDIA_ROOT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BASE_DIR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;media&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is pretty much the same as the above&lt;/p&gt;

&lt;p&gt;There is one more thing you need to do. &lt;/p&gt;

&lt;p&gt;If you have media files then to allow Django to server them you have to add a line to your urls.py file of the project (top-level urls file)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.conf&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.conf.urls.static&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;static&lt;/span&gt;

&lt;span class="n"&gt;urlpatterns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="c1"&gt;# ... the rest of your URLconf goes here ...
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;static&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MEDIA_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;document_root&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MEDIA_ROOT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I highly recommend you have a look at this documentation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.djangoproject.com/en/3.1/howto/static-files/" rel="noopener noreferrer"&gt;https://docs.djangoproject.com/en/3.1/howto/static-files/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last thing you need to serve your static files in production is WhiteNoise&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;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.) -WhiteNoise Documentation&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Install white noise&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;whitenoise
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add it in MIDDLEWARE in settings.py file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;MIDDLEWARE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="c1"&gt;# 'django.middleware.security.SecurityMiddleware',
&lt;/span&gt;  &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;whitenoise.middleware.WhiteNoiseMiddleware&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;# ...
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this don't forget to run the command which creates the requirements.txt file. Remember?&lt;/p&gt;

&lt;p&gt;have a look at the documentation&lt;br&gt;
&lt;a href="http://whitenoise.evans.io/en/stable/" rel="noopener noreferrer"&gt;http://whitenoise.evans.io/en/stable/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So finally we have completed the 2 most important steps for deploying&lt;/p&gt;
&lt;h1&gt;
  
  
  Adding Code to Github
&lt;/h1&gt;

&lt;p&gt;Make a new Github Repo and add all of your code in it. &lt;br&gt;
&lt;a href="https://dev.to/ayomide_bajo/pushing-an-existing-repository-to-github-1f68"&gt;Use this post a reference&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After that go to Heroku and under the Deploy tab, you will see an option to connect Github. &lt;/p&gt;

&lt;p&gt;Connect your repo and you can hit the deploy button to deploy your app.&lt;/p&gt;
&lt;h1&gt;
  
  
  Using Heroku Postgres
&lt;/h1&gt;
&lt;h2&gt;
  
  
  What is the Need? I am using SQLite already!
&lt;/h2&gt;

&lt;p&gt;The problem is that &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;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.&lt;br&gt;
In addition, under normal operations, dynos will restart every day in a process known as "Cycling".&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://help.heroku.com/K1PPS2WM/why-are-my-file-uploads-missing-deleted" rel="noopener noreferrer"&gt;https://help.heroku.com/K1PPS2WM/why-are-my-file-uploads-missing-deleted&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basically all the data you will store will get delete every 24hrs.&lt;/p&gt;

&lt;p&gt;To solve Heroku suggest using either AWS or Postgres. Heroku has made it very simple to use Postgres. &lt;/p&gt;

&lt;p&gt;Let's do this&lt;/p&gt;

&lt;p&gt;Go to your app dashboard and in the Resources section search for Postgres. Select it and you will get something like this &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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxhg14xt58hctdiwg9gwb.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxhg14xt58hctdiwg9gwb.png" alt="Check this image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now go to the settings tab and reveal the config vars&lt;/p&gt;

&lt;p&gt;You will see a DATABASE_URL key there. It means that Heroku has added the database and now we have to tell our app to use this database. &lt;/p&gt;

&lt;p&gt;For this, we will be needing another package called dj_database_url. Install it through pip and import it at top of settings.py file &lt;/p&gt;

&lt;p&gt;Now paste the following code below DATABASES in settings file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;db_from_env&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dj_database_url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;conn_max_age&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;DATABASES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;default&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db_from_env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it now your database is setup&lt;/p&gt;

&lt;p&gt;Currently, your database is empty and you might want to fill it. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open terminal&lt;/li&gt;
&lt;li&gt;type → &lt;code&gt;heroku login&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;After the login run the following commands
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;heroku&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="n"&gt;manage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt; &lt;span class="n"&gt;makemigrations&lt;/span&gt;
&lt;span class="n"&gt;heroku&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="n"&gt;manage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt; &lt;span class="n"&gt;migrate&lt;/span&gt;
&lt;span class="n"&gt;heroku&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="n"&gt;manage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt; &lt;span class="n"&gt;createsuperuser&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your app is ready to be deployed &lt;/p&gt;

&lt;p&gt;either use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;git&lt;/span&gt; &lt;span class="n"&gt;push&lt;/span&gt; &lt;span class="n"&gt;heroku&lt;/span&gt; &lt;span class="n"&gt;master&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(after committing the changes) or push it through Github.&lt;/p&gt;




&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;If there is any kind of improvement then please tell me in the comments.&lt;/p&gt;




&lt;h2&gt;
  
  
  Check Out my other articles
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.to/theshubhagrwl/should-you-track-your-time-4d52"&gt;https://dev.to/theshubhagrwl/should-you-track-your-time-4d52&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Visit My Blog
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://theshubhagrwl.hashnode.dev/" rel="noopener noreferrer"&gt;https://theshubhagrwl.hashnode.dev/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Visit my website and follow me on Blogging and social platforms
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://theshubhagrwl.netlify.app/" rel="noopener noreferrer"&gt;http://theshubhagrwl.netlify.app/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>django</category>
      <category>python</category>
      <category>heroku</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Should you Track your Time?</title>
      <dc:creator>Shubh Agrawal</dc:creator>
      <pubDate>Sun, 06 Sep 2020 18:30:09 +0000</pubDate>
      <link>https://dev.to/theshubhagrwl/should-you-track-your-time-4d52</link>
      <guid>https://dev.to/theshubhagrwl/should-you-track-your-time-4d52</guid>
      <description>&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  The reason behind this post
&lt;/h1&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;I tracked my time for around 6 months. Daily. It was the most consistent thing that I did. LOL&lt;/p&gt;

&lt;h1&gt;
  
  
  Benefits
&lt;/h1&gt;

&lt;p&gt;Whenever you start a new thing you are generally more excited about it but slowly the fun goes away. This is a normal thing.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h1&gt;
  
  
  Problems you might face
&lt;/h1&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;If you are reading this then here I would like to tell you some problems that I faced.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;So I decided to give it a break.&lt;/p&gt;

&lt;h1&gt;
  
  
  So What Happened after that?
&lt;/h1&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h1&gt;
  
  
  TL;DR
&lt;/h1&gt;

&lt;p&gt;The best advice that I can give is Start Tracking your time. Do it till you don’t face the above-mentioned problems.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Thanks for giving your valuable time to this post!&lt;/p&gt;

&lt;p&gt;Give it a ❤ if you liked it.&lt;br&gt;
This article was originally posted on &lt;a href="https://medium.com/@theshubhagrwl/should-you-track-your-time-by-shubh-agrawal-968aecfcf97f"&gt;Medium&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A little about me
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;I am a Full Stack Developer and a Technology lover. Other than technology I love reading and gaming.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Checkout my portfolio:&lt;/em&gt; &lt;a href="https://theshubhagrwl.netlify.app/"&gt;&lt;em&gt;https://theshubhagrwl.netlify.app/&lt;/em&gt;&lt;/a&gt; &lt;em&gt;and let’s connect on social platforms.&lt;/em&gt;😉&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>management</category>
    </item>
    <item>
      <title>Custom User Model in Django 3</title>
      <dc:creator>Shubh Agrawal</dc:creator>
      <pubDate>Sun, 16 Aug 2020 06:01:06 +0000</pubDate>
      <link>https://dev.to/theshubhagrwl/custom-user-model-in-django-3-32k7</link>
      <guid>https://dev.to/theshubhagrwl/custom-user-model-in-django-3-32k7</guid>
      <description>&lt;h1&gt;
  
  
  Introduction 
&lt;/h1&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h1&gt;
  
  
  Motivation
&lt;/h1&gt;

&lt;p&gt;I had to make a Custom User for my app, I was able to make the model but the problem was createsuperuser 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. &lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9-wwsHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/theshubhagrwl"&gt;
        theshubhagrwl
      &lt;/a&gt; / &lt;a href="https://github.com/theshubhagrwl/django_custom_user_app"&gt;
        django_custom_user_app
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;I have made a &lt;a href="https://github.com/theshubhagrwl/django_custom_user_app"&gt;GitHub&lt;/a&gt; repo, so if you want you can directly use that (instructions are there)&lt;/p&gt;

&lt;h1&gt;
  
  
  Let's Get Started
&lt;/h1&gt;

&lt;p&gt;First of all, make a &lt;br&gt;Django Project and create an app called &lt;b&gt;users&lt;/b&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Now we can start editing the models.py file inside our users app
&lt;/h2&gt;

&lt;p&gt;Before editing let's do some theory. &lt;br&gt;&lt;br&gt;
What are &lt;strong&gt;managers&lt;/strong&gt; in Django?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;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&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;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 &lt;em&gt;createsuperuser&lt;/em&gt; can be edited.&lt;br&gt;
Now open up the &lt;strong&gt;models.py&lt;/strong&gt; and put the following code in it&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The most important thing to note here is the &lt;em&gt;is_staff&lt;/em&gt; and &lt;em&gt;is_superuser&lt;/em&gt; attributes. Making a typo in this can cause a hard time debugging. &lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What have we done here?
&lt;/h2&gt;

&lt;p&gt;We have made a &lt;strong&gt;manger&lt;/strong&gt; for our user model. &lt;br&gt;
Inside of this, we have made 2 functions called &lt;strong&gt;&lt;em&gt;create_user&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;create_superuser&lt;/em&gt;&lt;/strong&gt;. &lt;br&gt;
&lt;em&gt;create_user&lt;/em&gt;, as the name suggests, creates a new user, and &lt;em&gt;create_superuser&lt;/em&gt; is used to create a superuser by setting &lt;strong&gt;&lt;em&gt;is_staff&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;is_superuser&lt;/em&gt;&lt;/strong&gt; to true. &lt;br&gt;&lt;br&gt;
After the manager, we have our usual model.&lt;br&gt; &lt;br&gt;
We have set &lt;strong&gt;&lt;em&gt;username&lt;/em&gt;&lt;/strong&gt; to None because we do not want to include a username.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;USERNAME_FIELD&lt;/em&gt;&lt;/strong&gt; in it indicated which we declare 'email'. This should be unique.&lt;br&gt;&lt;br&gt;
&lt;em&gt;session_token&lt;/em&gt; is an optional field. I have it there because I was making my custom token. &lt;br&gt;&lt;br&gt;
The last line of the models.py indicates that the CustomUser is an object of UserManager.&lt;/p&gt;
&lt;h1&gt;
  
  
  Important Thing
&lt;/h1&gt;

&lt;p&gt;After you have made the model, Open settings.py file and add a line in it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;AUTH_USER_MODEL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;users.CustomUser&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;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&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Last Steps
&lt;/h1&gt;

&lt;p&gt;Now you can run the migrations commands and create superuser also.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;py manage.py makemigrations
py manage.py migrate
py manage.py createsuperuser
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will ask for your email and password. Give it the details.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't Forget to register the app in admin
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;site&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CustomUser&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can run the server and login with your email and password in the admin panel&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you have any suggestions then please let me know&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Check out my portfolio: &lt;a href="https://theshubhagrwl.netlify.app/"&gt;https://theshubhagrwl.netlify.app/&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Connect with me on Social Platforms:
&lt;/h4&gt;

&lt;p&gt;LinkedIn: &lt;a href="https://www.linkedin.com/in/theshubhagrwl/"&gt;https://www.linkedin.com/in/theshubhagrwl/&lt;/a&gt;&lt;br&gt;
Twitter: &lt;a href="https://twitter.com/theshubhagrwl/"&gt;https://twitter.com/theshubhagrwl/&lt;/a&gt;&lt;br&gt;
GitHub: &lt;a href="https://github.com/theshubhagrwl"&gt;https://github.com/theshubhagrwl&lt;/a&gt;&lt;br&gt;
Instagram: &lt;a href="https://www.instagram.com/theshubhagrwl/"&gt;https://www.instagram.com/theshubhagrwl/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This post was originally written on &lt;a href="https://medium.com/@theshubhagrwl/custom-user-model-in-django-3-3750fb5656c4?source=friends_link&amp;amp;sk=003e40175d9f84f9eb6d5ba0c0c7e70d"&gt;Medium&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>django</category>
      <category>webdev</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
