<?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: keshav Sharma</title>
    <description>The latest articles on DEV Community by keshav Sharma (@ksharma20).</description>
    <link>https://dev.to/ksharma20</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%2F916714%2Fc2bab30f-b2fc-4403-95cc-0f88ff8b5ead.jpeg</url>
      <title>DEV Community: keshav Sharma</title>
      <link>https://dev.to/ksharma20</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ksharma20"/>
    <language>en</language>
    <item>
      <title>How to Learn Coding in Python ?</title>
      <dc:creator>keshav Sharma</dc:creator>
      <pubDate>Mon, 02 Jan 2023 07:55:06 +0000</pubDate>
      <link>https://dev.to/ksharma20/how-to-learn-coding-in-python--lgc</link>
      <guid>https://dev.to/ksharma20/how-to-learn-coding-in-python--lgc</guid>
      <description>&lt;p&gt;If you are considering learning to code in python, you are making a smart choice. &lt;a href="http://python.org" rel="noopener noreferrer"&gt;Python&lt;/a&gt; is a popular programming language that is widely used in various fields, such as web development, scientific computing, data analysis, and artificial intelligence.&lt;br&gt;
It is known for its simplicity, readability, and flexibility, which makes it a great choice for beginners as well as experienced developers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reasons why you should consider learning python.
&lt;/h2&gt;

&lt;p&gt;There are many Reasons why you should consider learning python. Here are a few:&lt;/p&gt;

&lt;p&gt;One of the main reasons why python is so popular is because it is relatively easy to learn, especially compared to other programming languages. It has a simple syntax and uses indentation to denote blocks of code, which makes it easy to read and understand. If you are new to programming, python is a great place to start.&lt;/p&gt;

&lt;p&gt;Python can be used to build almost any kind of software, from desktop applications to web applications and scientific applications. It is also widely used in data science and machine learning, making it a valuable skill to have in today’s job market. Whether you want to build a website, create a data analysis tool, or develop a machine learning model, python has the tools and libraries you need.&lt;/p&gt;

&lt;p&gt;Python has a large and active community of developers and users, which means that you will always have access to support and resources when you are learning or working with the language. There are also many libraries and frameworks available in python that can help you build applications more efficiently.&lt;/p&gt;

&lt;p&gt;Python is a widely used programming language, and as such, it is in high demand in the job market. Companies across various industries are looking for developers with python skills, and learning python can open up a lot of career opportunities for you.&lt;/p&gt;

&lt;p&gt;Now that you know why learning python is a good idea, let’s talk about&lt;/p&gt;

&lt;h2&gt;
  
  
  How to get started ?
&lt;/h2&gt;

&lt;p&gt;Here are some tips to help you on your journey:&lt;/p&gt;

&lt;p&gt;There are many resources available online for learning python, such as tutorials, online courses, and books. Make sure to choose a resource that is suitable for your learning style and pace. There are also many online communities and forums where you can ask questions and get help from other python developers.&lt;/p&gt;

&lt;p&gt;The best way to learn python (or any programming language) is to practice as much as possible. Write small programs and gradually increase the complexity as you become more comfortable with the language. Don’t be afraid to make mistakes – they are an essential part of the learning process.&lt;/p&gt;

&lt;p&gt;Instead of just following tutorials, try to work on a project of your own. This will give you a chance to apply the concepts you have learned and will also help you develop problem-solving skills. Start with a small project and gradually increase the complexity as you progress.&lt;/p&gt;

&lt;p&gt;As mentioned earlier, python has a large and active community. Consider joining forums, online groups, or local meetups where you can interact with other python developers and get help with your learning. These communities can also be a great source of inspiration and ideas for projects.&lt;/p&gt;

&lt;p&gt;Before diving into more advanced concepts, make sure to learn the basics of python. This includes data types, variables, loops, and control structures. These concepts form the foundation of any python program, and it is important to understand them before moving on to more complex topics.&lt;/p&gt;

&lt;p&gt;Python is a constantly evolving language, with new libraries and frameworks being released all the time. Make sure to stay up to date with the latest developments in the python&lt;/p&gt;

&lt;h2&gt;
  
  
  Summarize
&lt;/h2&gt;

