<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rohit Lakhotia</title>
    <description>The latest articles on DEV Community by Rohit Lakhotia (@rohitlakh).</description>
    <link>https://dev.to/rohitlakh</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%2F386610%2F4dce3f86-bc9b-45b0-9af7-d1cc5bf06a61.jpg</url>
      <title>DEV Community: Rohit Lakhotia</title>
      <link>https://dev.to/rohitlakh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rohitlakh"/>
    <language>en</language>
    <item>
      <title>EP 1: What is an API?</title>
      <dc:creator>Rohit Lakhotia</dc:creator>
      <pubDate>Sat, 02 Mar 2024 10:09:24 +0000</pubDate>
      <link>https://dev.to/rohitlakh/ep-1-what-is-an-api-20ea</link>
      <guid>https://dev.to/rohitlakh/ep-1-what-is-an-api-20ea</guid>
      <description>&lt;h2&gt;
  
  
  What’s an API?
&lt;/h2&gt;

&lt;p&gt;In simple terms, API is just an output to an input that you gave to someone. They’re like the ordering system for your software. You give them instructions (inputs), and they reliably provide you with what you asked for (predictable outputs).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0e6sqcuh4bd3jacbqjtj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0e6sqcuh4bd3jacbqjtj.png" alt="Request Response in API" width="800" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s consider the most widely used Google Maps, when we give the address as an input, it gives you back that address’s latitude/longitude coordinates as an output.&lt;/p&gt;

&lt;p&gt;Let’s understand APIs better with a real-life analogy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analogy: The Remote Control&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think of an API as a remote control for your home entertainment system. When you want to change the channel on your TV, increase the volume, or play a DVD, you don’t need to understand the complex electronics inside your devices. You simply press buttons on the remote control, and your commands are executed.&lt;/p&gt;

&lt;p&gt;In this analogy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The remote control serves as a client, providing a user-friendly interface.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The various entertainment devices (TV, sound system, DVD player), this is where the logic is i.e. server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your commands (changing channels, adjusting volume) represent API requests.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just as the remote control abstracts the technical complexities of your entertainment system, APIs abstract the inner workings of software systems, allowing them to communicate and perform tasks with ease.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Power of APIs
&lt;/h2&gt;

&lt;p&gt;APIs are the backbone of modern software development. They allow developers to leverage existing services and functionalities, saving time and resources. From the data you receive from a weather app to the seamless integration of social media platforms, APIs are everywhere to enhance our daily digital experiences.&lt;/p&gt;

&lt;p&gt;In brief:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;APIs make cross-platform development a breeze.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;APIs are like standardized contracts for communication.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;APIs facilitate communication between services.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;APIs also play a crucial role in security.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Payment Gateway APIs:&lt;/strong&gt; When you make an online purchase, the payment process is often facilitated by payment gateway APIs like PayPal, Stripe, or Square. They handle secure transactions, sparing developers from implementing complex payment systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Social Media Sharing APIs:&lt;/strong&gt; Social media platforms offer APIs that allow users to share content from other apps directly to their social feeds. For instance, the “Share on Facebook” option in various apps is made possible through Facebook’s API.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does an API Work?
&lt;/h2&gt;

&lt;p&gt;APIs function through a request and response process, sharing data among applications, systems, and devices. When a user interacts with an application, they initiate a request for data, which is sent to the API. The API retrieves the data and returns it to the user, completing the cycle.&lt;/p&gt;

&lt;p&gt;To illustrate this process, let’s liken APIs to the workings of a restaurant. In this analogy, the user plays the role of a customer placing an order. The API functions as the restaurant’s order-taking service, receiving the order details, specifying the desired items, and arranging the preparation process. The kitchen staff, akin to an API server, ensures that the order is accurately prepared and ready for delivery. Any additional requests, such as specifying cooking preferences or adding extra toppings, are handled seamlessly. This comparison serves to simplify the concept of APIs by drawing parallels with a familiar scenario — the ordering process in a restaurant.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc3va1nipk57vkrjrhhwn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc3va1nipk57vkrjrhhwn.png" alt="Customer Waiter API example" width="800" height="257"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example, imagine a user interacting with a restaurant API to place an order for a pizza. The user specifies the type of pizza, size, toppings, and any special instructions through the API (&lt;strong&gt;Input&lt;/strong&gt;). The API, acting as the order handler, communicates this information to the restaurant’s system (&lt;strong&gt;Server&lt;/strong&gt;). The Chef then prepares the pizza according to the specifications. Once ready, the pizza is delivered to the user’s location (&lt;strong&gt;Response&lt;/strong&gt;), ensuring a smooth and efficient process facilitated by the restaurant API.&lt;/p&gt;

&lt;p&gt;Take a closer look, the API client assembles requests based on user actions and sends them to the relevant API endpoint. These endpoints are like URLs, providing access to specific resources in a database.&lt;/p&gt;

&lt;p&gt;For instance, if a user wants to view products in an e-commerce store, the API client sends a GET request to the /products endpoint. This way, APIs enable efficient data exchange in the digital world.&lt;/p&gt;

&lt;h2&gt;
  
  
  How API works between client and server
&lt;/h2&gt;

&lt;p&gt;Imagine a client-server architecture where the client, representing the user, makes requests through a middleman — the API — and receives responses from the server in the backend. Here’s how it works:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxp0vtq3dzv778p33shbi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxp0vtq3dzv778p33shbi.png" alt="Client Server API Interaction" width="800" height="199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Your client kicks things off by initiating the API requests via the URI (&lt;a href="https://flight.beehiiv.net/v2/clicks/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1cmwiOiJodHRwczovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9Vbmlmb3JtX1Jlc291cmNlX0lkZW50aWZpZXI_dXRtX3NvdXJjZT1ody5nbGljaC5jbyZ1dG1fbWVkaXVtPXJlZmVycmFsJnV0bV9jYW1wYWlnbj1lcC0xLXdoYXQtaXMtYW4tYXBpIiwicG9zdF9pZCI6ImYyODgzZDU3LTNmNTgtNGQwNS04ZjBmLWUxZGIwN2IxNjEyNCIsInB1YmxpY2F0aW9uX2lkIjoiODcxNTU2OGEtYWY2OC00NzE4LWFkZmMtMDE2ZGJmZmQyYjA5IiwidmlzaXRfdG9rZW4iOiIyYzI3ZTIxNi02ZmI0LTRmZWYtOGFmYy01ZjJmNzIwMzc1ODAiLCJpYXQiOjE3MDkyODE5MDYsImlzcyI6Im9yY2hpZCJ9.b6LB6ERswWLp66lEbHxk0JbZhYAc9l9jd6f6WcZMiss"&gt;**Uniform Resource Identifier&lt;/a&gt;**)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The API request is sent to the server, relaying your intentions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The server processes your request, gathers the necessary information, and sends back a response.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The API, acting as the go-between or the communication channel, hands you the response containing the data you need.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;APIs are designed to be secure, using authorization credentials and an API gateway to control access and keep things safe. For extra layers of security, various techniques like HTTP headers, query string parameters, and cookies are employed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of APIs
&lt;/h2&gt;

