<?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: Showmik</title>
    <description>The latest articles on Forem by Showmik (@miskat).</description>
    <link>https://forem.com/miskat</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%2F674502%2Fd792c642-57c3-456f-b31f-fbddc89c16ef.png</url>
      <title>Forem: Showmik</title>
      <link>https://forem.com/miskat</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/miskat"/>
    <language>en</language>
    <item>
      <title>Django Rest API x Flutter</title>
      <dc:creator>Showmik</dc:creator>
      <pubDate>Tue, 26 Jul 2022 18:13:33 +0000</pubDate>
      <link>https://forem.com/miskat/django-rest-api-x-flutter-3346</link>
      <guid>https://forem.com/miskat/django-rest-api-x-flutter-3346</guid>
      <description>&lt;p&gt;It is amazing that two different technologies can work together. &lt;br&gt;
In this article we will find out how can we use django rest API in a flutter app. sound exiting? let's find out how...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;At first we will create rest api with django rest framework.&lt;/li&gt;
&lt;li&gt;with this two line we have created a django project along with an django app
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Django-admin startproject flutterApi .
Django-admin startapp api
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Now we have to install django rest framework
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install djangorestframework
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;after that add &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;'rest_framework' in &lt;/p&gt;

&lt;p&gt;flutterApi/settings.py&lt;br&gt;
 in your codebase&lt;/p&gt;
&lt;/blockquote&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%2Fta97znc0is0at2i249z7.png" 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%2Fta97znc0is0at2i249z7.png" alt="in settings.py" width="316" height="219"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now we have to create a model for our django database. This is a simple data model.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;api/models.py&lt;/p&gt;
&lt;/blockquote&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%2Fjbgjmhpn8hyidywbbqzq.png" 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%2Fjbgjmhpn8hyidywbbqzq.png" alt="Django model" width="696" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we will migrate the model by using these two lines&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;now the model is migrated.&lt;/p&gt;

&lt;p&gt;We will set the url setting for our api.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;flutterapi/urls.py we create the api designation&lt;/p&gt;
&lt;/blockquote&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%2Fn0s6epv5b15lechcmq2z.png" 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%2Fn0s6epv5b15lechcmq2z.png" alt=" " width="404" height="175"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;after that we crate a urls.py file in 'api' folder in your project structure&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%2F4prw3wcwricrl6vnw3g4.png" 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%2F4prw3wcwricrl6vnw3g4.png" alt=" " width="158" height="251"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In this file we will create the api get, post, update, delete urls.&lt;/li&gt;
&lt;/ul&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%2F6m5z525nlt9zxc3t9eq4.png" 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%2F6m5z525nlt9zxc3t9eq4.png" alt="url patterns" width="734" height="267"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After this we have to make the serializers for the api.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;crate serializers.py file like api/serializers.py&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;then write the code like this.&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%2F1jid9j6bl4fdk06hj7v2.png" 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%2F1jid9j6bl4fdk06hj7v2.png" alt="serializers" width="664" height="204"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's write the actual code for developing the api&lt;br&gt;
first go to api/views.py&lt;/p&gt;

&lt;p&gt;In here we will be writing the code.&lt;br&gt;
first import the models and serializers.&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%2Fumffatftfjhb5x0rssf5.png" 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%2Fumffatftfjhb5x0rssf5.png" alt="import" width="451" height="72"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code..&lt;br&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%2F82j0gawlv6c4py991r83.png" 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%2F82j0gawlv6c4py991r83.png" alt="view" width="571" height="373"&gt;&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%2Fd06ipsjl4gnbuibfdmn4.png" 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%2Fd06ipsjl4gnbuibfdmn4.png" alt="view" width="608" height="334"&gt;&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%2Ff0ynbtokvjwkjhuz9sr6.png" 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%2Ff0ynbtokvjwkjhuz9sr6.png" alt="view" width="758" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now register your model in api/admin.py file&lt;/li&gt;
&lt;/ul&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%2F44llgxp7zx75h7gutvnf.png" 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%2F44llgxp7zx75h7gutvnf.png" alt="admin.py" width="538" height="152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So we are done building the API! let's test it now&lt;br&gt;
first run the django server by writing below code in console&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;py manage.py runserver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you should see something like this &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%2Fkut0117jfxrtnxlz87by.png" 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%2Fkut0117jfxrtnxlz87by.png" alt="server" width="593" height="158"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;the server is at &lt;strong&gt;&lt;a href="http://127.0.0.1:8000/" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/&lt;/a&gt;&lt;/strong&gt;.hit it on your browser.&lt;/p&gt;