&lt;p&gt;To summarize, learning python can be a great investment of your time and resources. It is a versatile and in-demand programming language that can open up a lot of career opportunities for you. Make sure to choose a good resource, practice as much as possible, work on a project, and join a community to get the most out of your learning journey.&lt;/p&gt;

&lt;h3&gt;
  
  
  To get more such useful Posts and Contents:
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Please visit ⇒ &lt;a href="http://csegeeks.com" rel="noopener noreferrer"&gt;CSE Geeks&lt;/a&gt;
&lt;/h4&gt;

</description>
      <category>updates</category>
      <category>beginners</category>
      <category>coding</category>
      <category>python</category>
    </item>
    <item>
      <title>How to use subdomains for Different Apps in Django Project ?</title>
      <dc:creator>keshav Sharma</dc:creator>
      <pubDate>Wed, 31 Aug 2022 17:22:52 +0000</pubDate>
      <link>https://dev.to/ksharma20/how-to-use-subdomains-for-different-apps-in-django-project--fbi</link>
      <guid>https://dev.to/ksharma20/how-to-use-subdomains-for-different-apps-in-django-project--fbi</guid>
      <description>&lt;p&gt;Hello Folks 😁 !&lt;br&gt;
Welcome back to the world of learning.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In last article, we learnt about &lt;a href="https://dev.to/ksharma20/how-to-deploy-a-django-web-app-on-vercel-for-free-4fhe"&gt;&lt;strong&gt;How to deploy our django project on vercel for free&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this article, I will show you how to set up subdomains on different apps inside a &lt;strong&gt;Django&lt;/strong&gt; project.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Subdomains are a prefix on a URL that exists before the domain name. For example, for the &lt;a href="https://csegeeks.com" rel="noopener noreferrer"&gt;&lt;strong&gt;csegeeks.com&lt;/strong&gt;&lt;/a&gt; website, a subdomain is, &lt;a href="https://keshav.csegeeks.com" rel="noopener noreferrer"&gt;&lt;strong&gt;keshav.csegeeks.com&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It's a very common thing that is used for web pages.&lt;/p&gt;

&lt;p&gt;Subdomains for the domain name, example.com, might include api.example.com, maps.example.com, events.example.com, etc.&lt;/p&gt;

&lt;p&gt;So, how do we create subdomains for a website in Django ?&lt;/p&gt;

&lt;p&gt;It can be done in &lt;strong&gt;7 Easy Steps !&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It turns out there is a third-party module, django-hosts, that allows a Django website to have subdomains.&lt;/p&gt;

&lt;p&gt;So, let's Dive IN !!&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1
&lt;/h3&gt;

&lt;p&gt;Install django-hosts module onto your machine using&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Once this has been successfully installed, we need to make a number of changes to the &lt;code&gt;settings.py&lt;/code&gt; file of the project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2
&lt;/h3&gt;

&lt;p&gt;Add 'django_hosts' to INSTALLED_APPS in settings.py&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;INSTALLED_APPS&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;...&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;...&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;...&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;django_hosts&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;h3&gt;
  
  
  Step 3
&lt;/h3&gt;

&lt;p&gt;Add the new subdomains to the ALLOWED_HOSTS variable. &lt;em&gt;Without adding the subdomains to the ALLOWED_HOSTS list, the subdomains won't work once you enter them into a browser.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In this example, we are going to create the subdomains, api.mysite.com and maps.mysite.com&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;ALLOWED_HOSTS&lt;/strong&gt; variable will be equal to that as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;ALLOWED_HOSTS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;api.localhost&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;localhost&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;api.mysite&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;mysite&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;So within this &lt;strong&gt;ALLOWED_HOSTS&lt;/strong&gt; variable, we have a number of items.&lt;/p&gt;

&lt;p&gt;Again, any subdomain that you create must be added to the &lt;strong&gt;ALLOWED_HOSTS&lt;/strong&gt; variable. Or else, the subdomain will not work.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4
&lt;/h3&gt;

&lt;p&gt;The next thing we will need to do is add &lt;code&gt;'django_hosts.middleware.HostsRequestMiddleware'&lt;/code&gt; to the beginning of the MIDDLEWARE or MIDDLEWARE_CLASSES setting.&lt;/p&gt;