&lt;p&gt;APIs are categorized into many different types based on the use case. In practical experience, I’ve come across people using the term “API” in three different contexts. These are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Based on Accessibility:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff0d9ljqtlkvj6rtbluyu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff0d9ljqtlkvj6rtbluyu.png" alt="Types of API" width="712" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Private APIs:&lt;/strong&gt; These are also known as internal APIs. When companies create their applications, they build them using a set of interacting APIs. They’re used within an organization to connect various software components. Private APIs are not available for third-party use.&lt;/p&gt;

&lt;p&gt;For example, an e-commerce platform might have numerous private APIs for order processing, product catalog, recommendation, payment processing, etc. working altogether coordinating with each other.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💭 &lt;strong&gt;Even database calls are API calls under the hood.&lt;/strong&gt; The queries that we do are sent to the database through an API call. The database then proceeds to run that query and return the data as a response.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Public APIs:&lt;/strong&gt; Public APIs provide access to an organization’s data or services for third-party developers. These APIs can be freely available or offered as paid products. Sometimes, companies make some of their APIs available to the public and provide instructions on how to use them.&lt;/p&gt;

&lt;p&gt;A good example is the YouTube Data API, YouTube provides a public API that allows developers to access and interact with YouTube’s vast video content, including searching for videos, retrieving video details, uploading videos, and managing user playlists.&lt;/p&gt;

&lt;p&gt;Developers can use this API to create applications that integrate YouTube video features, such as video search, recommendations, and video uploading, into their own platforms. This public API has enabled the development of various third-party YouTube applications and services.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Interfaces:&lt;/strong&gt; Now, the first two types of APIs are quite practical, but developers also use the term “API” for lower-level stuff in code, like functions.&lt;/p&gt;

&lt;p&gt;A code interface API, or simply a code API, refers to a set of functions, methods, or procedures that a programming language or library provides for developers to interact with and use in their code.&lt;/p&gt;

&lt;p&gt;A classic example is the Math.random() function in JavaScript. It's an API that generates random numbers. There are other mathematical operations like Math.power() (power), Math.round() (round), and Math.sqrt() (Square root).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 There might be different types of API, but one thing is in common, they give an output based on an input. They might be named Public, Private, or Code Interfaces but still use API as a single term to describe them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foru0xnn0sdgr7i99bf59.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foru0xnn0sdgr7i99bf59.png" alt="Internal, Public and code interfaces API" width="713" height="257"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Based on Architectural Style:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some of the most used types of APIs are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;REST:&lt;/strong&gt; Representational State Transfer (REST) is the most common architectural style for Internet data transfer. It uses standard HTTP methods like GET, POST, PUT, and DELETE to interact with resources through endpoints.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SOAP:&lt;/strong&gt; Simple Object Access Protocol (SOAP) uses XML to exchange structured messages between a client and server. It’s often used in enterprise environments and offers advanced security features but can be slower than other architectures.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How developer talks about APIs
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“I’ve developed an API that allows you to discover the top 10 trending videos on YouTube tailored to your preferences, delivering personalized content effortlessly.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Less manual work and faster access to the desired search result.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“I keep encountering this authentication issue with the API; it’s like trying to enter a password that I can’t quite get right.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The API is throwing this puzzling auth error at me, like a locked door that requires the right key. I’m struggling to get through with the correct credentials.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“You can use the Facebook API to get that data into your app”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Connect your app with the Facebook API, and you can pull in data seamlessly. It’s like having a magic portal to grab the information you need for your application.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“I crafted an API that acts like a personal shopper, finding you the best book recommendations based on your preferences. It’s your literary guide in the vast bookstore of information.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The future is here! Getting things done within moments in a few touches.&lt;/p&gt;

&lt;p&gt;By now, you must have had a clear idea of &lt;strong&gt;APIs,&lt;/strong&gt; from its working to testing you know all of it now. However, understanding APIs on a theoretical level is just the first step. To know the practical aspects of working with APIs, you can try working on them by implementing some of the concepts in projects.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The post was originally published at &lt;a href="https://hw.glich.co/p/what-is-an-api"&gt;What is an API?&lt;/a&gt; which is a part of my newsletter called &lt;a href="https://hw.glich.co/subscribe?utm_source=medium&amp;amp;utm_medium=bottom&amp;amp;utm_campaign=what-is-an-api"&gt;Hello, World!&lt;/a&gt; where we help developers learn a new software engineering concept every Monday. Read what engineers from Google, Microsoft, and Amazon are reading for free.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webdev</category>
      <category>api</category>
      <category>http</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Configuring Ghost SSL with multiple domains</title>
      <dc:creator>Rohit Lakhotia</dc:creator>
      <pubDate>Sat, 17 Jul 2021 14:12:26 +0000</pubDate>
      <link>https://dev.to/rohitlakh/configuring-ghost-ssl-with-multiple-domains-5cjc</link>
      <guid>https://dev.to/rohitlakh/configuring-ghost-ssl-with-multiple-domains-5cjc</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was originally published at &lt;a href="https://rohitlakhotia.com"&gt;rohitlakhotia.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This tutorial assumes that you have a self-hosted ghost installation up and running.&lt;/p&gt;