&lt;p&gt;at first you will see this error but do not panic.&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%2Fo7d2vdv688cicl1stn6s.png" 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%2Fo7d2vdv688cicl1stn6s.png" alt="error" width="800" height="249"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;just hit &lt;strong&gt;&lt;a href="http://127.0.0.1:8000/api" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/api&lt;/a&gt;&lt;/strong&gt; to see all possible urls.&lt;br&gt;
you should see something like this.&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%2Fn8gh35ktolsbcgz5l1ms.png" 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%2Fn8gh35ktolsbcgz5l1ms.png" alt="api" width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;before see the api data we need to add data in our database. which is the admin panel in django. one of the best things in djnago.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;use this for createing you user admin. Fill with name username, password and the hit enter. after this run the server again&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://127.0.0.1:8000/admin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;login with your user and password which you just created.&lt;/p&gt;

&lt;p&gt;after login you will see&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%2Ffwz76ien5jpgdrutau2r.png" 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%2Ffwz76ien5jpgdrutau2r.png" alt=" " width="670" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;click products and then click add.&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%2F4tnpc2ywo4btp2ksb5tu.png" 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%2F4tnpc2ywo4btp2ksb5tu.png" alt=" " width="800" height="289"&gt;&lt;/a&gt;&lt;br&gt;
fill this with some values. ad hit save.&lt;br&gt;
example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Product name: OnePlus Nord 2 5G 12GB/256GB

Price: 40000

Prdoduct link = https://www.pickaboo.com/oneplus-nord-2-5g-12gb-256gb.html

Image: https://azse77seaprodsa.blob.core.windows.net/b2b-dr-
pickaboocdn/media/catalog/product/cache/ad6eca43ef1a34982ffeb01940d91d5b/n/o/nord-2-5g-12gb-256gb-7-16-2022.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;after saving the data follow the api links.&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%2Fakq6k71mplbbufxm8ew2.png" 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%2Fakq6k71mplbbufxm8ew2.png" alt=" " width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;if we go to &lt;strong&gt;&lt;a href="http://127.0.0.1:8000/api/product-list/" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/api/product-list/&lt;/a&gt;&lt;/strong&gt; like the urls we should see the data as json format like this.&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%2Fmv7znzys17v5zl33lc8w.png" 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%2Fmv7znzys17v5zl33lc8w.png" alt=" " width="800" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So our rest api creating is done! Now we have to prepare the flutter part!&lt;/p&gt;

&lt;h2&gt;
  
  
  Flutter app
&lt;/h2&gt;

&lt;p&gt;For creating a flutter app we use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flutter create app_name
ex: flutter create django_rest_api_x_flutter 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in your flutter project pubspec.ymal file add these dependencies&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%2Fhwouvk5ww4d9elivtwzt.png" 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%2Fhwouvk5ww4d9elivtwzt.png" alt=" " width="579" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;I will use &lt;a href="https://pub.dev/packages/get" rel="noopener noreferrer"&gt;GetX &lt;/a&gt;state management to manage your data in more efficient way.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I also used &lt;a href="https://pub.dev/packages/flutter_staggered_grid_view" rel="noopener noreferrer"&gt;flutter_staggered_grid_view &lt;/a&gt; to use in my project. it is very efficient for making grids in flutter.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I am not going to explain the designing part of flutter. I will be explaining the modeling and http part in this blog.&lt;br&gt;
you can download or fork the project from here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Miskat-UL/GetX-rest-api-flutter" rel="noopener noreferrer"&gt;https://github.com/Miskat-UL/GetX-rest-api-flutter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;don't forget to give it a star!&lt;/p&gt;

