<?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>Forem: Biplov</title>
    <description>The latest articles on Forem by Biplov (@biplov).</description>
    <link>https://forem.com/biplov</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%2F257596%2F7487d7f0-bffb-471c-ab0d-2125983b3750.jpeg</url>
      <title>Forem: Biplov</title>
      <link>https://forem.com/biplov</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/biplov"/>
    <language>en</language>
    <item>
      <title>Django: What, Why, When ?
</title>
      <dc:creator>Biplov</dc:creator>
      <pubDate>Mon, 13 Jul 2020 14:37:24 +0000</pubDate>
      <link>https://forem.com/biplov/django-what-why-when-5h9g</link>
      <guid>https://forem.com/biplov/django-what-why-when-5h9g</guid>
      <description>&lt;p&gt;In this article will take a look at Django-"The Web framework for perfectionists with deadlines". We will outline some of its feature and discuss why using Django is a good choice. We will also point out when to use django and when not to. &lt;/p&gt;

&lt;h1&gt;
  
  
  What is Django?
&lt;/h1&gt;

&lt;p&gt;Django is an open source web application framework written in Python that encourages rapid development and pragmatic, clean design. It follows the "batteries-included" philosophy, meaning that Django comes with common functionality for building web applications, reducing much of the hassle of Web development.&lt;/p&gt;

&lt;p&gt;Django supports the Model-View-Template (MVT) pattern, which is slightly different from Model-View-Controller (MVC) pattern. In MVT pattern:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Model is a data access layer that helps to handle database. &lt;/li&gt;
&lt;li&gt;View executes the business logic and interact with a model to carry data and render the appropriate template.&lt;/li&gt;
&lt;li&gt; Template is a presentation layer that defines how something should be displayed on a Web page . &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wZV9_uu3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/d85c2zuye6xw3odavxt0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wZV9_uu3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/d85c2zuye6xw3odavxt0.png" alt="MVT"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Why use Django ?
&lt;/h1&gt;

&lt;h3&gt;
  
  
  It is Fast
&lt;/h3&gt;

&lt;p&gt;Django is ridiculously fast and helps to turn your idea into product in no time. It follows DRY philosophy, which means we can reuse existing code, thus no unnecessary duplication.&lt;/p&gt;

&lt;h3&gt;
  
  
  It is Secure
&lt;/h3&gt;

&lt;p&gt;Security is a high priority for Django and helps developers avoid many common security mistakes including SQL injection, cross-site scripting, cross-site request forgery and clickjacking.&lt;/p&gt;

&lt;h3&gt;
  
  
  It is Scalable
&lt;/h3&gt;

&lt;p&gt;Some of the busiest sites on the Web leverage Django’s ability to quickly and flexibly scale.Some examples of websites that are running on Django are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Instagram&lt;/li&gt;
&lt;li&gt;Disqus&lt;/li&gt;
&lt;li&gt;Bitbucket&lt;/li&gt;
&lt;li&gt;Spotify&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  It is Versatile
&lt;/h3&gt;

&lt;p&gt;Django can be used to build almost any type of website, from simple website to high-end web application. Django is used to build all sorts of things — from content management systems to social networks to scientific computing platforms.&lt;br&gt;
It is compatible with most major databases and allows using a database that is more suitable in a particular project.&lt;/p&gt;
&lt;h1&gt;
  
  
  When use Django?
&lt;/h1&gt;

&lt;p&gt;Choosing a framework for your project depends on a lot of factors. It is better to make an informed choice before you start rather than regret it halfway. Selecting an appropriate framework depends on type of project and  desired outcomes.&lt;/p&gt;

&lt;p&gt;Some of the situations when Django is a good choice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;building a highly customizable app, such as a social media website.&lt;/li&gt;
&lt;li&gt;when security is a top priority.&lt;/li&gt;
&lt;li&gt;your app might scale up/down at any point of time.&lt;/li&gt;
&lt;li&gt;building apps that are entirely back-end.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just because you can use Django to develop almost any type of website doesn't mean you should always use them. Django is not the best option when building a basic web applications as it’s a heavy framework with a lot of features. Micro framework, such as Flask works better in such situations.&lt;/p&gt;
&lt;h1&gt;
  
  
  Getting started with Django