&lt;p&gt;Ghost only server content on one domain at a time, so in order to serve content from other domains you need to redirect (&lt;a href="https://www.seoclarity.net/resources/knowledgebase/use-301-redirect-vs-302-redirect-15683/"&gt;301 vs 302&lt;/a&gt;) that domain to the domain where the ghost CMS is hosted on.&lt;/p&gt;

&lt;p&gt;You may wish to have multiple domains that redirect to your site, e.g. to have an extra TLD or to support www domains.  This is intentional for SEO purposes, however, you can always redirect extra domains to your Ghost install using Nginx.&lt;/p&gt;

&lt;p&gt;If you want to redirect an HTTPS domain, you must have a certificate for it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Setup
&lt;/h2&gt;

&lt;p&gt;What we will try to achieve here is to have &lt;code&gt;www.rohitlakhotia.com&lt;/code&gt; point to the root domain &lt;code&gt;rohitlakhotia.com&lt;/code&gt; with an SSL certificate so the browser doesn't show warnings while visiting any of the above.&lt;/p&gt;

&lt;p&gt;This would also include the HTTP version to redirect to the HTTPS version so the search engine doesn't consider them duplicate pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure your secondary domain
&lt;/h2&gt;

&lt;p&gt;We would need to configure the domain DNS records in order to let the browser know where to go while requests are being made.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure your domains with proper records
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aaOGEKzl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://rohitlakhotia.com/content/images/size/w1000/2021/07/domain_A_records-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aaOGEKzl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://rohitlakhotia.com/content/images/size/w1000/2021/07/domain_A_records-1.png" alt="domain_A_records" width="800" height="146"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you look closely the &lt;code&gt;www&lt;/code&gt; version and the &lt;code&gt;@&lt;/code&gt; (root) version both point to the same IP (server).&lt;/p&gt;

&lt;p&gt;Basically, every request that points to those two versions would be handled by the server at that IP address. Which is exactly what we want. So we can handle them appropriately.&lt;/p&gt;

&lt;p&gt;Now we would need to SSH into the server to install the certificate and properly redirect the domain.&lt;/p&gt;

&lt;p&gt;After you have access to the server, go to the directory where you have installed ghost. Mostly it would be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/var/www/&amp;lt;your ghost installation&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So cd into the directory and then&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; ghost config url https://www.rohitlakhotia.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In place of &lt;code&gt;www.rohitlakhotia.com&lt;/code&gt;, add your domain (secondary domain) that you want to redirect to the root domain.&lt;/p&gt;

&lt;p&gt;Before proceeding with the next command just make sure that the A records are successfully updated, else the SSL certificate won't be installed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ghost setup nginx ssl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will generate SSL certificates for your domain (which for me is &lt;code&gt;www.rohitlakhotia.com&lt;/code&gt;) that you just added and also the Nginx configuration file for the HTTP and HTTPS version. (Easy!)&lt;/p&gt;

&lt;p&gt;Now we will again change the ghost installation URL back to the old one which for me is &lt;code&gt;https://rohitlakhotia.com&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ghost config url https://rohitlakhotia.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we would need to update the newly created Nginx configuration file so that we can redirect the user to the root domain.&lt;/p&gt;

&lt;p&gt;The Nginx configuration files are mostly located at &lt;code&gt;/etc/nginx/sites-available&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /etc/nginx/sites-available
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you will find all the Nginx configuration files. There should be a minimum of 4 files. Every domain has files with -ssl.conf (For HTTPS) and .conf (For HTTP).&lt;/p&gt;

&lt;p&gt;So we would have 4 files:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;rohitlakhotia.com-ssl.conf&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;rohitlakhotia.com.conf&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;www.rohitlakhotia.com-ssl.conf&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;www.rohitlakhotia.com.conf&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now we need to edit the files for the secondary domain.&lt;/p&gt;

&lt;p&gt;So the files that I need to edit would be &lt;code&gt;www.rohitlakhotia.com-ssl.conf&lt;/code&gt; and &lt;code&gt;www.rohitlakhotia.com.conf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We need to add this line of code inside the location block but at the end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return 301 https://rohitlakhotia.com$request_uri;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can change the 301 to 302 depending on your use case (&lt;a href="https://www.seoclarity.net/resources/knowledgebase/use-301-redirect-vs-302-redirect-15683/"&gt;301 vs 302&lt;/a&gt;). You will replace &lt;code&gt;rohitlakhotia.com&lt;/code&gt; with your primary domain.&lt;/p&gt;

&lt;p&gt;What this line would do is whenever a request is made to the secondary domain then it would redirect (301/302) it to the specific URL.&lt;/p&gt;

&lt;p&gt;So both the files should look like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ccWNZNcp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://rohitlakhotia.com/content/images/size/w1000/2021/07/www.rohitlakhotia.com.conf-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ccWNZNcp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://rohitlakhotia.com/content/images/size/w1000/2021/07/www.rohitlakhotia.com.conf-1.png" alt="www.rohitlakhotia.com.conf" width="800" height="590"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C8GZSDM5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://rohitlakhotia.com/content/images/size/w1000/2021/07/www.rohitlakhotia.com-ssl.conf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C8GZSDM5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://rohitlakhotia.com/content/images/size/w1000/2021/07/www.rohitlakhotia.com-ssl.conf.png" alt="www.rohitlakhotia.com-ssl.conf" width="800" height="694"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now check if the configuration files are valid by&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nginx -t
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it's successful then reload the Nginx server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nginx -s reload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it.&lt;/p&gt;

