

{"id":60834,"date":"2019-08-26T18:40:28","date_gmt":"2019-08-26T13:10:28","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=60834"},"modified":"2021-06-21T12:19:23","modified_gmt":"2021-06-21T06:49:23","slug":"django-file-upload","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/django-file-upload\/","title":{"rendered":"How to Upload File in Django &#8211; Learn with Easy Steps in just 10 Mins!"},"content":{"rendered":"<p>We all have used social platforms like Instagram and Facebook. The one thing common in all is that users can upload images, videos on them. We upload our files on a server and then others view it. That is the whole concept of social media.<\/p>\n<p>So, how Django upload a file? We will be answering the same question in this article. The contents of this article are:<\/p>\n<ol>\n<li>How to upload file in Django.<\/li>\n<li>Configuring settings.<\/li>\n<li>A User Profile Application.<\/li>\n<\/ol>\n<p>So, let\u2019s get started.<\/p>\n<h3>File Upload in Django &#8211; Working<\/h3>\n<p>File uploading is just like any input from the user. <strong>For example &#8211;<\/strong> On Facebook, when you update your profile picture. You select a file from your device and the file is then uploaded to the Facebook server. The server stores the file and is then served when anyone visits your profile.<\/p>\n<p>You can say the file is the same as static content on your website. Now let\u2019s learn how to upload file in Django.<\/p>\n<p>File uploading and handling have many approaches in Django. We will use models to implement file upload in Django. We are using model forms in this example.<\/p>\n<h3>Configuring Settings<\/h3>\n<p>Before any file upload application, these settings are necessary. Open project\u2019s <strong>settings.py file<\/strong> and add these lines below the <strong>STATIC FILES<\/strong> settings.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">MEDIA_ROOT = os.path.join(BASE_DIR, 'media')\r\nMEDIA_URL = 'media\/'\r\n\r\n<\/pre>\n<p><strong>Code Display:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Configuring-Settings.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-68537 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Configuring-Settings.png\" alt=\"Configuring Settings - Django File Upload\" width=\"1600\" height=\"813\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Configuring-Settings.png 1600w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Configuring-Settings-150x76.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Configuring-Settings-300x152.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Configuring-Settings-768x390.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Configuring-Settings-1024x520.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Configuring-Settings-520x264.png 520w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/a><\/p>\n<p><strong>Understanding the Settings<\/strong><\/p>\n<h4>1. MEDIA_ROOT<\/h4>\n<p><strong>MEDIA_ROOT<\/strong> is an empty string by default. It takes in the absolute file path of a directory. We have used the same join functions in <em><strong>Django\u00a0<\/strong><strong>static files tutorial<\/strong><\/em> that\u00a0we have passed in the file path of media directory. This directory will store all the files a user uploads in Django.<\/p>\n<p>Although you can directly give the path as a string in MEDIA_ROOT. It has its own problems. That approach will raise errors when you upload the file in the production environment. Always try to use dynamic URLs which are relative to the project directory. Like we used join method in the above setting.<\/p>\n<h4>2. MEDIA_URL<\/h4>\n<p><strong>MEDIA_URL<\/strong> works the same way as STATIC_URL. This URL is used by Django instead of serving files with an absolute path. When Django will serve an uploaded file media it will be automatically added to the URL.<\/p>\n<p>Remember MEDIA_ROOT &amp; MEDIA_URL can have totally different values. The directory name is not required to be same. You can name MEDIA_URL anything.<\/p>\n<p style=\"text-align: left;\"><strong>Note:<\/strong><\/p>\n<p style=\"text-align: left;\">MEDIA_URL &amp; STATIC_URL should always have different values. Also, this goes for MEDIA_ROOT &amp; STATIC_ROOT settings too. It was common in the past to use media root to all server static files. With the experiences of developers, this approach has some serious security implications.<\/p>\n<p style=\"text-align: left;\">It is mandatory to have different values for media settings and static settings.<\/p>\n<h4>Make a Directory named Media<\/h4>\n<p>Now, make a directory named <strong>media<\/strong> at the project level.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Directory-named-media.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-68538\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Directory-named-media.png\" alt=\"Directory named media - Django File Upload\" width=\"249\" height=\"436\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Directory-named-media.png 249w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Directory-named-media-86x150.png 86w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Directory-named-media-171x300.png 171w\" sizes=\"auto, (max-width: 249px) 100vw, 249px\" \/><\/a><\/p>\n<p>Media directory exists at the same level as <strong>manage.py <\/strong>file.<\/p>\n<h3>A User Profile Application<\/h3>\n<p>Now, we will make an application which can store a user\u2019s profile in Django. This profile will have some basic information and a profile picture. We will also make a form to upload the picture. We will learn some important concepts of doing same in Django.<\/p>\n<h4>1. Make a New Application<\/h4>\n<p>Now, from your terminal, execute the command to make a new application.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; python manage.py startapp profile_maker<\/pre>\n<p><strong>Command Display:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/image2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-60986\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/image2.png\" alt=\"image2\" width=\"1214\" height=\"286\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/image2.png 1214w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/image2-150x35.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/image2-300x71.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/image2-768x181.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/image2-1024x241.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/image2-520x123.png 520w\" sizes=\"auto, (max-width: 1214px) 100vw, 1214px\" \/><\/a><\/p>\n<p>Now, install the new application in <strong>settings.py<\/strong> file.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/image10.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-60987\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/image10.png\" alt=\"image10\" width=\"1600\" height=\"813\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/image10.png 1600w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/image10-150x76.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/image10-300x152.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/image10-768x390.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/image10-1024x520.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/image10-520x264.png 520w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/a><\/p>\n<h4>2. Make Models<\/h4>\n<p>Now, paste this code in<strong> profile_maker\/models.py<\/strong> file.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">from django.db import models\r\n\r\n\r\nclass User_Profile(models.Model):\r\n    fname = models.CharField(max_length=200)\r\n    lname = models.CharField(max_length = 200)\r\n    technologies = models.CharField(max_length=500)\r\n    email = models.EmailField(default = None)\r\n    display_picture = models.FileField()\r\n\r\n    def __str__(self):\r\n        return self.fname<\/pre>\n<p><strong>Code Display:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Models.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-68539 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Models.png\" alt=\"Models - Django File Upload\" width=\"1600\" height=\"813\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Models.png 1600w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Models-150x76.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Models-300x152.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Models-768x390.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Models-1024x520.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Models-520x264.png 520w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/a><\/p>\n<p><strong>Understanding the Code:<\/strong><\/p>\n<p>We have made a simple model for a user profile. It has fields like <em>fname, lname, technologies, email, display_picture.\u00a0<\/em>We have also defined an<strong> __str__ function<\/strong>. This function will return the value of fname when we reference the object. The important field is <strong>display_picture<\/strong> field.<\/p>\n<p><strong>display_picture is a File Field.<\/strong> It should have been an image field. We use a file field to store files on the server. It will create a File object which has many built-in attributes and methods. When a user uploads a file in the file field, we are storing file object in database and store file in <strong>MEDIA_ROOT<\/strong>.<\/p>\n<p>A file object is mainly to associate a file with an object or profile. We will learn more about file object in the upcoming section.<\/p>\n<h4>3. Make Forms<\/h4>\n<p>Make a new forms.py file in your application. Inside <strong>profile_maker\/forms.py<\/strong> file, paste this code:<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">from django import forms\r\nfrom .models import User_Profile\r\n\r\n#DataFlair #File_Upload\r\nclass Profile_Form(forms.ModelForm):\r\n\r\n    class Meta:\r\n        model = User_Profile\r\n        fields = [\r\n        'fname',\r\n        'lname',\r\n        'technologies',\r\n        'email',\r\n        'display_picture'\r\n        ]<\/pre>\n<p><strong>Code Display:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Forms.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-68540 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Forms.png\" alt=\"Forms - Django File Upload\" width=\"1600\" height=\"813\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Forms.png 1600w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Forms-150x76.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Forms-300x152.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Forms-768x390.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Forms-1024x520.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Forms-520x264.png 520w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/a><\/p>\n<p><strong>Understanding the code:<\/strong><\/p>\n<p>Here we are using things called model forms. These forms are special and are very handy.<\/p>\n<h4>Model forms<\/h4>\n<p>The basic concept of model forms is that they derive their structure from models. Yes, that\u2019s right, we don\u2019t have to define a form and connect it with models. We can do that directly via model forms.<\/p>\n<p>Models forms are a subclass of forms. When we make a form using<strong> ModelForm<\/strong> class, we use<strong> META<\/strong> class. In META, there are two attributes required, they are:<\/p>\n<ul>\n<li><strong>model:<\/strong>\u00a0It takes in the name of the model. We have to import the<strong> User_Profile<\/strong> model for this. This attribute defines the model to render a form. This form object is then used to save the user data to be stored directly in a database.<\/li>\n<li><strong>fields:<\/strong>\u00a0It is a list of strings. This list will take the name of the fields in the model. This field defines input fields for a form. We specify the fields from models in this list. All the fields mentioned in this list will be used to create a form.<\/li>\n<\/ul>\n<p>That\u2019s all the information on model forms, we require for this tutorial.<\/p>\n<p>So basically, we will get a form with the fields defined in fields attribute of Form. It\u2019s a very common practice to use model forms but is not necessary.<\/p>\n<h4>4. Make\u00a0Views<\/h4>\n<p>Now, in <strong>profile_maker\/views.py<\/strong> file, paste this.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">from django.shortcuts import render\r\nfrom .forms import Profile_Form\r\nfrom .models import User_Profile\r\n\r\nIMAGE_FILE_TYPES = ['png', 'jpg', 'jpeg']\r\n\r\ndef create_profile(request):\r\n    form = Profile_Form()\r\n    if request.method == 'POST':\r\n        form = Profile_Form(request.POST, request.FILES)\r\n        if form.is_valid():\r\n            user_pr = form.save(commit=False)\r\n            user_pr.display_picture = request.FILES['display_picture']\r\n            file_type = user_pr.display_picture.url.split('.')[-1]\r\n            file_type = file_type.lower()\r\n            if file_type not in IMAGE_FILE_TYPES:\r\nreturn render(request, 'profile_maker\/error.html')\r\n            user_pr.save()\r\n            return render(request, 'profile_maker\/details.html', {'user_pr': user_pr})\r\n    context = {\"form\": form,}\r\n    return render(request, 'profile_maker\/create.html', context)<\/pre>\n<p><strong>Code Display:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/views.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-68541 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/views.png\" alt=\"make views\" width=\"1600\" height=\"813\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/views.png 1600w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/views-150x76.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/views-300x152.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/views-768x390.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/views-1024x520.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/views-520x264.png 520w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/a><br \/>\nThe views are simple to understand. We have imported the models and forms in this view file. Then we have defined a list <strong>IMAGE_FILE_TYPES<\/strong>. We use it to check the type of file.<\/p>\n<p>Then our function definition starts.<\/p>\n<p>In this function, we have defined a form object. It will render a form. Then we are using form validation to clean our form data. This function returns True or False. If the form has valid data, we can store the data locally. Then we are extracting the file type uploaded by the user.<\/p>\n<p>Since we are using file field, we have multiple attributes. The file URL contains the filetype after the \u2018.\u2019. We have used a basic string function <strong>split()<\/strong> for this purpose.<\/p>\n<p>The split() will split the string into parts where <strong>\u2018.\u2019<\/strong> is present. You can get more on this in <em><strong>basic Python functions<\/strong><\/em>. In the next line, we are making it a lower type string. Then we are performing a check whether the file is an image file or not. We can skip this part if we use the image field.<\/p>\n<p>So, if the file is not an image file, it will render <strong>error.html.<\/strong><\/p>\n<p>Otherwise, it will render <strong>details.html<\/strong>, showing the details we just filled. If the form is rendered for the first time, it will render <strong>create.html<\/strong>. Now, we understood the view function. Let\u2019s make our templates.<\/p>\n<h4>5. Create Templates<\/h4>\n<p>Now, again make a templates folder. The directory pattern will be <strong>profile_maker\/templates\/profile_maker<\/strong>. Remember to make two directories. First is templates and then the profile_maker directory inside it.<\/p>\n<p>Now, make a new file in <strong>profile_maker\/templates\/profile_maker<\/strong> named <strong>create.html.<\/strong><\/p>\n<p>Paste this code in create.html.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n    &lt;head&gt;\r\n        &lt;title&gt;Make Profile&lt;\/title&gt;\r\n        &lt;link rel=\"stylesheet\" href=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.7\/css\/bootstrap.min.css\" integrity=\"sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz\/K68vbdEjh4u\" crossorigin=\"anonymous\"&gt;\r\n    &lt;\/head&gt;\r\n    &lt;body&gt;\r\n\r\n        &lt;center&gt;\r\n            &lt;div class=\"jumbotron\"&gt;\r\n                &lt;h1 class=\"display-4\"&gt;DataFlair Django File Uploading&lt;\/h1&gt;\r\n                        {% block replace %}\r\n                &lt;p class=\"lead\"&gt;To make a user profile and upload the files fill this form&lt;\/p&gt;\r\n                &lt;hr class=\"my-4\"&gt;\r\n                &lt;form method=\"POST\" enctype=\"multipart\/form-data\"&gt;\r\n                    &lt;!-- Very Important csrf Token --&gt;\r\n                    {% csrf_token %}\r\n                    &lt;table&gt;\r\n                        {{ form.as_table }}\r\n                    &lt;\/table&gt;\r\n                    &lt;input type=\"submit\" class=\"btn btn-primary btn-lg\" name=\"register\"&gt;\r\n            &lt;\/div&gt;\r\n        &lt;\/center&gt;\r\n        {% endblock %}\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><strong>Code Display:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Templates.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-68542 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Templates.png\" alt=\"Create Templates\" width=\"1600\" height=\"813\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Templates.png 1600w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Templates-150x76.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Templates-300x152.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Templates-768x390.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Templates-1024x520.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Templates-520x264.png 520w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/a><\/p>\n<p>It\u2019s a simple template rendering the form. We have also used some bootstrap. You can check out our <em><strong>Django\u00a0bootstrap tutorial<\/strong><\/em> for the same. The important part is the form attribute <strong>enctype<\/strong>. This attribute allows us to send the files with our data.<\/p>\n<h4>request.FILES dictionary<\/h4>\n<p>When any file is uploaded in Django it becomes a part of the request object. More specifically, it can be accessed with the<strong> request.FILES object<\/strong>. It is a dictionary and has a key for each file uploaded. You can access data from the uploaded file via this dictionary.<\/p>\n<p>Although, we have an image file and we have not used any API to access its data. Now, make a new file named<strong> details.html<\/strong> in the same directory. Paste this code in it.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">{% extends 'profile_maker\/create.html' %}\r\n{% block replace %}\r\n&lt;CENTER&gt;\r\n&lt;div class=\"jumbotron\"&gt;\r\n  &lt;h1 class=\"display-4\"&gt;Welcome to DataFlair&lt;br&gt;Hello {{ user_pr.fname }}&lt;\/h1&gt;\r\n  &lt;p class=\"lead\"&gt;its an awesome profile picture&lt;\/p&gt;\r\n  &lt;hr class=\"my-4\"&gt;\r\n  &lt;img src=\"{{ user_pr.display_picture.url }}\" class=\"image_responsive\" height=\"100px\" width=\"100px\"&gt;\r\n  &lt;p&gt;\r\n    {{ user_pr.display_picture.url }}&lt;BR&gt;\r\n   You have learned some awesome technologies like {{ user_pr.technologies }}&lt;\/p&gt;\r\n&lt;\/div&gt;\r\n&lt;\/CENTER&gt;\r\n{% endblock %}<\/pre>\n<p><strong>Code Display:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/detailhtml.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-60997\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/detailhtml.png\" alt=\"detailhtml\" width=\"1600\" height=\"813\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/detailhtml.png 1600w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/detailhtml-150x76.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/detailhtml-300x152.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/detailhtml-768x390.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/detailhtml-1024x520.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/detailhtml-520x264.png 520w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/a><\/p>\n<p>This template is used to display the image we just uploaded. We are using the <strong>{{ user_pr.display_picture.url }}<\/strong> in image src. Then make another file in the same directory. Its name is <strong>error.html<\/strong>. Paste this code in it.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">{% extends 'profile_maker\/create.html' %}\r\n{% block replace %}\r\n&lt;CENTER&gt;\r\n    &lt;h1 style = 'border: 5px red solid;'&gt; hello, you have uploaded the wrong file type.&lt;\/h1&gt;\r\n&lt;\/CENTER&gt;\r\n{% endblock %}\r\n\r\n<\/pre>\n<p><strong>Code Display:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/error-html.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-68543 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/error-html.png\" alt=\"error.html - Django File Upload\" width=\"1600\" height=\"813\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/error-html.png 1600w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/error-html-150x76.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/error-html-300x152.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/error-html-768x390.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/error-html-1024x520.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/error-html-520x264.png 520w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/a><\/p>\n<p>It will be rendered when the user uploaded a non-image file. It is defined in the view function.<\/p>\n<h4>6. Configure URLs<\/h4>\n<p>We have made all the files. Open your main urls.py file. In this file, paste this code:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">from django.contrib import admin\r\nfrom django.urls import path, include\r\n\r\nurlpatterns = [\r\n    path('admin\/', admin.site.urls),\r\n    path('upload\/', include('profile_maker.urls')),\r\n]<\/pre>\n<p><strong>Code Display:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Configuring-urls.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-68544 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Configuring-urls.png\" alt=\"Configuring URLs\" width=\"1600\" height=\"813\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Configuring-urls.png 1600w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Configuring-urls-150x76.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Configuring-urls-300x152.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Configuring-urls-768x390.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Configuring-urls-1024x520.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Configuring-urls-520x264.png 520w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/a><\/p>\n<p>Then make a new file in<strong> profile_maker\/<\/strong> directory named<strong> urls.py<\/strong>. Paste this code in that <strong>profile_,maker\/urls.py<\/strong> file.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">from django.urls import path\r\nfrom . import views\r\nfrom myproject import settings\r\nfrom django.conf.urls.static import static\r\n\r\nurlpatterns = [\r\n    path('', views.create_profile, name = 'create'),\r\n]\r\n\r\nif settings.DEBUG:\r\n    urlpatterns += static(settings.STATIC_URL, document_root = settings.STATIC_ROOT)\r\n    urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)<\/pre>\n<p><strong>Code Display:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/profile-makers-urlspy.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-68545 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/profile-makers-urlspy.png\" alt=\"profile_maker\/urls.py\" width=\"1600\" height=\"813\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/profile-makers-urlspy.png 1600w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/profile-makers-urlspy-150x76.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/profile-makers-urlspy-300x152.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/profile-makers-urlspy-768x390.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/profile-makers-urlspy-1024x520.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/profile-makers-urlspy-520x264.png 520w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/a><\/p>\n<p>Concentrate on the if section. We are using these settings only when the project is in debug mode. Then we have added these patterns to the <strong>urlpatterns variable<\/strong>. These patterns are referred when a media file is requested. These settings are important when serving the file uploaded by the user.<\/p>\n<p>Although, these are only used when you are developing a website. The server settings are different for servers.<\/p>\n<h4>7. Test the Application<\/h4>\n<p>Now, we are ready to test our app. Search in URL bar: <em>localhost:8000\/upload<\/em><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/django-file-upload.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61007\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/django-file-upload.png\" alt=\"django file upload\" width=\"1600\" height=\"829\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/django-file-upload.png 1600w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/django-file-upload-150x78.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/django-file-upload-300x155.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/django-file-upload-768x398.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/django-file-upload-1024x531.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/django-file-upload-520x269.png 520w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/a><\/p>\n<p>When you submit the form.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Form-submission-testing.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-68546 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Form-submission-testing.png\" alt=\"Form submission for testing - Django File Upload\" width=\"1600\" height=\"858\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Form-submission-testing.png 1600w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Form-submission-testing-150x80.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Form-submission-testing-300x161.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Form-submission-testing-768x412.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Form-submission-testing-1024x549.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Form-submission-testing-520x279.png 520w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/a><\/p>\n<p>This is the details page. Since there was no error, we get this output. You can also see that file in the media folder.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/media-folder.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-61010\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/media-folder.png\" alt=\"media folder\" width=\"1600\" height=\"813\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/media-folder.png 1600w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/media-folder-150x76.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/media-folder-300x152.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/media-folder-768x390.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/media-folder-1024x520.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/06\/media-folder-520x264.png 520w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/a><\/p>\n<p>I have already uploaded some images.<\/p>\n<p><strong>Note:<\/strong><\/p>\n<p><em>You can upload image or files with the same name as we expect users to upload files with the same name. Django automatically generates a new name for the files uploaded. As you can see all the files have some code in their name. that is automatically generated by Django.<\/em><\/p>\n<p>If you upload any other file, it will generate this error page.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Error-page.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-68547 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Error-page.png\" alt=\"Error page - Django File Upload\" width=\"1600\" height=\"858\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Error-page.png 1600w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Error-page-150x80.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Error-page-300x161.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Error-page-768x412.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Error-page-1024x549.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Error-page-520x279.png 520w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>Here we conclude our tutorial on how to upload file in Django. Files are handled in many possible ways in Django. This is what makes Django an awesome framework. It enables us to read files and apply machine learning or any backend process.<\/p>\n<p>Files have their own properties. What we discussed is one of the ways we can upload files in Django and render them. The process works fine for most but you can modify it according to the use case.<\/p>\n<p>Hope you liked our article. Ask your queries and clear your doubts through the comment section.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We all have used social platforms like Instagram and Facebook. The one thing common in all is that users can upload images, videos on them. We upload our files on a server and then&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":68563,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19149],"tags":[20962,20959,20961,20960,20326],"class_list":["post-60834","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-django","tag-create-html","tag-django-file-upload","tag-profile_maker","tag-request-files-dictionary","tag-user-profile-application"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Upload File in Django - Learn with Easy Steps in just 10 Mins! - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn to upload file in Django by using model forms, making views, creating templates and configuring URLs with the help of code &amp; implementation examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/django-file-upload\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Upload File in Django - Learn with Easy Steps in just 10 Mins! - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn to upload file in Django by using model forms, making views, creating templates and configuring URLs with the help of code &amp; implementation examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/django-file-upload\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-26T13:10:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-06-21T06:49:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/how-to-upload-file-in-Django.png\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"421\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Upload File in Django - Learn with Easy Steps in just 10 Mins! - DataFlair","description":"Learn to upload file in Django by using model forms, making views, creating templates and configuring URLs with the help of code & implementation examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/django-file-upload\/","og_locale":"en_US","og_type":"article","og_title":"How to Upload File in Django - Learn with Easy Steps in just 10 Mins! - DataFlair","og_description":"Learn to upload file in Django by using model forms, making views, creating templates and configuring URLs with the help of code & implementation examples.","og_url":"https:\/\/data-flair.training\/blogs\/django-file-upload\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2019-08-26T13:10:28+00:00","article_modified_time":"2021-06-21T06:49:23+00:00","og_image":[{"width":802,"height":421,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/how-to-upload-file-in-Django.png","type":"image\/png"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/django-file-upload\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/django-file-upload\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"How to Upload File in Django &#8211; Learn with Easy Steps in just 10 Mins!","datePublished":"2019-08-26T13:10:28+00:00","dateModified":"2021-06-21T06:49:23+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/django-file-upload\/"},"wordCount":1809,"commentCount":19,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/django-file-upload\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/how-to-upload-file-in-Django.png","keywords":["create.html","Django File Upload","profile_maker\/","request.FILES dictionary","user profile application"],"articleSection":["Django Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/django-file-upload\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/django-file-upload\/","url":"https:\/\/data-flair.training\/blogs\/django-file-upload\/","name":"How to Upload File in Django - Learn with Easy Steps in just 10 Mins! - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/django-file-upload\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/django-file-upload\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/how-to-upload-file-in-Django.png","datePublished":"2019-08-26T13:10:28+00:00","dateModified":"2021-06-21T06:49:23+00:00","description":"Learn to upload file in Django by using model forms, making views, creating templates and configuring URLs with the help of code & implementation examples.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/django-file-upload\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/django-file-upload\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/django-file-upload\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/how-to-upload-file-in-Django.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/how-to-upload-file-in-Django.png","width":802,"height":421,"caption":"how to upload file in Django"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/django-file-upload\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Django Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/django\/"},{"@type":"ListItem","position":3,"name":"How to Upload File in Django &#8211; Learn with Easy Steps in just 10 Mins!"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/60834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=60834"}],"version-history":[{"count":12,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/60834\/revisions"}],"predecessor-version":[{"id":97474,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/60834\/revisions\/97474"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/68563"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=60834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=60834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=60834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}