&lt;p&gt;Then we will need to add &lt;code&gt;'django_hosts.middleware.HostsResponseMiddleware'&lt;/code&gt; to the end of the MIDDLEWARE or MIDDLEWARE_CLASSES setting.&lt;/p&gt;

&lt;p&gt;This will look like that of the following below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;MIDDLEWARE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django_hosts.middleware.HostsRequestMiddleware&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;..............................................&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;..............................................&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;..............................................&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;django_hosts.middleware.HostsResponseMiddleware&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;The middleware handles requests and responses.&lt;/p&gt;

&lt;p&gt;When a user types in a URL and clicks the enter button, s/he is requesting a page. This triggers Django middleware to begin processing the request. If the domain name contains a subdomain, then the 'django_hosts.middleware.HostsRequestMiddleware' class intercepts and begins the process of retrieving this request.&lt;/p&gt;

&lt;p&gt;After this, we still have more lines of code to add to the &lt;code&gt;settings.py&lt;/code&gt; file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5
&lt;/h3&gt;

&lt;p&gt;Right underneath the &lt;code&gt;ROOT_URLCONF&lt;/code&gt; variable, Add the following 2 lines, shown below.&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;ROOT_HOSTCONF&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;mysite.hosts&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;DEFAULT_HOST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;www&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What the &lt;strong&gt;ROOT_HOSTCONF&lt;/strong&gt; does is it shows the path to the URL scheme of all the subdomains on the website. This is the file that maps out all the subdomains for the website.&lt;/p&gt;

&lt;p&gt;Usually you want to call this file hosts.py and put it in the same directory as the &lt;code&gt;settings.py&lt;/code&gt; file. This is why, in the &lt;code&gt;ROOT_HOSTCONF&lt;/code&gt; variable, you replace &lt;code&gt;'mysite'&lt;/code&gt; with the name of your project. &lt;strong&gt;hosts&lt;/strong&gt; exists because the file within this directory is named &lt;code&gt;hosts.py&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6
&lt;/h3&gt;

&lt;p&gt;Now we will create &lt;code&gt;hosts.py&lt;/code&gt; file in Root Directory.&lt;/p&gt;

&lt;p&gt;The contents of the &lt;code&gt;hosts.py&lt;/code&gt; file is shown below.&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_hosts&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;patterns&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;host&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="n"&gt;host_patterns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;patterns&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;www&lt;/span&gt;&lt;span class="sh"&gt;'&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;ROOT_URLCONF&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;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;www&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;api&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;api.urls&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;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;api&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As stated before, the hosts.py file within the project directory contains all the subdomains on the site. As you can see above, the website has a subdomain now site up: &lt;strong&gt;api.mysite.com&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The www is just the generic view that doesn't return any subdomain. This means that a user will be redirected to the main site.&lt;/p&gt;

&lt;p&gt;So we have the &lt;code&gt;hosts.py&lt;/code&gt; file done.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 7
&lt;/h3&gt;

&lt;p&gt;The last thing you must do now is create an app for &lt;em&gt;api&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Within this app, just like any other app, you must specify a &lt;code&gt;views.py&lt;/code&gt; function, along with a URL that maps to the appropriate page.&lt;/p&gt;

&lt;p&gt;So let's say we create the following &lt;code&gt;urls.py&lt;/code&gt; file within the api app.&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.urls&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;path&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;.views&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;apihome&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;apiaddnote&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;urlpatterns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
     &lt;span class="nf"&gt;path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;apihome&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;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;apihome&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
     &lt;span class="nf"&gt;path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;note&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;apiaddnote&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;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;apiaddnote&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
   &lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this URL configuration, you can now go to &lt;strong&gt;&lt;em&gt;api.mysite.com&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;api.mysite.com/note&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are running this site on a local server, you can access these subdomains with, &lt;code&gt;api.localhost:8000&lt;/code&gt; and &lt;code&gt;api.localhost:8000/note&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can add as many subdomains as wanted for your website. For each subdomain that you add, you have to create an app for each one. This is the correct way of doing it. This is because you are creating a subdomain to create division within your site. Therefore, you want each subdomain to have its own app.&lt;/p&gt;

&lt;h3&gt;
  
  
  Finally
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Testing Locally
&lt;/h4&gt;