&lt;p&gt;You just pointed your secondary domain to your primary domain in ghost.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For more content you can checkout my &lt;a href="https://rohitlakhotia.com/blog"&gt;blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>node</category>
    </item>
    <item>
      <title>How to Create/Extend Django Custom User Model</title>
      <dc:creator>Rohit Lakhotia</dc:creator>
      <pubDate>Sun, 31 May 2020 10:03:37 +0000</pubDate>
      <link>https://dev.to/rohitlakh/how-to-create-extend-django-custom-user-model-32fe</link>
      <guid>https://dev.to/rohitlakh/how-to-create-extend-django-custom-user-model-32fe</guid>
      <description>&lt;p&gt;Originally Published at &lt;a href="https://rohitlakhotia.com/" rel="noopener noreferrer"&gt;My personal website&lt;/a&gt; as a blog post &lt;a href="https://rohitlakhotia.com/blog/django-custom-user-model/" rel="noopener noreferrer"&gt;Django Custom User Model&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvgr5m4cgjbxjnjwawq3c.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvgr5m4cgjbxjnjwawq3c.jpg" alt="Django Custom User Model" width="1" height="1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are looking to find CMS, I have &lt;a href="https://www.contenttoolkit.co/" rel="noopener noreferrer"&gt;made a curated list of CMS tools&lt;/a&gt; that you can filter and find the one that you are looking for. Do check it out: &lt;a href="https://www.contenttoolkit.co/" rel="noopener noreferrer"&gt;Content Toolkit&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Django build-in &lt;code&gt;User&lt;/code&gt; model out of the box is solid. But it sometimes might not suit your need since it has some predefined field and you might want to add some more field to it like Date of Birth or maybe making email-only authentication since Django has username-password authentication out of the box. That’s when Django’s custom user model comes handy.&lt;/p&gt;

&lt;p&gt;Django uses Python language. If you want to learn Python go to Learn Python from the &lt;a href="https://learnitfree.org/subject/learn-python/" rel="noopener noreferrer"&gt;Best Free Python Courses and Tutorials&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Do I need a Custom User Model?
&lt;/h2&gt;

&lt;p&gt;Most of the time you don’t. Django’s built-in &lt;code&gt;User&lt;/code&gt; models provide more than enough features to serve you out of the box. But if you want the user to authenticate with an email address instead of username then the custom model could be the right choice.&lt;/p&gt;

&lt;p&gt;But that being said &lt;a href="https://docs.djangoproject.com/en/3.0/topics/auth/customizing/#using-a-custom-user-model-when-starting-a-project" rel="noopener noreferrer"&gt;Django Official documentation&lt;/a&gt; suggests you have a custom model even if you don’t want too so in future if you want to add more information about the user you can do so which is more likely if your app grows.&lt;/p&gt;

&lt;h3&gt;
  
  
  Application-specific data
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;User&lt;/code&gt; model is meant to show information related to your user’s authentication or authentication point of view. You might even be tempted to store other application-specific information related to the user.&lt;/p&gt;

&lt;p&gt;Since most users will have a profile picture, bio. Data like this could be stored in another model which is referenced with an &lt;code&gt;OneToOneField&lt;/code&gt; with the &lt;code&gt;User&lt;/code&gt; Model.&lt;/p&gt;

&lt;h3&gt;
  
  
  Storing application data on the User model
&lt;/h3&gt;

&lt;p&gt;There are some advantages and disadvantages to storing application data in the user model.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  For smaller applications, it will be simpler. There won’t be many things to look for. Everything in one place. But if the application grows the same model can become clutter in no time.&lt;/li&gt;
&lt;li&gt;  Since everything will be in one place there won’t be a need for advanced database queries. But that would also make your table in the database bloated.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Storing application data in a profile model
&lt;/h3&gt;

&lt;p&gt;The alternative way to store your user application data is to have another model &lt;code&gt;Profile&lt;/code&gt; which is referenced with &lt;code&gt;OneToOneField&lt;/code&gt; to the &lt;code&gt;User&lt;/code&gt; Model.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Since the application data is kept on another model the &lt;code&gt;User&lt;/code&gt; model is only used for authentication purposes and the &lt;code&gt;Profile&lt;/code&gt; model is used for user’s application data. Keeping it clutter-free.&lt;/li&gt;
&lt;li&gt;  But since the application data is different from authentication data than to get the user application data we need to load another object from the database in order to retrieve the data. Depending on your application it could be worth the effort.&lt;/li&gt;
&lt;li&gt;  The decoupling of application data with authentication data makes it easier to make changes in the future.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Default Fields of User Model
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;User&lt;/code&gt; Model Django provides out of the box has some fields in general:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;code&gt;username&lt;/code&gt;: The username that the user will use to authenticate. This will be unique in the table.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;email&lt;/code&gt;: The email that the user can choose to share. But out-of-the-box it is not unique.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;password1&lt;/code&gt;: The password user chooses to authenticate. It is not a plain password. It will be hashed for security reasons.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;password2&lt;/code&gt;: This is used for confirm password. At the Admin side, only one field named password is seen.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;first_name&lt;/code&gt;: First name of the person.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;last_name&lt;/code&gt;: Last name of the person.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;last_login&lt;/code&gt;: The last Date and Time the user logged in.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;date_joined&lt;/code&gt;: The Date and Time the user joined/authenticated with your website.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;groups&lt;/code&gt;: The groups the user is in.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;user_permissions&lt;/code&gt;: Admin permissions if any.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;is_staff&lt;/code&gt;: Designates whether the user can log into the admin site.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;is_active&lt;/code&gt;: Designates whether this user should be treated as active. Unselect this instead of deleting accounts.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;is_superuser&lt;/code&gt;: Designates that this user has all permissions without explicitly assigning them.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Ways to Extend the &lt;code&gt;User&lt;/code&gt; model
&lt;/h2&gt;

&lt;p&gt;There are 4 ways to extend an existing &lt;code&gt;User&lt;/code&gt; model in Django. Check them below and choose the one that fits your needs.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Proxy Model&lt;/li&gt;
&lt;li&gt; &lt;code&gt;Profile&lt;/code&gt; Model with &lt;code&gt;OneToOneField&lt;/code&gt; with &lt;code&gt;User&lt;/code&gt; Model&lt;/li&gt;
&lt;li&gt; &lt;code&gt;AbstractBaseUser&lt;/code&gt; to Create a Custom &lt;code&gt;User&lt;/code&gt; Model&lt;/li&gt;
&lt;li&gt; &lt;code&gt;AbstractUser&lt;/code&gt; to Create a Custom &lt;code&gt;User&lt;/code&gt; Model&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. Proxy Model
&lt;/h3&gt;

&lt;p&gt;Proxy models are a feature that developers might come across and move along without giving much importance. They can come in handy in many situations.&lt;/p&gt;

&lt;p&gt;A proxy model is just another class that provides a different interface for the same underlying database model.&lt;/p&gt;