&lt;/h1&gt;

&lt;p&gt;Congratulations, now you have a basic understanding about Django and its use cases.&lt;br&gt;
Here is a great article from &lt;a class="comment-mentioned-user" href="https://dev.to/wsvincent"&gt;@wsvincent&lt;/a&gt;
 to get started.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/wsvincent" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cyc_FXvb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--pLu15nDq--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/284931/37601a15-c230-4ca6-9de3-70ab2cb9a5df.png" alt="wsvincent image"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/learndjango/how-to-learn-django-2020-3g45" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;How to Learn Django (2020)&lt;/h2&gt;
      &lt;h3&gt;William S. Vincent ・ Jun 21 ・ 4 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#django&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#python&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>python</category>
      <category>django</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>17 Popular Python Opensource Projects on GitHub</title>
      <dc:creator>Biplov</dc:creator>
      <pubDate>Thu, 21 May 2020 16:43:28 +0000</pubDate>
      <link>https://forem.com/biplov/17-popular-python-opensource-projects-on-github-21ae</link>
      <guid>https://forem.com/biplov/17-popular-python-opensource-projects-on-github-21ae</guid>
      <description>&lt;p&gt;Python is a popular programming language, so it is no surprise that it has a large opensource presence with many powerful projects that receives contribution from developers around the world. Here is a list of some of the popular python open-source projects.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/tensorflow/tensorflow"&gt;TensorFlow&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 145K&lt;br&gt;
TensorFlow is a Machine Learning Framework that has a comprehensive, flexible ecosystem of tools, libraries, and community resources that lets researchers push the state-of-the-art in ML and developers easily build and deploy ML-powered applications.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/ytdl-org/youtube-dl"&gt;youtube-dl&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 66.4K&lt;br&gt;
Command-line program to download videos from YouTube and other video sites&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/nvbn/thefuck/"&gt;thefuck&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 53.6K&lt;br&gt;
It is an app which corrects your previous console command.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/pallets/flask"&gt;Flask&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 53.6K&lt;br&gt;
Flask is a micro web framework written in Python. It is designed to make getting started quick and easy, with the ability to scale up to complex applications. &lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/django/django"&gt;Django&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 49.4K&lt;br&gt;
Django is a free and open-source Python web development framework that follows the Model–Template–View (MTV) pattern. It comes with most of the libraries and tools required for common use cases.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/keras-team/keras"&gt;Keras&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 48.3K&lt;br&gt;
Keras is an Open Source Neural Network library written in Python that runs on top of TensorFlow, CNTK, or Theano.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/jakubroztocil/httpie"&gt;HTTPie&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 46.8K&lt;br&gt;
HTTPie is a command line HTTP client that makes CLI interaction with web services as human-friendly as possible.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/ansible/ansible"&gt;Ansible&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 43.2K&lt;br&gt;
Ansible is an open source IT Configuration Management, Deployment &amp;amp; Orchestration tool that makes your applications and systems easier to deploy.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/psf/requests"&gt;Requests&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 42.5K&lt;br&gt;
Requests is a Python HTTP library that makes HTTP requests simpler and more human-friendly.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/scikit-learn/scikit-learn"&gt;Scikit-learn&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 40.8K&lt;br&gt;
Scikit-learn is an open source Python library built on top of SciPy that has powerful tools for data analysis and data mining.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/pytorch/pytorch"&gt;PyTorch&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 38.8K&lt;br&gt;
PyTorch is an open source machine learning library based on the Torch library, used for applications such as computer vision and natural language processing.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/scrapy/scrapy"&gt;Scrapy&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 37.2K&lt;br&gt;
Scrapy is a fast high-level web crawling and web scraping framework, used to crawl websites and extract structured data from their pages. &lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/ageitgey/face_recognition"&gt;Face Recognition&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 34.2K&lt;br&gt;
Recognize and manipulate faces from Python or from the command line with the world's simplest face recognition library.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/pandas-dev/pandas"&gt;Pandas&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 25K&lt;br&gt;
Pandas is a Python package providing fast, flexible, and expressive data structures designed to make working with "relational" or "labeled" data both easy and intuitive.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/getsentry/sentry"&gt;Sentry&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 24.9K&lt;br&gt;
Sentry is a service that helps you monitor and fix crashes in realtime. Although written in Python, Sentry works with most languages and frameworks.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/pypa/pipenv"&gt;Pipenv&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 20.3K&lt;br&gt;
Pipenv is a dependency manager for Python projects that simplifies dependency management for common use cases.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/fastai/fastai"&gt;fastai&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐ 17.9K&lt;br&gt;
The fastai library simplifies training fast and accurate neural nets using modern best practices.&lt;/p&gt;