&lt;p&gt;In order to test it locally, you will need to setup a local DNS host.&lt;/p&gt;

&lt;p&gt;On Linux and Mac, the file is located in the path &lt;code&gt;/etc/hosts&lt;/code&gt;. For Windows it should be somewhere in &lt;code&gt;%SystemRoot%\system32\drivers\etc\hosts&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;hosts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;127.0.0.1 localhost
255.255.255.255 broadcasthost
::1             localhost

127.0.0.1 www.mysite.local
127.0.0.1 help.mysite.local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this is &lt;strong&gt;&lt;em&gt;how to set up subdomains for a website in Django.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So, this was another 7 Step tutorial after &lt;a href="https://dev.to/ksharma20/how-to-deploy-a-django-web-app-on-vercel-for-free-4fhe"&gt;&lt;strong&gt;How to Deploy Django project to Vercel for Free (&lt;em&gt;In Easy 7 Steps&lt;/em&gt;)&lt;/strong&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If you like my work, please consider &lt;em&gt;upvoting &amp;amp; bookmarking&lt;/em&gt; the post for later you ! And don't forget to &lt;a href="https://dev.to/ksharma20"&gt;&lt;strong&gt;follow&lt;/strong&gt;&lt;/a&gt; for more Django related Tutorial !!&lt;/p&gt;

</description>
      <category>django</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Deploy a Django web App on Vercel (For Free).</title>
      <dc:creator>keshav Sharma</dc:creator>
      <pubDate>Sun, 28 Aug 2022 10:12:00 +0000</pubDate>
      <link>https://dev.to/ksharma20/how-to-deploy-a-django-web-app-on-vercel-for-free-4fhe</link>
      <guid>https://dev.to/ksharma20/how-to-deploy-a-django-web-app-on-vercel-for-free-4fhe</guid>
      <description>&lt;p&gt;Hello forks ! 😁&lt;br&gt;
Now that &lt;a href="//heroku.com"&gt;Heroku&lt;/a&gt; is terminating its free tier, Django developers need an alternative to deploy their Django / DRF web App to get it live !&lt;/p&gt;

&lt;p&gt;In this post, I am going to show you how you can deploy your Django or Django rest framework project on &lt;a href="https://vercel.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;Vercel&lt;/strong&gt;&lt;/a&gt; in 7 easy steps.&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequisites:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You Already have a &lt;strong&gt;working Django Project&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You already have created a &lt;strong&gt;vercel account&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You already have a &lt;strong&gt;requirements.txt&lt;/strong&gt; file
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  django
  djangorestframework
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Vercel does not provide support for &lt;em&gt;dbsqlite3&lt;/em&gt; currently, if you try to deploy your project with Django's default dbsqlite3 database then it's going to lead to an error. Ensure to comment out your dbsqlite database configuration or switch to a different database (e.g. &lt;strong&gt;&lt;a href="https://www.postgresql.org/" rel="noopener noreferrer"&gt;PostgreSQL&lt;/a&gt;&lt;/strong&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Alright, let's dive in !!&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1
&lt;/h3&gt;

&lt;p&gt;In your projects root directory create a new file and name it build_files.sh then paste the code below inside it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# build_files.sh&lt;/span&gt;
pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt
python3.9 manage.py collectstatic &lt;span class="nt"&gt;--noinput&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file contains commands we want to run at build time on vercel&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;"pip install -r requirements.txt"&lt;/em&gt;&lt;/strong&gt; ensures that all our installed packages declared in our requirements.txt file are downloaded and installed on the vercel server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;"python3.9 manage.py collectstatic --noinput"&lt;/em&gt;&lt;/strong&gt; ensures that our static files are served on our server (ensure to add this line of code even if your static files are being served from an external website because our admin page contains some static files).&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2
&lt;/h3&gt;

&lt;p&gt;In your projects root directory create a new JSON file and name it &lt;strong&gt;&lt;em&gt;vercel.json&lt;/em&gt;&lt;/strong&gt; then paste the code below inside it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"builds"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"src"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;projectname&amp;gt;/wsgi.py"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"use"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"@vercel/python"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"config"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"maxLambdaSize"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"15mb"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"runtime"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"python3.9"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"src"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"build_files.sh"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"use"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"@vercel/static-build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"config"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"distDir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"staticfiles"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"routes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"src"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/static/(.*)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"dest"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/static/$1"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"src"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/(.*)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"dest"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;projectname&amp;gt;/wsgi.py"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ensure to replace &lt;code&gt;*&amp;lt;projectname&amp;gt;*&lt;/code&gt; with the actual name of your project name.&lt;/p&gt;

&lt;p&gt;Under &lt;code&gt;"builds", "src": "projectname/wsgi."&lt;/code&gt; points to the file that contains a WSGI application declaration that was created by Django for you in your projects directory.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"config": { "maxLambdaSize": "15mb", "runtime":"python3.9" }&lt;/code&gt; increases the size limit of our bundle (the default is 5MB),  while runtime specifies the python version we want to use, in this case we are using python 3.9.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"routes": [ ... ] rewrites all routes ("src": "/(.*)")&lt;/code&gt; to our WSGI application &lt;code&gt;("dest": "projectname/wsgi.py")&lt;/code&gt; to be handled.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3
&lt;/h3&gt;

&lt;p&gt;Go to your projects setting.py and paste in the code below&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;STATICFILES_DIRS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;BASE_DIR&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;static&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,]&lt;/span&gt;
&lt;span class="n"&gt;STATIC_ROOT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;BASE_DIR&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;staticfiles&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4
&lt;/h3&gt;