&lt;p&gt;A proxy model is actually a subclass of a database-table defining model. Typically creating a subclass of a model results in a new database table with a reference back to the original model’s table ie. multi-table inheritance.&lt;/p&gt;

&lt;p&gt;A proxy model doesn’t get its own database table. Instead, it operates on the original table.&lt;/p&gt;

&lt;p&gt;It is used to change the behavior of an existing model (e.g. order, new methods, etc.) without changing the existing database schema.&lt;/p&gt;

&lt;p&gt;When to use Proxy Model?&lt;/p&gt;

&lt;p&gt;When you don’t need to add extra data about but just want extra methods or change the model’s query Manager.&lt;/p&gt;

&lt;p&gt;It is a less intuitive way to extend the existing User model and is limited in many ways. You won’t have any drawbacks with this strategy.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;models.py&lt;/code&gt;&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.contrib.auth.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;.managers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;PersonManager&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;objects&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PersonManager&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;proxy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
        &lt;span class="n"&gt;ordering&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;email&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;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;do_something&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let see what we did here.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  First, we defined a Proxy Model named Person. To tell Django that it is a proxy model we make &lt;code&gt;proxy = True&lt;/code&gt; in &lt;code&gt;class Meta&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  We assign a custom Manager named &lt;code&gt;PersonManager&lt;/code&gt; to the Proxy model by &lt;code&gt;objects = PersonManager( )&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  Change the default ordering to &lt;code&gt;email&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  Defined a function &lt;code&gt;do_something&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also now &lt;code&gt;User.objects.all( )&lt;/code&gt; and &lt;code&gt;Person.objects.all( )&lt;/code&gt; will be using the same database table to query. The only difference has been the behavior of the Proxy Model.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Profile Model with OneToOne link with User Model
&lt;/h3&gt;

&lt;p&gt;The idea behind this is to create another table in the database and point the &lt;code&gt;User&lt;/code&gt; model to that table in the database with &lt;code&gt;OneToOneField&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What is OneToOne Link?&lt;/p&gt;

&lt;p&gt;It’s the Foreign Key relation but with &lt;code&gt;unique=True&lt;/code&gt;. So every row in a table would have only one relating row in another table and vice versa.&lt;/p&gt;

&lt;p&gt;But, when should I use this?&lt;/p&gt;

&lt;p&gt;You should do this when you want to store profile related information like a profile picture, bio, etc. Basically everything related to the user that is not authentication specific.&lt;/p&gt;

&lt;p&gt;Most of the time this is what you want.&lt;/p&gt;

&lt;p&gt;Since we will be creating another model that stores user’s profile data that will be related to the &lt;code&gt;User&lt;/code&gt; model. This will need an additional query or join to access the related data. To access the related data Django needs to fire additional queries.&lt;/p&gt;

&lt;p&gt;So let’s see what to do here,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;models.py&lt;/code&gt;&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.db&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.contrib.auth.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Profile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OneToOneField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;on_delete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CASCADE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;bio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CharField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;null&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;birth_date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;null&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;blank&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    
        &lt;span class="n"&gt;profile_pic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ImageField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;default.jpg&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;upload_to&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;profiles_pics&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;hobby&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CharField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;null&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now since the models are created, but they need to be created whenever a user is created. We need to use signals to do the same.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;models.py&lt;/code&gt;&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.db&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.contrib.auth.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.db.models.signals&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;post_save&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.dispatch&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;receiver&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Profile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OneToOneField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;on_delete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CASCADE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;bio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CharField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;null&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;birth_date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;null&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;blank&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    
        &lt;span class="n"&gt;profile_pic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ImageField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;default.jpg&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;upload_to&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;profiles_pics&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;hobby&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CharField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;null&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@receiver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;post_save&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_profile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;created&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;created&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;Profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@receiver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;post_save&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;save_profile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we are telling Django that whenever a save event occurs (signal called &lt;code&gt;post_save&lt;/code&gt;) create or save the profile depending on the situation.&lt;/p&gt;

&lt;p&gt;So, here whenever an entry/row of a user is created in the table, a new entry/row is also created in the profile table in the database.&lt;/p&gt;

&lt;p&gt;But that’s all fine, how do I access this profile data?&lt;/p&gt;

&lt;p&gt;You can access this data in Django Templates like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;template.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;{{ user.username }}&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;{{ user.email }}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;{{ user.profile.bio }}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;{{ user.profile.birth_date }}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For using it in views:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;views.py&lt;/code&gt;&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;update_profile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;objects&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="n"&gt;pk&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hobby&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Coding, Chess, Guitar&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we have signals setup we don’t have to save the &lt;code&gt;Profile&lt;/code&gt; models. If we save the &lt;code&gt;User&lt;/code&gt; model the &lt;code&gt;Profile&lt;/code&gt; models will also be saved.&lt;/p&gt;

&lt;p&gt;In Django, we can have multiple forms in the same templates at once. So, if we want to have a profile page where users email, username and other profile data like bio, etc is shown and can be updated by the user.&lt;/p&gt;

&lt;p&gt;First, we will create the forms: &lt;code&gt;form.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;forms.py&lt;/code&gt;&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&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;forms&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.contrib.auth.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Profile&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserUpdateForm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;forms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ModelForm&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;forms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;EmailField&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;
        &lt;span class="n"&gt;fields&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;username&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;email&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProfileUpdateForm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;forms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ModelForm&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Profile&lt;/span&gt;
        &lt;span class="n"&gt;fields&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;profile_pic&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;bio&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;To access the forms in &lt;code&gt;views.py&lt;/code&gt;&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="nd"&gt;@login_required&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;POST&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;u_form&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;UserUpdateForm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;POST&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;p_form&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ProfileUpdateForm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;POST&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FILES&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;u_form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is_valid&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;p_form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is_valid&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
            &lt;span class="n"&gt;u_form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="n"&gt;p_form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;success&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Your Profile has been Updated Successfully&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;redirect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;profile&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;   
        &lt;span class="n"&gt;u_form&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;UserUpdateForm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;p_form&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ProfileUpdateForm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;context&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;u_form&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;u_form&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;p_form&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;p_form&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;users/profile.html&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The template: &lt;code&gt;profile.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"POST"&lt;/span&gt; &lt;span class="na"&gt;enctype=&lt;/span&gt;&lt;span class="s"&gt;"multipart/form-data"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    {% csrf_token %}
    &lt;span class="nt"&gt;&amp;lt;fieldset&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-group"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;legend&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"border-bottom mb-4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Profile Info&lt;span class="nt"&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;
        {{ u_form.as_p }}
        {{ p_form.as_p }}
    &lt;span class="nt"&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Update&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. &lt;code&gt;AbstractBaseUser&lt;/code&gt; to Create a Custom User Model