</description>
      <category>python</category>
      <category>opensource</category>
      <category>github</category>
    </item>
    <item>
      <title>15 Fun APIs For Your Next Project</title>
      <dc:creator>Biplov</dc:creator>
      <pubDate>Mon, 04 May 2020 18:09:41 +0000</pubDate>
      <link>https://forem.com/biplov/15-fun-apis-for-your-next-project-5053</link>
      <guid>https://forem.com/biplov/15-fun-apis-for-your-next-project-5053</guid>
      <description>&lt;p&gt;Maybe you want to make something cool for the web using some APIs. Maybe you are tired from building all the to-do lists and calculators and want to try something different. Whatever be the case you can use these API and build something creative.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://funtranslations.com/api/"&gt;Fun Translations&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Translate regular English to 50+ languages from Yoda speak to Dorthraki to Klingon. Some fun stuff with this one, you can build. &lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="http://itsthisforthat.com/api.php"&gt;This for That&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Need a new idea for startup? &lt;a href="http://itsthisforthat.com/api.php"&gt;This for That&lt;/a&gt; generates new ideas by supplying two random parameters. You can visit their website &lt;a href="http://itsthisforthat.com/"&gt;here&lt;/a&gt; if you just need some new startup ideas.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://api.chucknorris.io/"&gt;Chuck Norris Jokes API&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;If you are a fan of Chuck Norris this one is for you, a free JSON API for hand curated Chuck Norris facts.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://deckofcardsapi.com/"&gt;Deck of Cards API&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;This API allows you to simulate a deck of cards. You can build some cool card games without worrying much aboaut the back-end stuff. &lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="http://jservice.io/"&gt;jService&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Maybe it’s time for you to build your own trivia app.This API provides Jeopardy trivia data including the questions and answers. There are over 156,800 Trivia Questions to choose from.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://developers.giphy.com/"&gt;GIPHY API&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;GIPHY's API makes it dead simple for developers to incorporate GIPHY's vast library right inside of their apps.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="http://www.omdbapi.com/"&gt;OMDb API&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;OMDb is the API for all the movie information you need. Maybe this is all you need to build somehing cool like &lt;a href="https://letterboxd.com/"&gt;letterboxd&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="http://open-notify.org/Open-Notify-API/ISS-Location-Now/"&gt;International Space Station API&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Ever wondered where the ISS could be right about now?  Well, wonder no more. This api returns the current location of the ISS. Now you can build your own ISS tracker.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://www.tronalddump.io/"&gt;Tronald Dump&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;If you want to find the dumbest things Donald Trump has ever said this one is for you.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://api.adviceslip.com/"&gt;Advice Slip&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Need some advice? Why not create an advice generator? You can use this API to generate a random piece of advice. &lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://api.nasa.gov/"&gt;Nasa API&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Outer space has always been fascinating to humans.Now you can explore more with NASA’s incredible data, including its spectacular imagery through NASA API.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://developer.spotify.com/documentation/web-api/"&gt;Spotify API&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Spotify's web API allows you to query data about music artists, albums, and tracks, directly from the Spotify Data Catalogue.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://spoonacular.com/food-api"&gt;Recipe API&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;With over 360k recipes and 90k products, you can build a great food app using this API.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://www.brewerydb.com/"&gt;BreweryDB&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.brewerydb.com/"&gt;BreweryDB&lt;/a&gt; is the most complete database of breweries and beers.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://developer.marvel.com/"&gt;Marvel Comics API&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Fan of comics? This API allows you to access information about Marvel's vast library of comics—from what's coming up, to 70 years ago.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can also check out this &lt;a href="https://github.com/public-apis/public-apis"&gt;github repository&lt;/a&gt; for an extensive list of public APIs.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>api</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to Paginate with Django?</title>
      <dc:creator>Biplov</dc:creator>
      <pubDate>Fri, 17 Apr 2020 03:20:16 +0000</pubDate>
      <link>https://forem.com/biplov/how-to-paginate-with-django-5c8p</link>
      <guid>https://forem.com/biplov/how-to-paginate-with-django-5c8p</guid>
      <description>&lt;p&gt;Pagination is a common navigation technique of dividing content into discrete pages. It helps make the content more organized, and thus improving user experience.&lt;/p&gt;