&lt;p&gt;If you are using dbsqlite3 then comment it out like so. Since this is going to be a production environment, I highly recommend that you should switch to another database such as PostgreSQL.&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;DATABASES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;# 'default': {
&lt;/span&gt;    &lt;span class="c1"&gt;#     'ENGINE': 'django.db.backends.sqlite3',
&lt;/span&gt;    &lt;span class="c1"&gt;#     'NAME': BASE_DIR / 'db.sqlite3',
&lt;/span&gt;    &lt;span class="c1"&gt;# }
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you commented out your database as shown above (i.e, You app does not need a database to store anything), then skip this Step and Go to Step 5.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4.5
&lt;/h3&gt;

&lt;p&gt;But if you took my advice and switched to a different database (i.e, PostgreSQL), then run the following commands in your terminal&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;python&lt;/span&gt; &lt;span class="n"&gt;manage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt; &lt;span class="n"&gt;makemigrations&lt;/span&gt;
&lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="n"&gt;manage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt; &lt;span class="n"&gt;migrate&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Creates a new migration and migrate your Django project to your database. This is needed for &lt;strong&gt;staticfiles&lt;/strong&gt; to served on the vercel server.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5
&lt;/h3&gt;

&lt;p&gt;Next step is to go to your settings.py file and update your ALLOWED_HOST to permit vercel.app to be a valid hostname for your Django app, like so&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;ALLOWED_HOSTS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;.vercel.app&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;.now.sh&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;h3&gt;
  
  
  Step 6
&lt;/h3&gt;

&lt;p&gt;Go to your wsgi.py file created for you by Django in your project directory and paste in the line of code below&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;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;application&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will point the app variable that vercel is going to be looking for to your project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 7
&lt;/h3&gt;

&lt;p&gt;Finally, upload your code to a GitHub repo and connect your GitHub account with said repo to your vercel dashboard.&lt;/p&gt;

&lt;p&gt;Import the project.&lt;/p&gt;

&lt;p&gt;You can change the default project name to something else if you wish, but ensure to leave all other settings as default.&lt;/p&gt;

&lt;p&gt;Then click on deploy and after a couple of seconds your project will be deployed successfully on vercel.&lt;/p&gt;

&lt;p&gt;Finally, go to &lt;a href="https://github.com/keshav-xebia/QuesMaker/" rel="noopener noreferrer"&gt;QuesMaker&lt;/a&gt; to see the example project on my GitHub page.&lt;/p&gt;

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

&lt;p&gt;Following the steps above will get your &lt;em&gt;Django&lt;/em&gt; or &lt;em&gt;Django rest framework project&lt;/em&gt; hosted on &lt;strong&gt;vercel&lt;/strong&gt;. As always thanks for reading, if you have any questions, thoughts or run into any error's following the steps above then leave a comment down below, and we'll try my best to help.&lt;/p&gt;

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