&lt;/h3&gt;

&lt;p&gt;This method is like starting from a clean slate. Use this method if you want to start from scratch.&lt;/p&gt;

&lt;p&gt;This method will have no predefined field, it only contains the authentication functionality, but no actual fields. You have to supply them when you subclass.&lt;/p&gt;

&lt;p&gt;It can be helpful in many cases like when you want to use email for authentication instead of username. But there are better ways to do the same by using &lt;code&gt;AbstractUser&lt;/code&gt; instead of &lt;code&gt;AbstractBaseUser&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;You this at your own will. JK. You will be fine.&lt;/p&gt;

&lt;p&gt;To demonstrate this we will be using the same example as in the documentation.&lt;/p&gt;

&lt;p&gt;Here is an example of an admin-compliant custom user app. This user model uses an email address as the username, and has a required date of birth; it provides no permission checking beyond an admin flag on the user account.&lt;/p&gt;

&lt;p&gt;This model would be compatible with all the built-in auth forms and views, except for the user creation forms. This example illustrates how most of the components work together, but is not intended to be copied directly into projects for production use.&lt;/p&gt;

&lt;p&gt;This code would all live in a &lt;code&gt;models.py&lt;/code&gt; file for a custom authentication app:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;models.py&lt;/code&gt;&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.db&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.contrib.auth.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;BaseUserManager&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;AbstractBaseUser&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyUserManager&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BaseUserManager&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;date_of_birth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
        Creates and saves a User with the given email, date of
        birth and password.
        &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Users must have an email address&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;normalize_email&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="n"&gt;date_of_birth&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;date_of_birth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;using&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_db&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_superuser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;date_of_birth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
        Creates and saves a superuser with the given email, date of
        birth and password.
        &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
        &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;date_of_birth&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;date_of_birth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_admin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
        &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;using&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_db&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;AbstractBaseUser&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;EmailField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;verbose_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;email address&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;unique&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;date_of_birth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateField&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;is_active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BooleanField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;is_admin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BooleanField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;objects&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MyUserManager&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="n"&gt;USERNAME_FIELD&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;email&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
    &lt;span class="n"&gt;REQUIRED_FIELDS&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;date_of_birth&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__str__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;has_perm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;perm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Does the user have a specific permission?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="c1"&gt;# Simplest possible answer: Yes, always
&lt;/span&gt;        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;has_module_perms&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;app_label&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Does the user have permissions to view the app `app_label`?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="c1"&gt;# Simplest possible answer: Yes, always
&lt;/span&gt;        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;

    &lt;span class="nd"&gt;@property&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;is_staff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Is the user a member of staff?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="c1"&gt;# Simplest possible answer: All admins are staff
&lt;/span&gt;        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_admin&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, to register this custom user model with Django’s admin, the following code would be required in the app’s &lt;code&gt;admin.py&lt;/code&gt; file:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;admin.py&lt;/code&gt;&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&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;forms&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.contrib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;admin&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.contrib.auth.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Group&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.contrib.auth.admin&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;UserAdmin&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;BaseUserAdmin&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.contrib.auth.forms&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ReadOnlyPasswordHashField&lt;/span&gt;

&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;users.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;MyUser&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserCreationForm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;forms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ModelForm&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;A form for creating new users. Includes all the required
    fields, plus a repeated password.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;password1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;forms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CharField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Password&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;widget&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;forms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PasswordInput&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;password2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;forms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CharField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Password confirmation&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;widget&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;forms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PasswordInput&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;MyUser&lt;/span&gt;
        &lt;span class="n"&gt;fields&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;email&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;date_of_birth&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;clean_password2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="c1"&gt;# Check that the two password entries match
&lt;/span&gt;        &lt;span class="n"&gt;password1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cleaned_data&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;password1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;password2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cleaned_data&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;password2&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;password1&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;password2&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;password1&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;password2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="n"&gt;forms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ValidationError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Passwords don&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;t match&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;password2&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;commit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="c1"&gt;# Save the provided password in hashed format
&lt;/span&gt;        &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;super&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;commit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cleaned_data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;password1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserChangeForm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;forms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ModelForm&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;A form for updating users. Includes all the fields on
    the user, but replaces the password field with admin&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s
    password hash display field.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ReadOnlyPasswordHashField&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;MyUser&lt;/span&gt;
        &lt;span class="n"&gt;fields&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;email&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;password&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;date_of_birth&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;is_active&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;is_admin&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;clean_password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="c1"&gt;# Regardless of what the user provides, return the initial value.
&lt;/span&gt;        &lt;span class="c1"&gt;# This is done here, rather than on the field, because the
&lt;/span&gt;        &lt;span class="c1"&gt;# field does not have access to the initial value
&lt;/span&gt;        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;initial&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;password&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserAdmin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BaseUserAdmin&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# The forms to add and change user instances
&lt;/span&gt;    &lt;span class="n"&gt;form&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;UserChangeForm&lt;/span&gt;
    &lt;span class="n"&gt;add_form&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;UserCreationForm&lt;/span&gt;

    &lt;span class="c1"&gt;# The fields to be used in displaying the User model.
&lt;/span&gt;    &lt;span class="c1"&gt;# These override the definitions on the base UserAdmin
&lt;/span&gt;    &lt;span class="c1"&gt;# that reference specific fields on auth.User.
&lt;/span&gt;    &lt;span class="n"&gt;list_display&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;email&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;date_of_birth&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;is_admin&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;list_filter&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;is_admin&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,)&lt;/span&gt;
    &lt;span class="n"&gt;fieldsets&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&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;fields&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;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;email&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;password&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;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Personal info&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;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;fields&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;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;date_of_birth&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;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Permissions&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;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;fields&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;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;is_admin&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;span class="c1"&gt;# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