&lt;p&gt;So, how do we paginate data in Django?&lt;br&gt;
First thing we need to do is update our views to  paginate the data.&lt;br&gt;
We will look at both &lt;code&gt;Function-Based Views&lt;/code&gt; and &lt;code&gt;Class-Based Views&lt;/code&gt;.&lt;/p&gt;
&lt;h1&gt;
  
  
  Function-Based View
&lt;/h1&gt;

&lt;p&gt;We need to import paginator from &lt;code&gt;django.core.paginator&lt;/code&gt; which splits a Query-Set into Page objects.&lt;br&gt;
Consider we have 45 blog posts and we want to display at most 10 posts per page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.shortcuts import render
from django.core.paginator import Paginator
form .models import Blog

def blogposts(request):
    blogs = Blog.objects.all()
    paginator = Paginator(blogs, 10)

    page_number = request.GET.get('page')
    page_obj = paginator.get_page(page_number)
    return render(request, 'index.html', {'page_obj': page_obj})


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above example will Paginate the blogs Query-Set in pages of 10. This will create a 5 pages result. The first 4 pages with 10 blog posts each and the last page with 5.&lt;/p&gt;

&lt;h1&gt;
  
  
  Class-Based View
&lt;/h1&gt;

&lt;p&gt;In class based views we can use  &lt;code&gt;paginate_by&lt;/code&gt; attribute to specify the number by which to paginate the queryset.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from .models import Blog
from django.views.generic import ListView

class blogposts(ListView):
    model = Blog
    paginate_by = 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Template
&lt;/h1&gt;

&lt;p&gt;After updating the views we need to update our template.&lt;br&gt;
To be able to navigate between posts we need to add links in our template.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!--
 code to display blog posts ...
--&amp;gt;
&amp;lt;div class="pagination"&amp;gt;
    &amp;lt;span class="step-links"&amp;gt;
        {% if page_obj.has_previous %}          
            &amp;lt;a href="?page={{ page_obj.previous_page_number }}"&amp;gt;previous&amp;lt;/a&amp;gt;
        {% endif %}

        &amp;lt;span class="current"&amp;gt;
          {{ page_obj.number }}
        &amp;lt;/span&amp;gt;

        {% if page_obj.has_next %}
            &amp;lt;a href="?page={{ page_obj.next_page_number }}"&amp;gt;next&amp;lt;/a&amp;gt;
        {% endif %}
    &amp;lt;/span&amp;gt;
&amp;lt;/div&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This displays a previous-next links with current page number. &lt;br&gt;
&lt;br&gt;&lt;br&gt;
This is a simple example of pagination but you can get more creative with it. You can follow this &lt;a href="https://docs.djangoproject.com/en/3.0/ref/paginator/"&gt;link&lt;/a&gt; for more information about Paginator class.&lt;/p&gt;

</description>
      <category>django</category>
      <category>python</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Deploy a Django Application to Heroku </title>
      <dc:creator>Biplov</dc:creator>
      <pubDate>Tue, 31 Mar 2020 02:42:48 +0000</pubDate>
      <link>https://forem.com/biplov/how-to-deploy-a-django-application-to-heroku-27nd</link>
      <guid>https://forem.com/biplov/how-to-deploy-a-django-application-to-heroku-27nd</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Heroku is a cloud platform as a service(PaaS) that facilitates the deployment of web applications that supports several programming languages, including Python.&lt;br&gt;