&lt;p&gt;Now in your flutter project structure your files like this&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%2F715y7qw2a1ns7rnayqbt.png" 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%2F715y7qw2a1ns7rnayqbt.png" alt=" " width="275" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In remote_service.dart file we will be importing the http packages.&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%2F7xcjlkqg58agykf67yvf.png" 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%2F7xcjlkqg58agykf67yvf.png" alt=" " width="577" height="118"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;we have to use the http module as follows. &lt;br&gt;
for cors we used the django cors.but it is not a matter now.&lt;br&gt;
just use the origin as headers so that the browser can access xml requests.&lt;br&gt;
the code gose here.&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%2Flgrui6bs3tnu9mvioeog.png" 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%2Flgrui6bs3tnu9mvioeog.png" alt=" " width="695" height="491"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;in product_controller.dart we make the getx controller&lt;/li&gt;
&lt;/ul&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%2F492n1qmododnld03kh6r.png" 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%2F492n1qmododnld03kh6r.png" alt=" " width="695" height="518"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;we are almost done. fork the github project to learn more with the code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;after this run the flutter project from your ide or cmd.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;make sure to run your django server&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;the app should run properly and the final output is kind of this&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%2Fvo0l8jtbg9k69xl7v98r.png" 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%2Fvo0l8jtbg9k69xl7v98r.png" alt=" " width="261" height="525"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading the blog. I hope you learned something.&lt;br&gt;
give a like and share with your friends!&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>django</category>
      <category>djangorestapi</category>
      <category>python</category>
    </item>
    <item>
      <title>The 'else' Keyword in "for" loop</title>
      <dc:creator>Showmik</dc:creator>
      <pubDate>Tue, 27 Jul 2021 07:29:00 +0000</pubDate>
      <link>https://forem.com/miskat/the-else-keyword-in-for-loop-3e04</link>
      <guid>https://forem.com/miskat/the-else-keyword-in-for-loop-3e04</guid>
      <description>&lt;p&gt;So , many of you don't know that there is a 'else' statement in for loop basically in python.&lt;br&gt;
I know python is a amazing programming language and it has some amazing features too. So, today we will be learning about the 'else' keyword&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;sometime you would have to search a friend name from a list of dictionary, like:&lt;/p&gt;
&lt;/blockquote&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%2F83lxe3sya0nmn8i5ybyh.png" 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%2F83lxe3sya0nmn8i5ybyh.png" alt="Example - 1" width="491" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;so at this point we can use a FOR loop for searching my friend&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;in this case we will use a user input.&lt;br&gt;
So, now if user types friends name like: 'sadi'&lt;br&gt;
it will search the whole dictionary&lt;br&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%2Fchv44xupci0gqx1qrq7l.png" 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%2Fchv44xupci0gqx1qrq7l.png" alt="example-2" width="381" height="98"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;then it will print "friend found" in the console.&lt;/p&gt;

&lt;p&gt;at this moment if the user type a wrong name which is not in the list of dictionary like,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;enter your friends name: 'showmik'&lt;br&gt;
it will give you nothing in the console.&lt;br&gt;
so in this case we can use the else keyword.&lt;br&gt;
so, if we write the code like this,&lt;/p&gt;
&lt;/blockquote&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%2Fs4qwl0nm08k7wpuz7a5m.png" 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%2Fs4qwl0nm08k7wpuz7a5m.png" alt="example-3" width="334" height="127"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;this time if the user type wrong name which is not in the list. it will print 'friend not found' in the terminal&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But there is a problem using else keyword!&lt;br&gt;
and that is,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;now if the user type correct write name which matches the list, it will output something like this,&lt;/p&gt;
&lt;/blockquote&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%2Fz29y6m21l3cj2zqm6vn8.png" 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%2Fz29y6m21l3cj2zqm6vn8.png" alt="ex-4" width="295" height="53"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;because the 'else' will be run after the loop ends. that's why it is printing the statement what the 'else' provide. &lt;br&gt;
i.e, 'friend not found'&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;in this case we can use 'break' statement after the loop ends. it will false the else keyword&lt;br&gt;
like,&lt;/p&gt;
&lt;/blockquote&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%2Fuwgjfuykw5947e3jgk5t.png" 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%2Fuwgjfuykw5947e3jgk5t.png" alt="ex-5" width="371" height="138"&gt;&lt;/a&gt;&lt;br&gt;
in this time after user type the correct name , the only thing will be print is 'Friend found'&lt;br&gt;
for the 'break' statement the 'else' keyword will not be printed.&lt;/p&gt;

&lt;p&gt;source: Tofayel&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