&lt;/span&gt;    &lt;span class="c1"&gt;# overrides get_fieldsets to use this attribute when creating a user.
&lt;/span&gt;    &lt;span class="n"&gt;add_fieldsets&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&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;classes&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;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;wide&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;fields&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;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;email&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;date_of_birth&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;password1&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;password2&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;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;search_fields&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;email&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,)&lt;/span&gt;
    &lt;span class="n"&gt;ordering&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;email&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,)&lt;/span&gt;
    &lt;span class="n"&gt;filter_horizontal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# Now register the new UserAdmin...
&lt;/span&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;MyUser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;UserAdmin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# ... and, since we're not using Django's built-in permissions,
# unregister the Group model from admin.
&lt;/span&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;unregister&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Group&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, specify the custom model as the default user model for your project using the &lt;code&gt;AUTH_USER_MODEL&lt;/code&gt; setting in your &lt;code&gt;settings.py&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;settings.py&lt;/code&gt;&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.MyUser&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. &lt;code&gt;AbstractUser&lt;/code&gt; to Create a Custom User Model
&lt;/h3&gt;

&lt;p&gt;This is pretty simple to start with and is flexible too. &lt;code&gt;AbstractUser&lt;/code&gt; is your &lt;code&gt;User&lt;/code&gt; Model the Django framework provides out of the box. Since you will be subclassing it. So now you can change stuff inside the class like using &lt;code&gt;email&lt;/code&gt; field instead of &lt;code&gt;username&lt;/code&gt; field for authentications.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;AbstractUser&lt;/code&gt; is a full &lt;code&gt;User&lt;/code&gt; model, complete with fields, like an abstract class, so that you can inherit from it and add your own profile fields and methods.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;models.py&lt;/code&gt;&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.db&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.contrib.auth.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AbstractUser&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;AbstractUser&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;bio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TextField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;blank&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;hobby&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CharField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;blank&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update your &lt;code&gt;setting.py&lt;/code&gt; to use the new &lt;code&gt;User&lt;/code&gt; Model&lt;/p&gt;

&lt;p&gt;&lt;code&gt;settings.py&lt;/code&gt;&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.MyUser&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where &lt;code&gt;users&lt;/code&gt; is the app’s name&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Django recommends having your own custom model even if you happy with the out of the box User model.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;What to do if I just need the default User Model and don’t want to add any other fields?&lt;/p&gt;

&lt;p&gt;Do it like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;models.py&lt;/code&gt;&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.contrib.auth.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AbstractUser&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;AbstractUser&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;pass&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__str__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And obviously, tell Django to use your Custom User Model in settings.py&lt;/p&gt;

&lt;p&gt;&lt;code&gt;settings.py&lt;/code&gt;&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.MyUser&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Referencing the &lt;code&gt;User&lt;/code&gt; model
&lt;/h2&gt;

&lt;p&gt;Now since you have changed your default &lt;code&gt;User&lt;/code&gt; Model. You might need to change the way you access it.&lt;/p&gt;

&lt;p&gt;Now in Option 2 where we used &lt;code&gt;OneToOneField&lt;/code&gt; in &lt;code&gt;Profile&lt;/code&gt; Model to relate to &lt;code&gt;User&lt;/code&gt; model like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;models.py&lt;/code&gt;&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.db&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.contrib.auth.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Profile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OneToOneField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;on_delete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CASCADE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;# Other Fields
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After using our Custom Model, the right/better way is to use &lt;code&gt;get_user_model( )&lt;/code&gt;, like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;models.py&lt;/code&gt;&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.db&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.contrib.auth&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;get_user_model&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Profile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OneToOneField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;get_user_model&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;on_delete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CASCADE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;# Other Fields
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;/p&gt;

&lt;p&gt;&lt;code&gt;model.py&lt;/code&gt;&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.db&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&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="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Profile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OneToOneField&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;AUTH_USER_MODEL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;on_delete&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CASCADE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;# Other Fields
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Up to you what you choose. Both will work fine.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reusable apps and &lt;code&gt;AUTH_USER_MODEL&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Reusable apps shouldn’t implement a custom user model. A project may use many apps, and two reusable apps that implemented a custom user model couldn’t be used together. If you need to store per user information in your app, use a ForeignKey or &lt;code&gt;OneToOneField&lt;/code&gt; to &lt;code&gt;settings.AUTH_USER_MODEL&lt;/code&gt; as described above.&lt;/p&gt;

&lt;h3&gt;
  
  
  Right Choice?
&lt;/h3&gt;

&lt;p&gt;It all ends up on you, your needs.&lt;/p&gt;

&lt;p&gt;A project I am working now needed Email Authentication instead of the username-password authentication that Django provides out of the box and we wanted the username field to be removed from my &lt;code&gt;User&lt;/code&gt; Model. So we used &lt;code&gt;AbstractUser&lt;/code&gt; to subclass my Custom User Model.&lt;/p&gt;

&lt;p&gt;To store more information about Users like the profile picture, bio, and other user-related information we created another Model called &lt;code&gt;Profile&lt;/code&gt; and we used &lt;code&gt;OneToOneField&lt;/code&gt; to relate it to Custom User Model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;It’s always a good idea to use a custom user model if you are still happy with the one provided by Django out of the box.&lt;/p&gt;

&lt;p&gt;That’s all for Custom User Model in Django.&lt;/p&gt;

&lt;p&gt;Let me know if this post helps you in any way in the comment section below.&lt;/p&gt;

</description>
      <category>django</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What is Programming?</title>
      <dc:creator>Rohit Lakhotia</dc:creator>
      <pubDate>Fri, 15 May 2020 07:52:05 +0000</pubDate>
      <link>https://dev.to/rohitlakh/what-is-programming-everything-you-need-to-know-39hl</link>
      <guid>https://dev.to/rohitlakh/what-is-programming-everything-you-need-to-know-39hl</guid>
      <description>&lt;p&gt;Creating products from scratch feels good or in some sense make us feel very proud and confident of ourselves. Which is very important for self-improvement. But how do you create them? What are the things involved? Let's see what is programming?&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Programming?
&lt;/h2&gt;

&lt;p&gt;There are many definitions to this but what I prefer is:&lt;/p&gt;