So let's look at how we can deploy a Django application to Heroku easily in no time.&lt;/p&gt;
&lt;h1&gt;
  
  
  Getting Started
&lt;/h1&gt;

&lt;p&gt;The first thing you need to do is to create an account on heroku. You can create one from &lt;a href="https://signup.heroku.com/"&gt;here&lt;/a&gt;. Once you have created an account you need to install the &lt;a href="https://devcenter.heroku.com/articles/getting-started-with-python#set-up"&gt;Heroku Command Line Interface (CLI)&lt;/a&gt; that will be used manage and scale your applications, view your application logs, and run your application locally. You also need to have &lt;a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git"&gt;git&lt;/a&gt; installed on your machine.&lt;/p&gt;

&lt;p&gt;After the Heroku CLI is installed, open your terminal and log in to your heroku account using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ heroku login
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Managing the Application
&lt;/h1&gt;

&lt;p&gt;Now CD into your project folder. We need to add a few files to be able to deploy the app in heroku. The first file you need is a &lt;code&gt;requirements.txt&lt;/code&gt; file. If you have your virtual environment setup and active you can just type the following command on terminal to create your requirements file.&lt;br&gt;
&lt;/p&gt;

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



&lt;p&gt;Or you can manually list all dependencies on the &lt;code&gt;requirements.txt&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;The next thing Heroku web applications require is a &lt;code&gt;Procfile&lt;/code&gt;. Inside your project root folder, create a new file called &lt;code&gt;Procfile&lt;/code&gt; and add the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;web: gunicorn myproject.wsgi
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You need to change &lt;code&gt;my-application&lt;/code&gt; with the name of your Django project.&lt;/p&gt;

&lt;p&gt;Now you need to install something called Gunicorn. If you want to know more about Gunicorn you can follow this &lt;a href="https://devcenter.heroku.com/articles/python-gunicorn"&gt;link&lt;/a&gt;. Use the following command to install Gunicorn:&lt;br&gt;
&lt;/p&gt;

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



&lt;p&gt;Add gunicorn to your requirements.txt file as well.&lt;/p&gt;

&lt;p&gt;In addition you can also add a &lt;code&gt;runtime.txt&lt;/code&gt; file to your app’s root directory that declares the exact version number to use. For example, you can create a new file &lt;code&gt;runtime.txt&lt;/code&gt; and add the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python-3.7.2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  &lt;code&gt;settings.py&lt;/code&gt; changes
&lt;/h1&gt;

&lt;p&gt;Now you need to make some changes to your &lt;code&gt;settings.py&lt;/code&gt; file. The first thing to do is install &lt;code&gt;django-heroku&lt;/code&gt;. It is a package that automatically configures your Django application to work on Heroku.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip install django-heroku
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Be sure to add django-heroku to your requirements.txt file as well.&lt;/p&gt;

&lt;p&gt;Now, add the following statement to the top of &lt;code&gt;settings.py&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import django_heroku
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then add the following to the bottom of &lt;code&gt;settings.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Activate Django-Heroku.
django_heroku.settings(locals())
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Creating heroku app
&lt;/h1&gt;

&lt;p&gt;Now we will create a new heroku app. Type the following command on your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ heroku create my-app
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Change &lt;code&gt;my-app&lt;/code&gt; with your app name. It should be unique and not taken by anyone. Heroku will inform you if the name already exists.&lt;/p&gt;

&lt;p&gt;This command will create your heroku app with the name you provided. Now you can visit your heroku dashboard on your browser to see your app. You can also see the default page of your application by using the link in the terminal. The link looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://my-app.herokuapp.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Deploying the Django project
&lt;/h1&gt;