&lt;p&gt;Programming is a way to instruct/tell a computer to perform a specific task/solve a problem.&lt;/p&gt;

&lt;p&gt;There are 3 key phrases to look out for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  You: Computer will do what you (Programmer) told it to do.&lt;/li&gt;
&lt;li&gt;  Instruct: Instruction is given to the computer in a language that it can understand. We will discuss that below.&lt;/li&gt;
&lt;li&gt;  Problem: At the end of the day computers are tools (Complex). They are there to make out life simpler.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is a saying&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you told a computer to fall off a cliff, It definitely would!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is so true! They will do what they are programmed to do.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Programming used for?
&lt;/h2&gt;

&lt;p&gt;Programming is used in many scenarios. It can be making games, software that solves a particular task, apps that run on your phone, predicting trends or future.&lt;/p&gt;

&lt;p&gt;It plays a very important role in the software development process.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Computer Programming?
&lt;/h2&gt;

&lt;p&gt;Computer programming is programming that helps to solve a particular technical task/problem.&lt;/p&gt;

&lt;p&gt;Computer programming helps in developing programming languages that are used for solving technical problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, How is Computer programming done?
&lt;/h2&gt;

&lt;p&gt;We know that computer programming is giving instruction to the computer to solve tasks/problems.&lt;/p&gt;

&lt;p&gt;But&lt;/p&gt;

&lt;p&gt;How to convey instruction?&lt;/p&gt;

&lt;p&gt;The answer is Programming Languages&lt;/p&gt;

&lt;p&gt;Just like us, they have their own language (&lt;a href="https://www.computerhope.com/jargon/m/machlang.htm"&gt;Machine Language&lt;/a&gt;) to convey information. Therefore, computers don't understand languages like English, Spanish, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Programming Languages?
&lt;/h2&gt;

&lt;p&gt;According to &lt;a href="https://en.wikipedia.org/wiki/Programming_language"&gt;Wikipedia&lt;/a&gt;, A programming language is a formal language, which comprises a set of instructions that produce various kinds of output. Programming languages are used in computer programming to implement algorithms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Programming Languages:
&lt;/h2&gt;

&lt;p&gt;Programming Language can be categorized into 2 types of language:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; High-Level Language&lt;/li&gt;
&lt;li&gt; Low-Level Language&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  High-Level Language:
&lt;/h3&gt;

&lt;p&gt;High-Level Languages are programming languages like Java, Python, C, C++, etc which helps programmer to write programs which is independent with the type of computer.&lt;/p&gt;

&lt;p&gt;The computer with the help of the compiler compiles the High-Level Language into Low-Level Language which the computer can read and run to get the desired output.&lt;/p&gt;

&lt;h4&gt;
  
  
  High-Level Language is divided into 3 parts:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt; Procedural-Oriented language (3GL)&lt;/li&gt;
&lt;li&gt; Problem-Oriented language (4GL)&lt;/li&gt;
&lt;li&gt; Natural language (5GL)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Low-Level Language:
&lt;/h3&gt;

&lt;p&gt;Low-level languages are languages that the computer can understand and process without the need of a compiler.&lt;/p&gt;

&lt;h4&gt;
  
  
  Low-Level Languages are divided into 2 parts:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt; Machine language (1GL)&lt;/li&gt;
&lt;li&gt; Assembly language (2GL)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Difference between Coding and Programming?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FyMa5vS9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://learnitfree.org/wp-content/uploads/2020/03/Coding-VS-Programming.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FyMa5vS9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://learnitfree.org/wp-content/uploads/2020/03/Coding-VS-Programming.png" alt="In Image, Comparison of Coding VS Programming has been done." width="800" height="1132"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Coding VS Programming&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Definition:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Coding is the translation of Natural Language into Machine commands through an intermediary coding language.&lt;/p&gt;

&lt;p&gt;Programming is the process of development of a fully functional software solution.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Involves:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Coding involves writing many lines of code in order to create a software program.&lt;/p&gt;

&lt;p&gt;Programming involves not only coding but also other tasks, such as analyzing and implementing algorithms, understanding data structures, solving problems, and more.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Approach:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Coding, no previous preparation is needed. Trial-and-error. Whereas in Programming, methodical approach, attention to detail.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Experience:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Coding, basic knowledge of a programming language, it's syntax and keywords are needed.&lt;/p&gt;

&lt;p&gt;In Programming, experience in creating algorithms, modeling a problem, data processing, project management is needed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Outcome:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Coding, a simple solution or a small part of a project is the output. Whereas in Programming, full ready-to-use application is ready.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Difficulty:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Easier to be a Coder. Difficult to be a Programmer. Needs years of Experience.&lt;/p&gt;

&lt;p&gt;When I first started coding my first instinct was to learn Web Development since I wanted to make a website of my own where I would upload cool stuff that people could share and have fun with.&lt;/p&gt;

&lt;p&gt;So, I started learning HTML and CSS. BTW if you want to learn HTML5 you can check the &lt;a href="https://learnitfree.org/subject/learn-html-5/"&gt;Free Courses and Tutorial on HTML5&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;But wait.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is HTML even a Programming Language?
&lt;/h2&gt;

&lt;p&gt;Now that's a matter of debate. Since HTML stands for HyperText Markup Language. It can be classified as Language?&lt;/p&gt;

&lt;p&gt;Well, some say it is a programming language some say its just a language.&lt;/p&gt;

&lt;p&gt;According to &lt;a href="https://stackoverflow.com/users/2766176/brian-d-foy"&gt;Brian D Foy&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"No, HTML is not a programming language. The "M" stands for "Markup". Generally, a programming language allows you to describe some sort of process of doing something, whereas HTML is a way of adding context and structure to text."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;According to &lt;a href="https://stackoverflow.com/users/7831/chris-pietschmann"&gt;Chris Pietschmann&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"YES, a declarative programming language."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Well, What do you think, Is HTML a Programming Language?&lt;/p&gt;

&lt;h3&gt;
  
  
  Where to go next?
&lt;/h3&gt;

&lt;p&gt;So you started to gather interest in programming? Want to learn to Code? Can't find resources? Then you can check out &lt;a href="https://learnitfree.org/"&gt;Free Courses and Tutorial from all over the Web&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