&lt;p&gt;We will use &lt;a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git"&gt;git&lt;/a&gt; to deploy our project to heroku. CD to your project root folder and initialize  the git using following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can add &lt;code&gt;.gitignore&lt;/code&gt; file to your project. You can visit &lt;a href="https://gitignore.io/"&gt;.gitignore.io&lt;/a&gt; to create &lt;code&gt;.gitignore&lt;/code&gt; file for your project&lt;br&gt;
Now add and commit the files to git:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git add --all
$ git commit -m 'initial commit'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Before you can push your project, you need to set your remote to heroku.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ heroku git:remote -a my-app
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;my-app&lt;/code&gt; with your app name.&lt;br&gt;
Now, you can push your project to heroku:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git push heroku master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then, migrate the database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ heroku run python manage.py migrate

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Congratulations!! The deployment is complete. Your project is now live on heroku.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;So, we deployed our project to heroku with not-so-good-looking domain name. Well, we can change that too. Heroku allows you to add a custom domain to your application. You can go through the &lt;a href="https://devcenter.heroku.com/articles/getting-started-with-python"&gt;Heroku Python docs&lt;/a&gt; for more information.&lt;/p&gt;

</description>
      <category>django</category>
      <category>heroku</category>
      <category>python</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Function-Based Views Vs Class-Based Views - Django </title>
      <dc:creator>Biplov</dc:creator>
      <pubDate>Sat, 28 Mar 2020 13:48:49 +0000</pubDate>
      <link>https://forem.com/biplov/function-based-views-vs-class-based-views-django-20ak</link>
      <guid>https://forem.com/biplov/function-based-views-vs-class-based-views-django-20ak</guid>
      <description>&lt;p&gt;A view is a place where you put the logic of the application. The Views are used to perform activities like fetching objects from the database, modifying those objects if needed, rendering forms and so on.&lt;/p&gt;

&lt;p&gt;The Django official documentation describes views as:&lt;br&gt;
"A view function, or view for short, is a Python function that takes a Web request and returns a Web response. This response can be the HTML contents of a Web page, or a redirect, or a 404 error, or an XML document, or an image . . . or anything, really. The view itself contains whatever arbitrary logic is necessary to return that response. "&lt;/p&gt;

&lt;p&gt;In the earlier days of Django there was only the function based views. They were easy to implement and very useful, but while working on a large project, the views were often crowded with similar functions. This was one of the reasons for the creation of class based views.&lt;/p&gt;
&lt;h1&gt;
  
  
  Function Based Views
&lt;/h1&gt;

&lt;p&gt;Function based views are the views in Django that are defined by functions. These python functions take a web request and returns a web response.&lt;br&gt;
 Function based views are most of the time based on 'What you see is what you get approach'. This is because all the logic of the view must be included.&lt;/p&gt;

&lt;p&gt;The biggest disadvantage of this approach is the length and repetition of codes. Writing a same block of code over and over is never a good practice.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;example_fbv&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;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Item&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="nb"&gt;all&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="s"&gt;'items'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;item&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;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="s"&gt;'app/index.html'&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;This example of FBVs is easy to implement and understand, but if it was a part of a larger Django project we would see a lot of similar functions. This causes code repetition and views become long and hard to read.  &lt;/p&gt;

&lt;h1&gt;
  
  
  Class Based Views
&lt;/h1&gt;

&lt;p&gt;Class based views are Django views based on Python classes. As mentioned in the Django official documentation, 'class based views do not replace function-based views, but have certain differences and advantages when compared to function-based views'. CBVs are very easy to use in simple cases, but extending them with increasing project complexity becomes more and more difficult. &lt;/p&gt;

&lt;p&gt;Class based views may be easy to begin with but you need to understand Python classes along with Django views to master them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;example_cbv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;View&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;Item&lt;/span&gt;
    &lt;span class="n"&gt;template_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'app/index.html'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This class based view does the exact same thing as the function based view above. It makes code relatively shorter and reduce code duplication, but it makes code harder to understand due to implicit code flow.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;As stated earlier class based views do not replace function-based views and there is no right or wrong. Function based views can be a better choice in some cases, whereas class based views in another. It all depends on context and need of the project.&lt;/p&gt;

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