<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vikashvar Rajan on Medium]]></title>
        <description><![CDATA[Stories by Vikashvar Rajan on Medium]]></description>
        <link>https://medium.com/@vikashvarrajan19?source=rss-4c0a94a8e21f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*HrGQyMJYTUsbF12f</url>
            <title>Stories by Vikashvar Rajan on Medium</title>
            <link>https://medium.com/@vikashvarrajan19?source=rss-4c0a94a8e21f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 13:01:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vikashvarrajan19/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Mixpanel with Django]]></title>
            <link>https://python.plainenglish.io/mixpanel-with-django-f9da40a59675?source=rss-4c0a94a8e21f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9da40a59675</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Vikashvar Rajan]]></dc:creator>
            <pubDate>Sun, 24 Dec 2023 17:57:16 GMT</pubDate>
            <atom:updated>2023-12-26T05:03:19.736Z</atom:updated>
            <content:encoded><![CDATA[<p>Imagine you are a product manager and we have to check whether a newly implemented feature in your product is consumed efficiently by the users or not?Or you have to track the number of active users of the particular feature.At the same time,how will you keep track of each and every user of the particular feature.Here,we need a tool to track the events that occurs in our product every time it is used so that we can have the analytics of our product which helps to improve the quality of our product.Here,the show stealer <strong>MIXPANEL</strong> comes into the picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wdOFq9sjd388-RlUECDTHg.png" /></figure><p><strong><em>What is mixpanel?</em></strong></p><p>Mixpanel is an analysing tool used to keep track of the activities that are performed by the users in your digital product.Any button clicks or events that are to be tracked can be tracked using mixpanel.The possibility of creating custom fields helps us to track and get all the necessary information from the event handle thus providing more data for analysis.</p><p><strong><em>Mixpanel Account</em></strong></p><p>Create a mixpanel account ,go to mixpanel’s official website <a href="https://mixpanel.com/">https://mixpanel.com/</a> ,fill in the required details ,verify the email and complete the sign in process.This is a simple process and will not ask any payment kinda details.Once,your account is successfully created, you can create projects and start using mixpanel features.</p><p><strong><em>Integrating Mixpanel with Django.</em></strong></p><p>To start working with mixpanel in your Django Application,you should install the mixpanel library,</p><p>&gt;&gt;<strong><em>pip3 install mixpanel</em></strong><br>Now,in the <strong><em>settings.py</em></strong> file,enter the project token so that a connection between your Django application and the mixpanel site takes place(optional!you can do in the view method as well.But in bigger projects you shouldn’t repeatively writing it in all views,thus declare it in the settings.py file).This step is very important to track the events.(This is not for production).In production,this configuration will be made in .env file</p><p><strong>Getting mixpanel token:</strong></p><p>Mixpanel token is essential for integrating Mixpanel with your project.So our first job is to get the token and add it to the settings.py file( or in view) in our project. Now,where do we find the token .A unique token will be created for each and every projects that you are creating in mixpanel.Now,create a new project in mixpanel so that we can use it.</p><p><strong>Create a new Project:</strong></p><p>To create a new project,go to <strong>organizaton settings </strong>and you can find <strong>projects</strong> in the left-side menu.Click on the menu and you will be navigated to a paged where all your projects will be available.Initially,the page will be empty as projects are yet to be added</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZrrazCPpnS4cwnuKLuabMg.png" /></figure><p>Now,create on the <strong>create project</strong> Option in the top right and create a project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yc8o61Jle_GtTAf-pMGdPw.png" /></figure><p>Now a project has been created.To get the project Token,click on the project Name.The details of the project will be loaded.There you can find the project token.</p><p>Path:</p><p><strong>&gt;&gt;organization settings &gt;&gt; projects &gt;&gt; create projects</strong></p><p>Now,all the configurations has been done.To practically apply and test it.We create a simple registartion page with few buttons to track the events occured in the page.<br>Now ,create a Django project:</p><p><strong>&gt;&gt;django-admin startproject Mixpanel</strong></p><p>create an app inside the project:</p><p><strong>&gt;&gt;python manage.py startapp home</strong></p><p>Create a template folder and create a html page where we are gonna have the buttons and track the events.</p><p><strong>Quick grasp to create the setup:</strong></p><p>add the create app to the installed apps.</p><p>create a view where we read the code to track the events.Let the view return a html page where the buttons will be available.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*sPzcX95JEla5lavjad3kbw.png" /></figure><p>Create a urls.py file in the app to map the view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*E7DA5GQbYHqin1-hBw90bw.png" /></figure><p>add the app’s path to the main project by including the app.</p><p>Now the stage is set.Let’s play with mixpanel!</p><p>Now,let us first track a simple form action using mixpanel.</p><p>Our view function will be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*ILcOYqsdxZC8SCYfdDlKLA.png" /></figure><p>Here the home page is to load the html page where the user is gonna enter the details.Let’s keep the home page simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*8GyyxO-8li9DoQ7VlNP2lw.png" /></figure><p>while submitting the form,the action will be handled in tracks view.<br>Firstly,we are storing the values from the forms in separate variables.These varaibles will be the properties of the event(custom events).There are few default properties will also be tracked in the mixpanel.<br><em>To initialize the event,use this api:</em></p><p><strong>Mixpanel(‘ur project token’) </strong>and store it in a variable.Now,using this variable, call the track api.</p><p><strong>mixpanel.track():</strong></p><p>This track method will take <strong><em>3 arguments(2 mandatory args and a optional one).</em></strong>The first arg will be the id of the event, the second will be the name of the event and the optional one will be the <strong>custom parameters</strong>.</p><p>when .track() is called, the event will be triggered and the details will be sent to the mixpanel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bdlmDLxgS9O4CHY_RnBeMg.png" /></figure><p>The tracked event will be stored in the <strong>mixpanel events board</strong>.In the above figure,you can find details of the events.It is that simple.We have successfullly integrated mikxpanel and tracked the events.</p><p><strong>A walk through to the event details page:</strong></p><p>In the mixpanel home page,click on the starter board and you will be naviagated to the below page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5yu_xAdVsORTYtE1j0edMw.png" /></figure><p>Here,click on the card which you want to look into</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZGt2N5toLJDwVJps6XNqFA.png" /></figure><p>There ,click on the users to see the diff users who tracked the event and to get the details of the events click on the view events.The event page will look like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u0ZO9CgxmM_wlAY3FHSo5g.png" /></figure><p>the time of the event occured is also tarcked with geological locaation as well.</p><p>Features:</p><p>Most of the useful features are paid services and few of the above mentioned features are free.Here are few features offered by mixpanel,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*izBdFuoq3eSrxD13_1HB2Q.png" /></figure><p>The insight report is one of the useful free feature.We can take a clear view of all the events and distingush them using this insight which gives clear insight of the events.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*F--oAwpBFytluAxme_t-GA.png" /></figure><p>This deep insight will give us a better understanding of the event and the numbers as all.<br>Flow report is one of the free feature as well.1</p><p>While coming to the advanced features(upgraded),funnel report and retention reports falls under this upgrade user handle.<br>One more interesting feature available in mixpanel is the filter option.we can filter the events in the n number of categories.</p><p>Various visualization options such as charts , graphs helps us to analyse the events data more precisely.This option is one of the free key free options</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kIhuCGnMj1T_d0N_EjECDw.png" /></figure><p>Time period wise data is also a key feature which helps the user to analyse the data in different time stamps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*CE3bgY2S8BGU2Ga8dEC8HA.png" /></figure><p>Apart from the above-mentioned features,there are a lot of other features which are very helpful in analyses. Exploring them by using them is the only most faascinating way to get more understanding. Hope, this blog depicts a clear insight about mixpanel. Keep exploring!! happy learning!Thanks for Reading!</p><h3><a href="https://plainenglish.io/">PlainEnglish.io</a> 🚀</h3><p><em>Thank you for being a part of the In Plain English community! Before you go:</em></p><ul><li><em>Be sure to </em><strong><em>clap</em></strong><em> and </em><strong><em>follow</em></strong><em> the writer</em><strong>️</strong></li><li><em>Learn how you can also </em><a href="https://plainenglish.io/blog/how-to-write-for-in-plain-english"><strong><em>write for In Plain English</em></strong></a><em>️</em></li><li><em>Follow us: </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>X</em></strong></a><strong><em> | </em></strong><a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><strong><em> | </em></strong><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><strong><em> | </em></strong><a href="https://discord.gg/in-plain-english-709094664682340443"><strong><em>Discord</em></strong></a><strong><em> | </em></strong><a href="https://newsletter.plainenglish.io/"><strong><em>Newsletter</em></strong></a></li><li><em>Visit our other platforms: </em><a href="https://stackademic.com/"><strong><em>Stackademic</em></strong></a><strong><em> | </em></strong><a href="https://cofeed.app/"><strong><em>CoFeed</em></strong></a><strong><em> | </em></strong><a href="https://venturemagazine.net/"><strong><em>Venture</em></strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9da40a59675" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/mixpanel-with-django-f9da40a59675">Mixpanel with Django</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django-Database relationship(MySQL configuration)]]></title>
            <link>https://python.plainenglish.io/django-database-relationship-mysql-configuration-8849c98e72b?source=rss-4c0a94a8e21f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8849c98e72b</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Vikashvar Rajan]]></dc:creator>
            <pubDate>Wed, 30 Aug 2023 19:22:59 GMT</pubDate>
            <atom:updated>2023-08-31T10:47:54.524Z</atom:updated>
            <content:encoded><![CDATA[<p>While developing a website ,we need to store app data and user information in a safe and secure place and it should be easily accessible by the webapp so that the <strong><em>data can be stored and retrieved</em></strong> at a faster rate and the user can experience a smooth web service.Speaking about the data,where will be the data stored?How can a connection be established between a data storage area and the webapp?How can the web app perform <strong><em>read and write operation</em></strong> on a remote database?You can find the answers for all the above questions in this informative blog.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*6B30WpvaMQEcI_rJ.png" /></figure><p>Django is a powerful web develepment framework and robust web apps can be developed using Django.Talking about data,Data will be stored in the databases snd we should make necessary <strong><em>configurations with the remote database</em></strong> and webapp to store and retrieve data for app functionalities.Fortunately,we have Django and we have <strong><em>settings.py in the main project folder </em></strong>to store configuration information of the webapp.Lets see how to configure and make queries from Django.</p><h3><strong>CONTENT:</strong></h3><p>1.sql connection</p><p>2.models</p><p>3.migrations</p><p>4.ORM(Object Related Mapping)</p><h3><strong><em>Mysql Database connection:-</em></strong></h3><p>First of all,to conenct with a database, go to <strong><em>settings.py</em></strong> and we can find a variable called <strong><em>DATABASE</em></strong> where the database configuration will be given</p><p>The default configuration when a new django app is created is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*4lMS_0ARf7Rar3ci_RaEUw.png" /></figure><p>Here,<strong><em>SQLite </em></strong>is the default database.This is because SQLite is readily included in Python so that you need not install SQLite.Now,a question may arise.<strong><em>Why we should go for MySQL database as we already have SQLite connection</em></strong>.The answer is simple.The SQLite is suitable for smaller databases and is not suitable for multiple user access.MySQL and other databases like MongoDb can handle <strong><em>multiple user access</em></strong> and the size will not be a problem.This is why,it is insisted to change your database.But,it depends on your <strong><em>app’s need</em></strong>.If you are not going to use Database much for your app,It is better to stay with SQLite.In commercial apps,we can’t go for SQLite so we configure other Databases.Now,what are all the changes we should do in the database variable so that the connection can be established.</p><p>First of all,create a Database in the SQL workbench</p><p>&gt;&gt;<strong><em>create database Database</em></strong></p><p>Now,in the settings.py file,add the following snippet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*xJUrGzUBHMBziNM3Gi7UhA.png" /></figure><p>In this default <strong><em>settings</em></strong>,firstly,we have to mention the <strong><em>database engine</em></strong> that we are going to use.In our case,it is mysql.So we add <strong><em>django.db.backends.mysql</em></strong></p><p>In the subsequent lines,give the <strong><em>db name</em></strong> in the name key.In the host key,give the<strong><em> host url</em></strong>.Here,i have given localhost as i have my database in my system and if you are hosting your database in any web hosting platforms,add the url of your <strong><em>db_host</em></strong>.A host url will be provided by the web host service provider.In the port key,give the <strong><em>port number 3306</em></strong> as it is the default port for db connection,In the user key,give the username of the database.It can either be the root user of the Database or the other admins that are created by the root user.In the password key,give the password of the database.Now,we have configured out database and we are good to go.</p><h3><strong><em>MODELS:</em></strong></h3><p>If you are working database and django,you should have know what are models.If not,I am here to explain.Models are the classes that are represented as the tables of the database.Each model represents a table of the database.OK,table will have fields right.Here,<strong><em>the attributes of the class are the fields of the table</em></strong>.Each model will inherit a base <strong><em>models.Modal</em></strong> class which has in-built methods to create fields with database.For example,see the following model,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*uGMnK_VkLwSTI53t08Z_Iw.png" /></figure><p>Each attribute is a field here.<strong><em>user_name</em></strong> is a field,<strong><em>name</em></strong> is a field.Each field is assigned to a datatype.Here,user_name field is of character type with the maximum length of the field is 20.These datatype methods are written in <strong><em>models.Model</em></strong> class and that’s why we are inheriting <strong><em>models.Model</em></strong> class for all the user defined models.To query the database,we are going to use <strong><em>ORM(Object Related Mapping)</em></strong> and we will be discussed about it after configuration part is over.</p><h3><strong><em>DB MIGRATION:-</em></strong></h3><p>If you are familiar with django,you would have heard about <strong><em>makemigrations and migrate</em></strong>.If not,no problem,I am here to explain.</p><p><strong><em>Makemigartions:-</em></strong></p><p>makemigartion is used to pack up all the changes that you have made in the models(database design changes<strong><em>(CRUD) — adding tables,altering tables,deleting tables,updating tables).</em></strong>It is similar to <strong>git init</strong> command in the git.It will make all the changes ready to migrate to the remote Database so that the changes will be saved.What if you are doing if for the first time in your app.There will be no models right.So,no changes are made.So,what will this command do for the first time?</p><p>The answer is,In the first time,all the default tables of the app will be kept ready for migrations and migrated(either the user defined models are created or not.If user defined model is created,user defined model + default models will be kept ready or else only the default models).Ok,now,what are all the default tables?You have come across installed apps section in the <strong><em>settings.py file</em></strong>,this installed apps will have this following snippet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*lPlq_7bXAFjDUxJC_Md_EQ.png" /></figure><p>Django uses Database to store a varity of details.For example,Django uses Database to store <strong><em>user details,authentication details,permissions and even app’s sessions data(These tables are the default tables)</em></strong>.Hence,these tables should be created as soon as makemigration runs for the first time.<strong><em>NOTE:Most of the tables may be useless,but it is recommended not to delete the default tables.</em></strong></p><p>To run makemigrations:</p><p><strong><em>&gt;&gt;python manage.py makemigrations</em></strong></p><p>Now,all the tables are ready to migrate.To migrate run</p><p><strong><em>&gt;&gt;python manage.py migrate</em></strong></p><p>For the first time,if there is no model craeted so far,the output will be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*3O1qBoFYK6YxIXhdGzgeUw.png" /></figure><p>All the default tables are migrated.</p><p>Now,what if there is a user defined model class.If new model is created and migrated,a table will be created in the database and if any changes has been made,the changes will be reflected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*957Dqt4zonsTPO9MLcixSQ.png" /></figure><p>In the above example,a new model has been created and once makemigration is run,this will be output.The table will be created when migrate is run(above example).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*bQybZrYxy3tYGNlMwdDQtQ.png" /></figure><p>In the above example,I have removed a field from my model and that has been ready to migrate and once migrated,the colums will be deleted from the table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*rZ5mcK-DZBq1WCsNIMo6Mg.png" /></figure><p>Once <strong><em>python manage.py migrate</em></strong> is run,the output will be the above one and the result will be reflected in the database.</p><h3><strong><em>ORM(OBJECT-RELATED MAPPING):</em></strong></h3><p>Now,we have configured database and have created tables.Once users started using our app, how will be the data stored to indatabase and the how will the data be retreived.We use <strong><em>Object Related Mapping</em></strong> for stored and quering database<strong><em>(read and write operations)</em></strong>.Instead of writing sql queries,we can query the database in <strong><em>pythonic way</em></strong> and it is much easier and efficient.Here,ORM comes into the picture.ORM will convert Relational databases into object-oriented programming classes.</p><p><strong>TABLES — — — ORM(BRIDGE) — — — APP(Python based)</strong></p><p>Instead of writing SQL queries,we can use methods as ORM will map tables with classes and fields with objects</p><p>We have a varity of methods in ORM to query the database.For example,</p><p><strong><em>.save() </em></strong>is used to store the data in the database.The implemention will be much easier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L9hX5OPSuAWy7IYkAlD6Vw.png" /></figure><p>In the above example,we store the usename,email and password given by user in the <strong><em>User model class</em></strong>.To save them,we use .save() method.We use this method to the model instance with the attributes given by the user.Here,the atrtributes we are going to store is userename,email and password.</p><p>similarly,to get all the rows in the table,we use..</p><p>&gt;&gt;<strong><em>modelname.objects.all()</em></strong></p><p>this is similar to the query:-<strong><em>select * from table;</em></strong></p><p>.<strong><em>all()</em></strong> method will get all the instances of the table.</p><p>similarly,</p><p><strong><em>.filter() </em></strong>is used to get specific fields.The <strong><em>‘where’ </em></strong>condition should be given as a parameter to the filter method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*obFJc5zmHyGI--eQdVJ-hg.png" /></figure><p><strong><em>.get()</em></strong> is used to get the first row that matches the given condition.</p><p>&gt;&gt;equivalent sql=&gt;<strong><em>select * from table where user_name=user limit 1;</em></strong></p><p>To get all the instances,use <strong><em>getAll() method</em></strong></p><p>Likewise,we can do n number of opertions in ORM and these operations are more efficient than plain sql queries.</p><p>We are at the end of this blog,the takeaways are:</p><p>— — Mysql configurations</p><p>— — Models</p><p>— — Migrations</p><p>— — ORM</p><p><strong><em>Thanks for reading…</em></strong></p><h3>In Plain English</h3><p><em>Thank you for being a part of our community! Before you go:</em></p><ul><li><em>Be sure to </em><strong><em>clap</em></strong><em> and </em><strong><em>follow</em></strong><em> the writer! 👏</em></li><li><em>You can find even more content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><strong><em> 🚀</em></strong></li><li><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. 🗞️</em></li><li><em>Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a><strong><em>(X</em></strong>), <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a>, <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a>, and <a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8849c98e72b" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/django-database-relationship-mysql-configuration-8849c98e72b">Django-Database relationship(MySQL configuration)</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data visualization using Matplotlib, Pandas-Django(Beginner’s level)]]></title>
            <link>https://awstip.com/data-visualization-using-mathplotlib-pandas-django-beginners-level-abd8b22ce1cd?source=rss-4c0a94a8e21f------2</link>
            <guid isPermaLink="false">https://medium.com/p/abd8b22ce1cd</guid>
            <category><![CDATA[charts]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Vikashvar Rajan]]></dc:creator>
            <pubDate>Sat, 26 Aug 2023 19:14:59 GMT</pubDate>
            <atom:updated>2023-08-31T11:15:03.983Z</atom:updated>
            <content:encoded><![CDATA[<p>In this data driven world, Data plays a vital role in analyzing, decision making and solving various real world problems. Passing data in pictorial form has more reach and understanding than passing data as mere numbers. How could we display numbers in a graphical representation so that information has been conveyed more efficiently? Here, charts comes into the picture.</p><p>Speaking about the charts, How could we integrate charts with Django so that we can process data and the data can be displayed in the website so that the end users are benefitted?There are a varity of libraries that helps us to picturize the data.Charts.js lib is one of them and I have a seperate blog on integrating charts.js with Django app.</p><p><a href="https://medium.com/aws-tip/data-visualisation-django-with-django-chartjs-e2334cf1ce6c">https://medium.com/aws-tip/data-visualisation-django-with-django-chartjs-e2334cf1ce6c</a></p><p>Speaking about the data, Do you think that all the information that you get are apt for data analysis?The answer is No.Some data has to be removed and some has to be modified.Hence,we are going to process the data before representing it using a popular python library-<strong>pandas</strong>.</p><p>In this blog, we will integrate <strong>mathplotlib</strong>-a pure python based charts library with our Django app to represent the data to the users in charts form.</p><p><strong>What are we going to do:-</strong></p><p>— -creating a Django app</p><p>— -requesting for an API and fetching data</p><p>— -processing the data using pandas</p><p>— visualizing the data</p><p><strong>prerequisite:</strong></p><p>— -Basic knowledge in python and charts</p><p>Let’s get started,</p><p>First of all, create a new django project</p><p>&gt;&gt;<strong><em>django-admin startproject Mathplotlib</em></strong></p><p>Inside the main django project, create an app -lobby and register the app in the installed apps:</p><p>&gt;<strong>&gt;python manage.py start project lobby</strong></p><p><strong>NOTE: </strong>To the people new to django, we create separate apps for separate modules inside our main projects.</p><p>Ok, create a template folder to store all the html files. It is the standard process for storing all static files of the app. Inside the template folder,create a html file in which the chart will be displayed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*DlImNMvn4OA3u0pmz1RXQQ.png" /></figure><p>Create an urls.py to map all the views with the corresponding urls. Whenever the url is called,the corresponding view will be triggered and the body of the view will be executed.This is the routing process of the django framework.</p><p>In the settings.py file, in the template section,do the following,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*libPyk1RlFFUzRoQqFiV7w.png" /></figure><p>It is to join the templates to the base directory so that the django project can find the certain file.</p><p>Now, In the views.py file, create a view that renders the lobby page in which the charts will be displayed.This view must be mapped with the urls.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*S6nC0qtj659HX2EciQinRQ.png" /></figure><p>This is just a template and in this view, we are going to code to porcess the data and sending the data to the html file where we are going to create the data.</p><p>&gt;&gt;in the urls.py file of the app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*t4WX78S2VES-OaivGYmwUQ.png" /></figure><p>In the main project’s urls.py file, add the app’s urls.py file so that the routing will be done by the main project.</p><p>Now,lets dive into the actual process. The process is simple:-</p><ol><li>read an API</li><li>retrieve the necessary information</li><li>plot and display it</li></ol><p><strong>Required libraries:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*I4i1iDyWs9l26uI-abWWGQ.png" /></figure><p><strong><em>StringIO</em></strong> is used to store the image data in a file like object</p><p><strong><em>render</em></strong> is used to render the html where the chart will be displayed</p><p><strong><em>pandas</em></strong> is used to clean the data</p><p><strong><em>requests</em></strong> is used to read the api</p><p>Atlast,<strong><em>matplotlib</em></strong> is used to plot the data</p><h3><strong>Reading an API :</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*crpzDsRXluYzgwh4cDbKLg.png" /></figure><p>Here, we use <strong>.get()</strong> method of requests library to read the data and this method will return a response object of the API and the data is converted into JSON so that we can process the data to retrieve the necessary iinformation. Here,<strong> .json() method is used to convert the response object into json format</strong></p><h3><strong>Cleaning the data using Pandas:</strong></h3><p>The json file is to be converted into dataframe. It is to simplify the processing and cleaning process of the JSON data. OK now,what is data cleaning? Data cleaning is the process in which the data table is processed and the incorrect data, incorrectly formated data, duplicate data will either be fixed or remove. This step is essential for analyzing data to the higher accuracy.</p><p>Few important data cleaning methods:</p><ul><li>What if a city’s population count is missing? In this case,we can either eliminate the enitre city from the process or the fill the missing data with the mean population of the country.This can be done using pandas libaray:</li></ul><p>&gt;&gt;<strong><em>df.dropna()</em></strong> is used to remove the entire cell</p><p>&gt;&gt;<strong><em>df.fillna()</em></strong> isused to fill the missing data</p><p><em>NOTE:This data can be processed without converting into dataframe as well</em>.</p><p>OK,we know the importance of dataframe,we create our own dataframe.</p><p>&gt;&gt;<strong><em>df=pandas.DataFrame(data[‘data’])</em></strong></p><p>The output of the the above line is :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*Z2nx6xZCr_5-9ebY75OEZg.png" /></figure><p>The data is in tabular form.Now we have to process this to get the list of cities and the population to plot them.</p><p>NOTE:Here,the data is clean enough as there is no improper data or missing data.In your use case,if you find any,just use <em>.</em><strong><em>dropna() and .fillna()</em></strong> methods.These methods will create a new dataframe with changes.If you want the changes to be applied in the existing file,pass a param<strong><em> (inplace =True)</em></strong>.This is modify the existing file without creating a new file.</p><p>If you find any data is missing,try to fill the missing data with the mean value(It is the preferred method).In our use case,if you find my city’s population value is Null,then calculate the mean population of the country and fill it in the empty cell.Now,how can be find the mean of the specific axis.We have a method <strong>mean(axis=n)</strong> in pandas ,which is used to calculate the mean value of the specific column.Pass the parameter axis to get the mean of the particular axis and similarly,pass n to get the mean value of n th axis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*abpL69OMmQF3A3vyVXuhSw.png" /></figure><p>First of all,we are split the data into several parts.</p><p>//first two lines are samples and has nothing to do with the project. You can jump straight to the third line.</p><p>df will store the names of the all the cities.df2 will have the population count.NOTE:population count has value,sex and details as well and we want the value alone to plot the graph</p><p>df3 will get the city who country matches with the value specified.In our case,it will filter the cities who country is france.</p><p>df.loc[] is used to used to return the specific rows who values matches the passed value.Here,It will return the dataframe with cities whose country name is ‘France’.Here,I have hardcoded it for easy understanding. To make this project better,use can pass the user’s input as well.</p><p><strong>.head() </strong>is used for slicing.Usually,head() will return the first five rows of the dataframe and if any number of rows is specified,it will return those number of rows.Here ,we are going to get first 10 rows.</p><p><strong>.to_list()</strong> is used to convert the dataframe into the list so that the list can be passed to plot the graph.</p><p>Now as I mentioned earlier,This API has populationCount key which has year,value and sex and we want the year only. To do so, we have used list comprehension.</p><p>&gt;&gt;<strong><em>populationList=[float(population[pp][0][‘value’]) for pp in range(len(population))]</em></strong></p><p>Now,this population list has the population count in numbers alone.</p><h3><strong><em>Plotting the data:</em></strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*46dJqTCnj73DX4dp8DqqZA.png" /></figure><p>Here,we are going to create a bar chart.</p><p><strong>.figure</strong> is used to create a new figure .The size of the figure can be set by using <strong>.figsize()</strong> method.</p><p><strong>.bar()</strong> is used to create a bar chart. It takes two lists as the parameters,one for the x axis and one for the y axis.</p><p>.<strong>xlabel()</strong> and <strong>.ylabel() </strong>are used to create labels for the respective axis.</p><p><strong>.title()</strong> is used give a title for the graph</p><p><strong>.tight_layout() </strong>is used to make sure that no part of the graph is trimmed or cut.</p><p><em>Now,we have to temporarily store the data and pass it to the html page.</em></p><p>First of all, why this segment?This segment is used to save the fig in a file without <em>write in a file</em>.This helps to transmit the data over the network without directly writing inside a file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*xCz-2115pwPiikChFgCQVQ.png" /></figure><p><strong>StringIO</strong> is used to create a new object for StringIO class which will be helpful in storing the graph data</p><p><strong>fig.savefig()</strong> is used to save the figure to a file. It takes the StringIO instances and the format of the file</p><p><strong>.seek(0)</strong> is used to set the file pointer curser to the first line of the file. This ensures that no data is missed or left behind.</p><p><strong>.getvalue()</strong> is used to get the data inside the file. The output will be stored in a variable so that it can be passed to the html file.</p><p>Atlast, this method will return the html page.</p><p>In the html page, we are just gonna display the file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*5Qxoss97l3KDVx1wn7mP4A.png" /></figure><p>The output of the code will be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*LbLaaG2-0dUEj7FmGUIBnQ.png" /></figure><p>we have successfully integrated pandas and matplotlib with Django.</p><p>takeaways of this blog:</p><p>→usage of request libaray</p><p>→pandas for data cleaning</p><p>→matplotlib for ploting a garph</p><p><strong><em>Thanks for reading.Happy coding!</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abd8b22ce1cd" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/data-visualization-using-mathplotlib-pandas-django-beginners-level-abd8b22ce1cd">Data visualization using Matplotlib, Pandas-Django(Beginner’s level)</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create A Music Player App using Django]]></title>
            <link>https://awstip.com/create-a-music-player-app-using-django-dd7149b4217c?source=rss-4c0a94a8e21f------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd7149b4217c</guid>
            <category><![CDATA[music-player-app]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Vikashvar Rajan]]></dc:creator>
            <pubDate>Sun, 30 Jul 2023 08:47:47 GMT</pubDate>
            <atom:updated>2023-08-03T07:12:18.442Z</atom:updated>
            <content:encoded><![CDATA[<p>While learning a framework,creating fancy real life websites will help us to understand the concepts and architecture of the framework in a better way.In this blog,I will walk you through my music player website which is built using pure django<em>(javascript is not used in this blog from creating this website)</em>.At the end of the blog,you will be able to work with <strong><em>media files and paginators</em></strong>(we can inprove the UX using paginator and it is a in-built module in Django) using Django framework.Let’s start.</p><p>First of all,create a Django project.</p><p><strong><em>&gt;&gt;django-admin startproject Musicplayer</em></strong></p><p>Create an app inside the django project</p><p><strong><em>&gt;&gt;python manage.py startapp Music_player</em></strong></p><p>Register your app in the installed apps of your main project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*hDmL3F03FBSodB9BbjDmAg.png" /></figure><p>Now, create a template folder in which we are going to create all our html files.We have to configure this folder to our base directory in order to manage a clean and modular structure in your Django app.Django app doesn’t require a seperate structure for template configuration yet it is recommended to do so to organise and manage the templates of our projects.</p><p>TEMPLATES:</p><p>Create a template folder</p><p>Go to settings.py file,In the templates section,add the following code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*lh61vfqBYGv4anWgM8oI_w.png" /></figure><p>Now,create an urls.py file in order to map the created app to our main project(Routing the app to the main project).In this urls.py file,all the function views which are used to render the html pages and implementing the business logic for our website will be mapped with the specific urls. This file will be mapped to the main project.</p><p>Go to urls.py file in the main project and include the urls.py file of our app</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*zuLKbRUroTeQfKZRAZTqAA.png" /></figure><p>Now,create a view to render a home page of our page and map the view to a url in urls.py in our app.As it the home page,we need not sepecific an url path for the home page.</p><p>&gt;&gt;In the views.py file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*oSYrjX-pLiKOUow67dYm6A.png" /></figure><p>In the urls.py file in the app,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*yNd8iV0ikC7nr-Ya9hZEGA.png" /><figcaption>KO</figcaption></figure><h3>DATABASE CONFIGURATIONS AND MODEL LAYER:</h3><p>Now,before we start working on the home page,lets work on the database where the albums and songs will be store.Here,we are going to use Mysql as our Database.It will store the mp3 files in BLOB format(Binary large Object).</p><p>Now,Let’s configure the Database with our main project.Let’s create a database using Mysql workbench and start configuring.</p><p>To configure the database,Go to settings.py file and add the below lines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*jx1RIwu3WHFr-dVdzN1Vbg.png" /></figure><p>In the “NAME” place,give your db name,and in “USER” place,give your username and in the password section, give your password.</p><p>Now,before migration, let’s create the models which will act as the heart of our app .Go to models.py file in your app,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*NGDIchaeINAV8YtrFd2M6Q.png" /></figure><p>We are going to have two tables.One is for Albums and the other is for Songs.A relationship should be created between the tables in such a way,a album will have relation will mulitple songs.A album can hold multiple songs and these songs can be categorized with the help of the album name.Here,the relationship will be established via a foreign key and they are cascaded,that is if an album is deleted,all the songs inside the album must be deleted.</p><p>In the album model,we have two fields — Album_name for storing names and a cover picture of the album.Here,the picture will be stored in media folder and it is a in-built feature and you just wanna configure the media folder to the base directory.</p><p>Now,in settings.py ,add the following lines to configure media files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*vGekkFQUIRzynTVmT4pNwQ.png" /></figure><p>After doing this ,you can find a new folder created in our app.</p><p>Now, in the second model,we are going to store the songs.A foreign key is created to create a one to many relationship between the folders and the songs.The songs will be stored in songs folder and image will be stored in picture folder.(we need not create these folders,django will take care of it)</p><p>Now,we migrate the models.</p><p><strong><em>&gt;&gt;python manage.py makemigrations</em></strong></p><p><strong><em>&gt;&gt;python manage.py migrate</em></strong></p><h3><strong>VIEWS AND TEMPLATES:</strong></h3><p>In our views,we are going to render the home page of our app and the in the views,we are going to fetch the album details and pass it to the html file.By using ORM,we get the all the rows by using Album.objects.all() and the result of this query is a list of the folders.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*H5quT3Q1vKX2wabN_-NZnw.png" /></figure><pre>{% load static%}<br><br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br><br>&lt;head&gt;<br>    &lt;title&gt;MusicApp&lt;/title&gt;<br>    &lt;style&gt;<br>        body {<br>            font-family: Arial, sans-serif;<br>            margin: 0;<br>            padding: 0;<br>        }<br>        <br>        .container {<br>            display: flex;<br>            align-items: center;<br>            padding: 20px;<br>            border: 1px solid #ccc;<br>            border-radius: 8px;<br>            max-width: 500px;<br>            margin: 20px auto;<br>        }<br>        <br>        .profile-image {<br>            width: 100px;<br>            height: 100px;<br>            border-radius: 50%;<br>            overflow: hidden;<br>            margin-right: 20px;<br>        }<br>        <br>        .profile-image img {<br>            width: 100%;<br>            height: 100%;<br>            object-fit: cover;<br>        }<br>        <br>        .profile-name {<br>            font-size: 24px;<br>            font-weight: bold;<br>        }<br>    &lt;/style&gt;<br>&lt;/head&gt;<br><br>&lt;body&gt;<br>    &lt;center&gt;<br>        &lt;h1&gt;MUSIC PLAYER&lt;/h1&gt;<br>    &lt;/center&gt;<br>    &lt;center&gt;<br>        &lt;i&gt;<br>        &lt;h3&gt;Find ur favourite artist&#39;s songs here for free!&lt;/h3&gt;&lt;/i&gt;<br>    &lt;/center&gt;<br>    {% for x in albums%}<br>    &lt;div class=&quot;container&quot;&gt;<br>        &lt;div class=&quot;profile-image&quot;&gt;<br>            &lt;img src=&quot;{{x.album_image.url }}&quot; class=&quot;img-fluid&quot;&gt;&lt;br&gt;<br>            <br>        &lt;/div&gt;<br>        &lt;div class=&quot;profile-name&quot;&gt;<br>            &lt;a href=&quot;{% url &#39;songs&#39; %}?album={{x.id}}&quot;&gt;{{x.album_name}} &lt;/a&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>    {%endfor%}<br>&lt;/body&gt;<br><br>&lt;/html&gt;</pre><p>In the home.html file,we are going to use a for loop to iterate through the list and display them.Here, a &lt;a&gt; tag used in album name place,so thatt when the user clicks on the name,it will take the users to the songs page,where the songs in the folder can be played.A varaible will be passed to the view-songs so that using this key,we can get the songs of the particular folder.This id is the foreign key for songs table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*pmiJYwrNr0QxNWKhXrpXXw.png" /></figure><p>In the views,We get the album id and we use filter method to filter the songs which belongs to the particular folder.Here,we are going to use Paginator to switch songs.</p><h3><strong><em>//use js,we can do page switching more efficiently,but I like to create this app as a pure django app so that I didn’t use js.</em></strong></h3><h3><strong>PAGINATOR:</strong></h3><p>This is a module which is your for improving the user experience .With the help of this module,we can create websites with any number of micro-pages.This module can be imported using</p><p><strong><em>&gt;&gt;from django.core.paginator import Paginator</em></strong></p><p>This paginator module has various in-built functions and we are going to use few of them.</p><p>example:</p><p>.has_next — use to check whether there is any pages available after this page</p><p>Paginator is used to split the objects among the webpages.By using the paginator,we can pass a queryset and can specific the number of queries can be displayed in a particular page.In our case,We are going to pass the songs in the order of one per page.We are going to render the songs.html file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vQQyzGEp48I5WH0yd3FbIw.png" /></figure><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Songs&lt;/title&gt;<br>    &lt;style&gt;<br>        body {<br>            font-family: Arial, sans-serif;<br>            margin: 20px;<br>        }<br><br>        h1 {<br>            color: #007bff;<br>        }<br><br>        ul {<br>            list-style: none;<br>            padding: 0;<br>        }<br><br>        li {<br>            margin-bottom: 10px;<br>        }<br><br>        audio {<br>            display: block;<br>            width: 100%;<br>            margin-bottom: 5px;<br>        }<br><br>        span.song-name {<br>            font-size: 18px;<br>            font-weight: bold;<br>        }<br><br>        .pagination {<br>            margin-top: 20px;<br>        }<br><br>        .pagination a {<br>            color: #007bff;<br>            margin-right: 10px;<br>        }<br><br>        .pagination .current {<br>            font-weight: bold;<br>        }<br><br>    &lt;/style&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br><br>    &lt;ul&gt;<br>        {% for song in songs_page %}<br>            &lt;li&gt;<br>                &lt;center&gt;&lt;img src ={{song.picture.url}} alt=&quot;myimage&quot;&gt;&lt;/center&gt;<br>                &lt;audio controls&gt;<br>                    &lt;source src=&quot;media/{{ song.song }}&quot; type=&quot;audio/mpeg&quot;&gt;<br>                    Your browser does not support the audio element.<br>                &lt;/audio&gt;<br>                &lt;span class=&quot;song-name&quot;&gt;{{ song.song_name }}&lt;/span&gt;<br>            &lt;/li&gt;<br>            &lt;center&gt;{{song.name}}&lt;/center&gt;<br>        {% endfor %}<br>    &lt;/ul&gt;<br>    &lt;div class=&quot;pagination&quot;&gt;<br>        &lt;span class=&quot;step-links&quot;&gt;<br>            &lt;center&gt;<br>            {% if songs_page.has_previous %}<br>                &lt;a href=&quot;?album={{ album_name }}&amp;page={{ songs_page.previous_page_number }}&quot;&gt;previous&lt;/a&gt;<br>            {% endif %}<br><br><br>            {% if songs_page.has_next %}<br>                &lt;a href=&quot;?album={{ album_name }}&amp;page={{ songs_page.next_page_number }}&quot;&gt;next &amp;raquo;&lt;/a&gt;<br>            {% endif %}<br>            &lt;/center&gt;<br>        &lt;/span&gt;<br>    &lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>In the songs.html file,we are going to use a for loop to get the songs.</p><p>songs_page is the list passed and .previous_page_number and .next_page_number will pass the page number to the album view and the above process repeats to get the next songs.These are placed inside a if statement,so that if there is no next page,has_next will not work and it ensures proper working of our app.</p><p>Here the album name is the page number :-)</p><p>//use js,we can do it more efficiently,but i like to create it as a pure django app so that I didn’t use js.</p><p>Now,let’s test our app</p><p>We should add the songs and albums throught the admin panel.To do so,we should create a super user and should register our models to the app</p><p>&gt;&gt;<strong>python manage.py createsuperuser</strong></p><p>127.0.0.8000/admin is the admin panel’s url and use it to access the admin panel.You can see that the admin url in the urls.py of the main project.</p><p>The admin panel will be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jPMlH0nXjNkL9qGSLUM8ZQ.png" /></figure><p>Here,use can find our models and can add files using the + sign.</p><p>To register our app,to go to admin.py file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*_dcESb1u2uhJXSI6XZoBxg.png" /></figure><p>The resultant output will be</p><h3><strong>//no stylings has been added.</strong></h3><p>home page ::-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E-V53Vxkxc8XL4UQga2eHg.png" /></figure><p>songs.html ::-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZPhluXnDqj7UnVdLM7_kWg.png" /></figure><p>Now,we have built your backend using django,we can apply any stylings to make our app stylise by using js in the html pages.</p><p>Here is this blog ends.Hope,you find it useful.Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd7149b4217c" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/create-a-music-player-app-using-django-dd7149b4217c">Create A Music Player App using Django</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django-Calculator app(Beginner’s friendly)]]></title>
            <link>https://awstip.com/django-calculator-app-beginners-friendly-5c9529febdf4?source=rss-4c0a94a8e21f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c9529febdf4</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[calculator]]></category>
            <category><![CDATA[django-rest-framework]]></category>
            <dc:creator><![CDATA[Vikashvar Rajan]]></dc:creator>
            <pubDate>Tue, 18 Jul 2023 18:49:47 GMT</pubDate>
            <atom:updated>2023-07-19T16:03:01.247Z</atom:updated>
            <content:encoded><![CDATA[<p>Django is a powerful web framework which is used to create amazing websites.While learning a framework,we must do several mini projects in order to get familar with the framework.Now,in this blog,we are going to create a simple calculator app.Let’s jump into the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*Jqn9_PP6oBrdGvk67CO-pw.jpeg" /></figure><p>Note:It’s a pure django project so we aren’t gonna use js here.(It’s a beginner’s friendly tutorial,all the coding are made simple.)</p><p>To create a Django-project :</p><p>&gt;&gt;<strong><em>django-admin startproject calculator</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*i-UugGFEoPqmNimdEiO1dg.png" /></figure><p>navigate into the project using your fav editor.Here,we are going to use VS code.</p><p>create an app inside our Django project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*BeTgY9m3_NONOr1NPFk-tw.png" /></figure><p>Register the app inside the installed app section in settings.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*S0ORFCqjhkQA4Khs4O_scg.png" /></figure><p>For user interface,we have to create HTML file through which the user enters the input and the output will be displayed.</p><p>Create a folder and create a html file inside the folder.Then, merge the templates folder to the base directory so that the framework can locate the HTML file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*UxhMT5v-6KuINNwUvJOJdg.png" /></figure><p>Now,Go to settings.py file and find templates section.There,join the created folder with the base directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*MGM_-gAKUdfVSgLgxoJLYg.png" /></figure><p>Now,we are going to code our logic inside the views.py.But,how are we going to route the created app to the main project.To do so,create a urls.py inside the created app and there,we have to route the views created by us.This urls.py should be included to the main project’s urls.py.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*YmYyb2zpELAsxUEWfaaRvQ.png" /></figure><p>The app has been added to the main project.Now,we have to map the view to its url pattern.To do so,create urls.py file inside the app</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*Jp_hhgC7EKBLms2Vy02BCA.png" /></figure><p>here,we have import the views from views.py and map it to the urls.Here,the calc view is mapped to home page as the empty string denotes home page</p><p>In views.py:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*Z7ziEzJeaj36p-FREjwYmg.png" /></figure><p>This view will render the html which will be our calc reception.Now,we are going to work on html page to get the inputs from the users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*swsDPc9rsXG0Tx3c3xWiBA.png" /></figure><p>Here,we use form to get two inputs from the submit.Here,we have used 4 submits from four different operations.The method parameter in the form is used to handle the form inputs and when the submit button of the form is clicked,there will be a connection established between the form and the view.The inputs will be processed the view denoted.The submit buttons are named by the operations and the names of the each button will be passed to the views via <strong>POST request</strong>.Here,csrf token has be added to the form for security reasons.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*6_mHgzrkG77knMPq5sxPxQ.png" /></figure><p>In theview,the input from the from is get through the <strong><em>request.POST()</em></strong> method.Here,each button represents each operator and the operation type is passed from the button via post method.This is handled by if statements.If the value passed by the button is add,then the if with add will be executed.</p><p>This ans can be displayed in the html page through jinja code.Use {{}} and pass the key value inside the jinja tag to see the output.The routing should be done for the view that are created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*7m7zB84qmDWgPkC0Fmukdw.png" /></figure><p>The output will be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3wJ-g71gF8St5QCnsV2nDQ.png" /></figure><p>Here,the input is disappeared as we rerender the page.We will learn to dispaly the answer without rendering the html to keep the input visible in the upcoming blog.</p><p>This is the simple calculator app.We are going to build a complex calculator app in the upcoming blogs.Stay tuned!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c9529febdf4" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/django-calculator-app-beginners-friendly-5c9529febdf4">Django-Calculator app(Beginner’s friendly)</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data visualisation-Django with django-chartjs]]></title>
            <link>https://awstip.com/data-visualisation-django-with-django-chartjs-e2334cf1ce6c?source=rss-4c0a94a8e21f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2334cf1ce6c</guid>
            <category><![CDATA[charts-and-graphs]]></category>
            <category><![CDATA[chartjs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Vikashvar Rajan]]></dc:creator>
            <pubDate>Wed, 12 Jul 2023 17:48:47 GMT</pubDate>
            <atom:updated>2023-07-13T16:47:16.739Z</atom:updated>
            <content:encoded><![CDATA[<p>Data visualisation is one of the best ways to suitcase a dataset.Picturizing a data will help us to convey the information in a efficient way.In this blog,we are going to use charts.js within our Django project to create a website that visualise a dataset.Charts.js is a javascript library which is used to create charts.We are going to integrate this library with our Django project.We are going to query a database and visualise it with the help of models.Let’s get started</p><p>create a Django project</p><p><strong><em>&gt;&gt;django-admin startproject Django_charts</em></strong></p><p>create an app inside the django project</p><p><strong><em>&gt;&gt;python manage.py startapp charts</em></strong></p><p>Register your app in the installed apps in settings.py</p><p>create a view which fetches the data from the model and renders a html page.In this HTML page,we are going to write scripts with charts.js to display a chart.</p><p>To begin with,Let’s create a model from which we are going to get the data.Move to models.py and start working in it.Here,we are going to visualize the dataset of text-editor users.So,our model will have two attributes,Text editor name and the number of people uses it.</p><p>In our models.py-</p><p>create a model in the following model.Initially,we are going to add the data to the table manually using the admin panel and query the table to visualise the data</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*j006wxqdCDJfW8fCWGAiog.png" /></figure><p>To migrate the data,we have to set up the database connection.Go the settings.py file and set-up your database.Here,we are using Mysql as our database and the setup will be</p><p>Use migrate comments to migrate the table to the database</p><p>&gt;&gt;python manage.py makemigrations</p><p>&gt;&gt;python manage.py migrate</p><p>Now,we create a super user to access the data so that we can add data to the table via admin panel</p><p>&gt;&gt;python manage.py createsuperuser</p><p>&gt;&gt;create a superuser with a password</p><p>Register your model in the admin.py file so that the model will be displayed in the admin panel.</p><p>charts&gt;&gt;admin.py —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*iSbWIvzo0-3nDfR85hDKDw.png" /></figure><p>Import the model and register it</p><p>Now,we run our server to see check whether the model iss added or not.To use admin panel,</p><p>&gt;&gt;python.manage,py runserver</p><p>&gt;&gt;url will be <a href="http://127.0.0.1:8000/admin/">Site administration | Django site admin</a></p><p>Now,enter your username and password</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fqfOvjIwNr2DquUn6tIUgA.png" /></figure><p>We can use the add option to add data to the table.</p><p>Now,we create a view to fetch the data and render a html page to visualise the data</p><p>&gt;&gt;views.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*4ReizG_J6b_oARqZNwSMzw.png" /></figure><p>Create a template folder and create a html file inside the template folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*vKRAgHsPXkTZ5L2hQh0V_Q.png" /></figure><p>join the template folder with the base directory.This can be done in settings.py</p><p>&gt;&gt;settings.py&gt;&gt;templates</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*Hy1GfW3WuEZO6GvLBzRPfg.png" /></figure><p>Now,include our app in the project.Move to urls.py in django_charts</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*cpr1XuaxZL3bB2Kh_8c_vw.png" /></figure><p>Create a urls.py file inside our charts app to map our view with a url</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*-LFVe-aZAiOtV4LGZXAdVA.png" /></figure><p>Now,all setup is done and lets work on views.py file to fetch the data and Html page to create a chart.</p><p>In views.py file</p><p>Query the table to fetch the data and pass it to the html page.</p><p>In admin panel,we add some text_editors to our model for sample</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DjpfsIyvaiRnRBNTzdlw1Q.png" /></figure><p>All done,now we work on html file to dispaly the chart</p><p>To do so,firstly, we have to install django-chartjs</p><p>&gt;&gt;<strong><em>python -m pip install charts.js</em></strong></p><p>Go to the official site of charts.js and get a template for the chart.you can find a number of templates for different type of charts.The only thing you have to do is to pass the value from the database to the html</p><p>Modify the views.py in the following way</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*0NP1NhBspN6MQDMZCVCxCA.png" /></figure><p>This will query the db and get us the fields..</p><pre>&lt;script src=&quot;https://cdn.jsdelivr.net/npm/chart.js@2.9.3/dist/Chart.min.js&quot;&gt;&lt;/script&gt;</pre><p>This script should be added to the html page</p><p>link for charts.js — <a href="https://www.chartjs.org/docs/latest/samples/line/line.html">https://www.chartjs.org/docs/latest/samples/line/line.html</a></p><p>A canva tag must be created to display the chart</p><p><strong><em>&lt;canvas id=”myChart” width=”400&quot; height=”100&quot;&gt;&lt;/canvas&gt;</em></strong></p><p>Then,pass the value through for loop</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*B71J45W8luXpreZk3gy_Mw.png" /></figure><p>The modified html page wis shown above.The background color is added apart from the documentation data.</p><p>Now,we can run our server and the output chart will be displayed in the webpage</p><h3><strong>The resultant webpage:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FtLst6MXdOzgO8OyTxipDw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cRplMxNFBjpqs-Ow5ZE3eQ.png" /></figure><p>Change the backgroundcolor field to get a colored chart</p><pre>backgroundColor: [<br>                        &#39;rgba(255, 99, 132, 0.2)&#39;, <br>                        &#39;rgba(54, 162, 235, 0.2)&#39;,<br>                        &#39;rgba(255, 206, 86, 0.2)&#39;,<br>                        &#39;rgba(75, 192, 192, 0.2)&#39;,<br>                        &#39;rgba(153, 102, 255, 0.2)&#39;,<br>                        &#39;rgba(255, 159, 64, 0.2)&#39;<br>                    ],</pre><p>Summary:</p><p>— Create an app</p><p>— Create a model</p><p>— fetch data from the model</p><p>— install charts.js</p><p>— pass the values</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2334cf1ce6c" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/data-visualisation-django-with-django-chartjs-e2334cf1ce6c">Data visualisation-Django with django-chartjs</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django-Dynamic HTML page creation with image(user profile page )]]></title>
            <link>https://awstip.com/django-dynamic-html-page-creation-with-image-user-profile-page-530e51d0b17b?source=rss-4c0a94a8e21f------2</link>
            <guid isPermaLink="false">https://medium.com/p/530e51d0b17b</guid>
            <category><![CDATA[django-login]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[django-image-upload]]></category>
            <category><![CDATA[django-models]]></category>
            <category><![CDATA[django-admin]]></category>
            <dc:creator><![CDATA[Vikashvar Rajan]]></dc:creator>
            <pubDate>Sun, 02 Jul 2023 08:07:32 GMT</pubDate>
            <atom:updated>2023-07-03T15:10:42.734Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog,we are going to create a log-in page for our page and we will create a dynamic html page for displaying user’s profile and personal details whoever logs in.Displaying user uploaded images inside an app along with user details is explained in this blog.Here,we are going to create a model(table) which holds all the user details like profile pic,email,education and create a dynamic html page to show the user details and the content for the page changes,whenver a different user logs in.To create a sign-in page -<a href="https://medium.com/aws-tip/django-sign-in-page-with-otp-verification-via-email-59ba45bc4871">https://medium.com/aws-tip/django-sign-in-page-with-otp-verification-via-email-59ba45bc4871</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*Jqn9_PP6oBrdGvk67CO-pw.jpeg" /></figure><h3><strong>HOME PAGE</strong></h3><p>Now, first of all, we should create a home page that has four buttons,sign-in ,log-in, create profile and show profile.Here, we can use sign-in page to create a profile for a user but by using a model in this simple use case will be help you to understand the models architecture of Django.Ok,now,we create a home page for the buttons</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*oJyvQoUWISyrdpP5PqVnhg.png" /></figure><p>Here,we have created four buttons and each button is inside an &lt;a&gt; tag which means,whenever the button is submitted,it will direct the user to the respective views.In href,we give function based view’s name,indicating that the submit action should direct to the particular view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*9VLfcHuwUzbUPSvbGjY6kg.png" /></figure><p>Each view in the above picture simply render a html where user can either enter the details or view the details</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*4F_SctkuTdV-O2CJ2i21nQ.png" /></figure><p>Each view is routed in urls.py file.If the view is not routed then the app will not find the view and throws error.Four html pages have to be created inside the templates folder(sigin,login,createuser,profile)</p><h3><strong>LOGIN PAGE CREATION:</strong></h3><p>Ok,now we are going to work on login html page to get username and password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*KBPKlMJE0flKi88RX53N3A.png" /></figure><p>We create a form and get two inputs from the user,username and password.The method will be post as the password is sensitive.The action will be <em>login_verification</em> where we check for the username in the database and the password and anthenticate the user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*fCuQg-EC_95zx9MduJ2VmQ.png" /></figure><p>Here,in login-verification view,we get the username and password and we check for the authentication.In django,there is a build in method called <strong><em>authenticate() </em></strong>which will surf through the DB and if the username and password exists,it will return the username or else it will return None.We use a if statement for further process(rendering html pages).If the authentication is success,user will be logged in or else alert message will be popped up denoting invalid login.Here,a session variable is created named user.This is created to denote that the user is logged in.The create user button will not work until the session variable user is created.This ensures that only the logged in user can create a profile.</p><h3><strong>CREATING A MODEL:</strong></h3><p>Now,let us create a model which will have the fields to be displayed in user profile section.To create a model, go to models.py file and create a model class.Each user defined model should inherit the models.Model class.Here,why should we inherit models?This is an exciting feature in Django that enables developer to inherit the existing fields into their own model class.For example,,we use models to inherit datafields,which denotes the datatype of the field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*Wl2XSDYD2hpkvZ1p4oi7sQ.png" /></figure><p>Our model consists of a profile_pic field which holds the image of the user.<strong><em>Imagefield()</em></strong> denotes that the field accepts images.<strong><em>upload_to </em></strong>denotes the location where the image must be stored.Likewise,there are textfield,emailfield and BigIntegerfield.</p><p>Now,we have to migrate the changes to the database</p><p>&gt;<strong><em>&gt;python manage.py makemigrations</em></strong></p><p>&gt;&gt;<strong><em>python manage.py migarte</em></strong></p><p>Now,we have to get the details from the user for creating the user.We move to createuser html file and create a form which will get the our model’s fields as input and we create a view called save to update the details to the database.We can also create a user using <strong>admin panel</strong>(Admin panel will be discussed in a separate blog).</p><p>Now,as we are getting an image as a input,where will be store the image.Here,the images will be stored in media files.In django,we need not create a media folder as it will be created automatically whenever a media is unrouted.Thus,we just need to create root for the media.</p><h3><strong>MEDIA FILE:</strong></h3><p>In settings.py,we add the following lines to create a base url for media files and a path to store it,</p><p>&gt;&gt;main project&gt;&gt;settings.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*hHX2lWyM-q5JldRwhUWqrg.png" /></figure><p>In urls.py file of the main project,we should add this media_root path,</p><p>&gt;&gt;main project&gt;&gt; urls.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*tfxrzYewS_tKdflgkkGb9g.png" /></figure><p>import the following ,</p><p>&gt;&gt;<strong><em>from django.conf import settings</em></strong></p><p>&gt;&gt;<strong><em>from django.conf.urls.static import static</em></strong></p><h3><strong>UPLOADING USERIMAGE BY USER WITH USER DETAILS:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*Uw-_ARqn99ND-uY83iteTA.png" /></figure><p>This will be our form.Here,the input type of the image file will be specified as “file”.In django,all the image and other static files fall under file type.Thus file input file is used to get the image as an input from the user.The <strong>accept</strong> parameter indicates that this field will accept only the specified type as the input.In our case,it is image.The other input types used here are tel(to get phone number),email(to get email ) and text.</p><p>Now,lets work on views to save the details to the database.So,let us create a view and name it as save</p><h3><strong>STORING INTO DATABSE:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CA5ailnIVIdHUj0CJLEQtg.png" /></figure><p>Here,we use request.file to post the image file and for all the other fields,we use request.post.To insert a row,we use ORM.Here,we wanna import the model into views.py.Now,use the model name and enter the data,In our case,<strong>User_profile(field1=value1,field2=value2)</strong>.This is similar to the sql query — <strong>INSERT INTO <em>table_name</em> (<em>column1</em>,<em> column2</em>,<em> column3</em>, …)<br>VALUES (<em>value1</em>,<em> value2</em>,<em> value3</em>, …); and to save the changes,we use .save() method.</strong></p><p>Now,to display the user_profile,lets work on profile view</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*yZgBG7Ig8Htes4r8G8qCvw.png" /></figure><p>In this view,we will select a row from the table which matches username who is logged in.<strong>get()</strong> method will return a dictionary with fields as its key and user details as its value.</p><p>output of get() function</p><p>The user must be logged in to get the user details.Here we make a few changes to do that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*7t8ZFTMcNSOOT4Rt69N54g.png" /></figure><p>while logging in,we created a session variable named user.This variable will be created only after the successfully log-in.Here,in our profile view,we uses that session user to fetch the data from the database.Thus,if the user is not logged in ,the session variable wil not be created and using it will through an exception.So we use try-except.We try to get data and if the user is not logged in,except block will be executed and a pop up will notify the user to log in.</p><p>The user details are quered and stored in a variable.This variable will be passed to the html to display the details.All the vatriables in the views is passed to the html page in dictionary form.We can access the view variable with the help of the dictionary’s key.In our case,user is the key and queryset will be the value</p><h3><strong>DYNAMIC HTML PAGE:</strong></h3><p>In profile.html ,we display the user details.This page is dynamic and the content of this page changes whenever different user logs in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*8gRJC6IQtq_mDzsiTXyJOg.png" /></figure><p>In profile view,we passed a dictionary with the user details.Those details will be rendered into the html file using jinja code.The data is passed in dictionary form thus we can use keys to access the user details<strong>(“.” is used to access the keys of the dictionary)</strong>.For example,to access the email,we use <strong>user.email</strong>(here,user is the dictionary name and email is the key which holds user’s email as its value).Likewise we can access all the fields with dictionary passed.Here,the point to note here is while accessing the image file,we have to use .url in the end.</p><p><strong>Summary:</strong></p><p>created a log in page.</p><p>created a model to store the user details.</p><p>created a form to get user details.</p><p>created a dynamic html page to show the user details.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=530e51d0b17b" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/django-dynamic-html-page-creation-with-image-user-profile-page-530e51d0b17b">Django-Dynamic HTML page creation with image(user profile page )</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DJANGO-sign in page with otp verification via email]]></title>
            <link>https://awstip.com/django-sign-in-page-with-otp-verification-via-email-59ba45bc4871?source=rss-4c0a94a8e21f------2</link>
            <guid isPermaLink="false">https://medium.com/p/59ba45bc4871</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[email]]></category>
            <category><![CDATA[sessions]]></category>
            <category><![CDATA[otp-verification]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Vikashvar Rajan]]></dc:creator>
            <pubDate>Tue, 27 Jun 2023 06:19:30 GMT</pubDate>
            <atom:updated>2023-06-27T14:01:31.298Z</atom:updated>
            <content:encoded><![CDATA[<h3>DJANGO-sign in page with OTP verification via email</h3><p>While learning a framework ,creating mini projects helps us to explore the features of the framework.Now,we are going to create a simple sign-in page with email verification using Django.At the end of this blog,you will get an insight about the django database connections,django forms,django sessions,django email architecture and few crud methods like get and post.Let’s get started.</p><p>Find the source code: <a href="https://github.com/VIKASHVARR/signin-blog">https://github.com/VIKASHVARR/signin-blog</a></p><h3>Setting up the project:</h3><p>First of all,create a virtual environment for our django project to isolate it from other django folders.Then,create a new django project in the command prompt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mPrS_5WnZtMYZfeu3SDW2Q.png" /></figure><p>Then,open the project folder in your test editor.In my case,it is vs code</p><p>Create a new app with my name.In my case,I name it home</p><p>&gt;&gt;<strong><em>python manage.py startapp home</em></strong></p><p>Create a view which will render a html page where the user will be entering their personal details for signin.Create template folder inside the app to store the html pages.Create a html page inside the templates and name it as home.html.Join the templates with the base directory in settings.py file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*l8gkr1Bta0LgdtYUPwvS0Q.png" /></figure><p>Map the view function with a url by creating a urls.py file inside the app and map the app with the main project by including the urls.py file into the urls.py file of the main project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*WoFLUGazN8FluRTQOrve7w.png" /><figcaption>view to render the signin page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*pMYo8aLKopa6eJnnCrUTEA.png" /><figcaption>view function is mapped with home page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*xu0-6DVtS0eZDI9MBlO-Hg.png" /><figcaption>app’s url.py file is included to the main project’s url file</figcaption></figure><h3><strong>Signin view:</strong></h3><p>Now,we work on html page to get the user details.Here,we use html forms to get the user details.HTML forms takes two arguments,Action and method.Action is used to indicate where the data has to be sent whenever the form is submitted.Usually,we send the data to a view to process the data.Here in the views.py file ,we gather the data and store it in a DB table.Method indicates how the data to be sent.Usually there are two common methods to send the data to the views-GET and POST.GET method is used to send the data as a url variable.Since,we want to send personal details and passwords,we don’t use get method because passwords should be sent securely.Thus we use POST method to send the data securely.</p><p>Ok,Now,we set the inputs for the forms.This includes first name,Last name,User name,Email,password,Confrim password.Here, in the back-end ,we will check for unique username creation and password -confrim password match.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DuO_GJzettOrXQO5kuq8qg.png" /><figcaption>signin html page for getting user details</figcaption></figure><p>Here,<strong><em>csrf token</em></strong> has to be used whenever we are using post request.This csrf token is stored in server side application.The server side application ensures the token created while user login matches the token stored on the server side thus ensures data security and <strong><em>prevents csrf attacks</em></strong>.Once the submit button is clicked,The data will be sent to <strong><em>signin_verification</em></strong> views.</p><p>Now,Coming to the forms,All the details needed for user sign-in are received and will be sent to the signin_verification view.</p><p>We wanna create a view called signin_verification(you can name it whatever you want) and wanna map it to a url in urls.py file.</p><p>In signin_verification view,all the data are received from the form and stored to the corresponding variables via http post method.</p><h3><strong>database connection:</strong></h3><p>If all the details are valid,where will be the user data stored? Thus database connections is required.Here,I am using Mysql as my DB but you can use whatever you are familiar with as django supports almost all of the DB available.Now,let us set up the DB.</p><p>Go to settings.py,There,you can see the Database section,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*9mSghNJrWJE7O5ShOG4n0A.png" /></figure><p>The default DB issqlite3,we wanna change it as we use Mysql.The altered database configuration will be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*FOao1URrF2TqqumRQNEisQ.png" /></figure><p>Here,we wanna create a database for our app,this can be done by executing the following command in Mysql workbench</p><p>&gt;&gt;create database DB_NAME</p><p>Now,provide your user name and password as the user and password values in the database section.Now,our database is ready to use.Here,we have a special feature in Django.We don’t wanna create seperate tables for storing user ceredentials.Django will create default tables for user,permissions and groups.We just wanna migrate them to the database to store data and use them.Here,to migrate data,we have to execute two commands,</p><p>&gt;&gt;<strong><em>python manage.py makemigrations</em></strong></p><p>This command will indicate that a new table is created or changes has been made in the existing table and tables are ready for migration.(This is similar to git init method)</p><p>&gt;&gt;<strong><em>python manage.py migrate</em></strong></p><p>This command will migrate the new tables and changes to the database</p><p>The tables that are created are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/234/1*gzXWsgc7WLZIQXOSi1iYWw.png" /><figcaption>tables</figcaption></figure><p>Here,in auth user ,all the user details will be stored</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*v6u9_WFDZ2mmQ6DiaJrCJQ.png" /></figure><p>We have to import the above modules and methods for our app and the usage of these methods will be discussed below,</p><p>Now,lets look into validation and otp verification</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*iwUMVcvrq9WFdpAK0B-3vA.png" /><figcaption>signin view to verify the data and send otp</figcaption></figure><p>Here,all the meta data are stored in variables and ready for validation,First of all,we check for password -confrim password match.If both mismatches,then an error message will be popped up notifing that the password mismatches.<strong><em>message.info() </em></strong>is used to process the error message and the message display method will be written in html page to display the message(discussed below).If the passwords matches,we check for unique username ,if username is already taken,we should insist the user to take a different username.Here,ORM(Object Related Mapping) is used to query the database.<strong>User</strong> is the table name and <strong><em>User.objects.filter()</em></strong> is used to select the tuple with the parameter given,Here the parameter is username and here we will check for tuple with the username with the username passed.<strong>exists()</strong> method returns True if the username is already in the table indicating that the username is taken.Similarly,email is also verified.If the email is taken,then error message will be popped up.If all the ceredentials matches,otp verification process will be launched.</p><p><strong><em>message handling:</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*fk_Bfhy78EIEjaLQpSmM_Q.png" /><figcaption>js is used for script messages.Included in home.html</figcaption></figure><p>Here,we pass the message to the html page and the above code is used to display the message.</p><h3><strong>Email verification:</strong></h3><p>To send an email ,we have to set up few things in settings.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*lTVm5q6ZxgNtZsWp_xlH5Q.png" /></figure><p>Include these things ,notifing the host name,port name and other email details.</p><p>How to get email_host_password?</p><p>To get the host password,First go to your google accounts and go to security.There,enable two-step verification.After enabling two step verfication,search for app passwords in the search bar,go to app passwords and there, select others from the drop box and name the app and click generate.A password will be generated.Copy that and paste it in the email settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fnuNh1_6eYrLvzGj7vULWw.png" /><figcaption>Accounts-&gt;Security-&gt; app password</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*cVGTqVvVoA6fqMj3G8tVGw.png" /><figcaption>enter an app name and generate a password</figcaption></figure><p>Now,lets write the view to send the otp.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*--7EVOnntmIusF5EtQfOjA.png" /><figcaption>send_otp view to send opt and render to the otp html page where user can enter the otp receivered.</figcaption></figure><p>In the above function,we generate a 4 digit otp pin using a for loop and the email is sent via <strong><em>send_mail() </em></strong>method.This method should be imported</p><p>&gt;&gt;<strong><em>from django.conf.core import send_mail</em></strong></p><p><strong>send_mail()</strong> takes five arguments.</p><p>— The subject of the mail</p><p>— The content of the mail.Here the content is otp</p><p>— The sender mail id</p><p>— the receiver mail id</p><p>— <strong>fail_silently()</strong> is used to terminate the process without any breakdown if the process fails.</p><p>Then,this view will render a html page where the user enter their otp for verification.Create a html file inside the templates.Here,I create a file named otp.html</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SCMn3gDANFMq7WSfDNDetQ.png" /><figcaption>html page to get the otp from the user</figcaption></figure><p>Create a form to get the otp from the user.The data should be sent to a view named otp_verification for the verification process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AAqt-wmi4vsCXceCVaGSiw.png" /><figcaption>view for otp verification and data storage</figcaption></figure><p>In the otp_verification() view ,we check whether the entered otp matches the otp send by the send_otp() view.We use sesssion to increase the scope of the otp variable and thus otp comparison is made.</p><h3>Django Session:</h3><p>Sessions are used to pass the variables across the website.It is more or less similar to cache machanism.Here,we use sessions for passing username ,email ,password from the signin_verification views to otp_verification views(can be used across all views) to store the data in the database.Session variable is created for otp to share it to otp_verification views.</p><p>In the opt_verification view,if the otp matches,the details should be stored in the database.How could we do that?It is simple to store the data.Just use the table name and pass the values.</p><p>&gt;&gt;<strong><em>name=User(username=username_variable,email=email_variable,password=encrypted_password)</em></strong></p><p>&gt;&gt;<strong><em>name.save()</em></strong></p><p>To save the details to the DB,use <strong><em>.save()</em></strong> method.Here,the password is encrypted.This is because,while authenticating the user during log-in we use,<strong><em>auth.authenticate()</em></strong> method to check for the username and password in the DB,Here,this method(auth.authenticate)will convert the password to encrypted password and check for the encrypted password in the database.If we store the data in text form,the password will not match with the password passed through auth.authenticate[encrypted password] even though your password is correct.Thus keeping this in mind,we store the password in encrypted form.Password can be encrypted by using the method <strong><em>make_password</em></strong></p><p>&gt;&gt;<strong><em>from django.contrib.auth.hashers import make_password</em></strong></p><p>&gt;&gt;<strong><em>encrypted_password=make_password(users_password)</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5HmRoBI2-l6IH6svERkNvw.png" /><figcaption>page for otp</figcaption></figure><p>The opt will be sent to the user’s email.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*gMB86OVw6BMa0jIf7qxf-A.png" /><figcaption>otp received</figcaption></figure><p>When the otp is verified,a pop up will notified that the signin was successful and the user will be created and the data will be stored in the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S0ucoYlHMEWkI044Mfdl8Q.png" /></figure><p>In the next blog,lets create the login page and add some dynamic html pages to our page.</p><p><strong>Summary:</strong></p><p>Created a signin page</p><p>Configured database</p><p>Configured email</p><p>Otp verification</p><p>Data stored in DB</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59ba45bc4871" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/django-sign-in-page-with-otp-verification-via-email-59ba45bc4871">DJANGO-sign in page with otp verification via email</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django templates(Configure HTML and CSS),heard of html inheritance?]]></title>
            <link>https://awstip.com/django-templates-configure-html-and-css-heard-of-html-inheritance-ca10a301ff8e?source=rss-4c0a94a8e21f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca10a301ff8e</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[html5]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[css3]]></category>
            <dc:creator><![CDATA[Vikashvar Rajan]]></dc:creator>
            <pubDate>Sat, 24 Jun 2023 15:07:45 GMT</pubDate>
            <atom:updated>2023-06-29T14:18:34.779Z</atom:updated>
            <content:encoded><![CDATA[<p>We know that ,HTML is the user interface of any webpage. User interface will help the user to use the service of the website .Even though Django is a python based framework,we can configure the HTML and beautify the pages using CSS within the framework.As Django is a structured framework,All the Html pages of an app should be created under a folder(usually the folder will be named as templates) and the folder will be added to the BASE_DIR(base directory) so that the framework can locate the specific HTML and render the specific html page whenever the link is triggered.Now,This article discuss about the templates and static file management of the django framework and we are gonna create a sample webpage using django with html and css configaration.</p><p>First of all,a template folder should be created which acts as a container for all html pages.After create the folder,we have to add the templates folder to the base directory.In settings.py,you can find the templates setting,there will be a empty list with the key ‘DIRS’.There,we have to join the base directory with the templates.That can be done by the following code</p><p><strong><em>DIRS:[os.path.join(BASE_DIR,’templates’)],</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*l8gkr1Bta0LgdtYUPwvS0Q.png" /></figure><p>You have to import os library to join them.</p><h3><strong>RENDERING HTML PAGE</strong></h3><p>Next step,we must have a view function to render a html page.We can come with a simple view function and render a html page.To do that,we wanna create a html page inside the templates with the extension .html to make the framework know that the file is html file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*xREtICJoL0wLgYyBCzRVow.png" /></figure><p>Now ,write a simple view function and render our html page.Here,render function will help us to load a html page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*WoFLUGazN8FluRTQOrve7w.png" /></figure><p>The rendered html page will be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b_QBaa9SdLFaVSdsh3rvgA.png" /></figure><h3><strong>HTML INHERITANCE</strong></h3><p>A special feature in django enables HTML inheritance in Django.First of all,why HTML inheritance?Suppose we wanna create a website in a single style for all html pages,It is a sick process to write the same div tags and styles in all html pages.Instead of writing the same html code in multiple html pages,we can create a html file with the common code and inherit it .We can write the html tags which are unique for the certain page inside the block content to have a neat and maintainable html code.Let’s practically apply it.</p><p>Create a base html page for Inheritance.Base file will act as the parent file for all the other html files.Then inherit it using jinja code.(refer my Django-MVT architecture stroy for jinja notation examples).Use<strong><em> {% include “base.html”%} </em></strong>as a header in the child html file to inherit the html page inside the current page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*HEvGtcp5sw2Y5bj5_H9ToQ.png" /></figure><p><strong><em>use{%block content%} “specific content of the page”{%endblock content%}</em></strong> to write the specific html code of the block.This concept is exampled below with images</p><p>create a base.html file(parent file) inside the templates folder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*s9eV2VSca9ORnZYCbgTasA.png" /></figure><p>This is a sample base html and the content outside the block content will be inherited by all the child html pages.Here.”inherited code lines ” will be passed on.</p><p>create a child html page which inherits base.html</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*ssCCDxuAtE4BLX29PD8eTQ.png" /></figure><p>First line in the image is used to inherit the base html file and the file specific codes which are unique to the particular html page are written inside the block content tags.The resultant html page will be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*heVOKsfwnb9nBqzcYRYVnA.png" /></figure><p>By comparing the code and output,we can differentiate the base.html and home.html files and can understand the inheritance concept.This method is simplified in the above example and it will be very handy when we are writing complex code.</p><h3><strong>STATIC FILES</strong></h3><p>Now,how can we add images and css into the html?Why fear when Django is here?Handling static files is also structured in Django.To include the static files,we must have a folder to store all static files and also,we should let the framework know about the folder.Django has a in-built static file handling architecture.Here,our job is only to add the static files to the base directory and acknowlegde the framework.</p><h3><strong>ADDING IMAGES</strong></h3><p>First of all,create a static folder inside the app ,then add few images to the folder,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sl4-l6HKmuxkQ4lJFnWa0Q.png" /></figure><p>Just create a folder and drag and drop a image.Now,go to settings.py file .Scroll down to the last and you can find static file variable,add the following lines of code to acknowledge the framework and add the static files with the base directory.To make the framework locate the static files,add the static folder to the base directory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*a8oni2UWwFG4iBszbWT86w.png" /></figure><p>Now,we go to the html page and add the image to the html page</p><p>To load the static files,use <strong><em>{% load static%}</em></strong> jinja notation.Now,we can use &lt;img&gt; tag to display the image.The only thing we have to look into is ,we should give the image location in jinja format.See the image to get better understanding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*-9ojMh_09z83oF5-W6YxVA.png" /></figure><p>Load static is used to load the static files.In the image tag,we give the source location in the jinja format — static keyword,file name.Here,static keyword is used to indicate the file is static and django-basics.png is the file name.The output willl be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pIKM1NsCSwOSEaQfl_gLCw.png" /></figure><h3><strong>CONFIGURING CSS FILES</strong></h3><p>Yeah,We have successfully inserted a static image into the html page.Now,as a final step we try to add css styling to the hml page.To add css file,we have to use link tag in the html page.CSS file will also fall under the static file category.Here we can either add the css styling in the same html page with the &lt;style&gt; tag.But while working in big projects,maintaining separate files is preferred.Thus,we create a separate css file and try to add some styling.</p><p>Create css file with .css extension.Link the css with html with the help of link tag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l8nBdma3JoSyy3RzlHsCtQ.png" /></figure><p>Here,I have created a sub folder inside the static folder to separate css files from other files.To link the css file,we use link tag,Once again the reference link should be in jinja notation.<strong><em>{%static ‘location of the file’%}</em></strong>.To check whether the css is linked or not,let us change the background color in home.css file and test it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*XztHxA5-Y_m5_mx3Srv0pg.png" /></figure><p>Here,the body color is changed to aqua.As this file is linked to home.html,the styling will be reflected in the home.html file.The output will be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m2T77HvKtpiOLTIbj7NRJQ.png" /></figure><p>Yeah,we have configured the css with html. This is just for testing and you can style any number of html blocks in a html page using the above instructions.</p><p>Now,we have successfully configured html and css with our backend,In the upcoming blogs,we use this to create wonderful webapps</p><p><strong>SUMMARY:</strong></p><p>Rendering the html page</p><p>Inheriting ahtml Page</p><p>Loading static images</p><p>Linking CSS files</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca10a301ff8e" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/django-templates-configure-html-and-css-heard-of-html-inheritance-ca10a301ff8e">Django templates(Configure HTML and CSS),heard of html inheritance?</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build your first app using Django]]></title>
            <link>https://awstip.com/build-your-first-app-using-django-8e1523e2188f?source=rss-4c0a94a8e21f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e1523e2188f</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[myfirstapp]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Vikashvar Rajan]]></dc:creator>
            <pubDate>Thu, 22 Jun 2023 14:57:33 GMT</pubDate>
            <atom:updated>2023-06-26T17:37:14.901Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s create our first app using Django in a structured manner.</p><p>It is always suggested to provide a virtual environment for each Django project you create.Ok,now why virtual environment?The reason for creating a virtual environment for each Django projects is to isolate each project and eliminate dependencies.For example,If you are given a django project that uses an older version of Django,You have to switch to the older version of Django.It’s fine for one project.But ,what if you are working on multiple projects?You should change your Django version each time .Thus ,creating virtual environment helps you to install the dependencies of the projects in the specific virtual environment and you don’t want to make changes everytime as the virtual environment has the dependenies of the particular project ready in the project’s own environment.Thus,each project has its own requirements ensures isolation.Now,let’s create a virtual environment.</p><p>First install the virtual environment,</p><p>&gt;&gt;<strong>pip install virtualenv virtualenvwrapper-win</strong></p><p>To create a virtual ennvironment,use</p><p>&gt;&gt;<strong>mkvirtualenv name</strong></p><p>To work on the virtual environment, use</p><p>&gt;&gt;<strong>workon name</strong></p><p>Now,we can create our first app using django,To create an app,use</p><p>&gt;&gt;<strong>django-admin startproject project_name</strong></p><p>Use a text editor to work,here,we are going to use VS code.To move your project to the VS code,use</p><p>&gt;&gt;<strong>code .</strong></p><p>or simply,you can drag and drop your folder or go to VS code</p><p>— — file</p><p>— — — — — —open folder</p><p>— — — — — — — — — select folder</p><p>OK,now we can start building our app.As you progressed this long,you can see few files in the folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/189/1*YsNd34K0adBMAIKS_PpyJA.png" /><figcaption>Files that are created</figcaption></figure><p>Here,__init__.py is to indicate that the directories are python based and the files are marked as python files.</p><p>wsgi.py and asgi.py are required so that web app can communicate with web server.ASGI is the advanced feature of Django which allows multiple async event to communicate.[These topics will be discussed in a seperate Blog]</p><p>settings.py has the app settings where you can make database connections,add the template sessions and allow the web host to host the app,add middlewares and much more.While practical applicaton,we can go through all the options available in setting.py.</p><p>urls.py is used to map the sub apps to the main project.A project is divided into several sub apps.Each apps will do a certain job.For example,in a e-commerce project,we may have separate app for login/sign-in,a separate app for products/purchase and a separate app for other applications.Using Urls.py ,we can map all the apps to the main project.</p><p>manage.py is the command line utility for django apps.</p><p>&gt;&gt;<strong>python manage.py runserver</strong></p><p>Here,python manage.py is the command line utility and runserver is the sub comment to run the app on the localhost.</p><p>we can use <strong>&gt;&gt;help</strong> subcomment to get all the common subcomments</p><p>&gt;&gt;<strong>python manage.py help</strong></p><p>Now,To create a seperate app,we can use</p><p>&gt;&gt;<strong>python manage.py startapp test1</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/187/1*-B_2SRqZB3AHiD6sbnWaUA.png" /></figure><p>Here,we need to create a file named <strong>urls.py</strong> inside our app to map all the views to their specific urls. and finally this urls.py file will be included in the main project’s urls.py .Views are the functions which will be called when the mapped url is triggered.For example, if ‘/home’ url is called,then the function mapped with the url will be called and the body of the function will be executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*p2slh28davN9OvEEuCA1fQ.png" /></figure><p>On right click on the app,with new file option,we can create new file and name it urls.py.</p><p><strong>In urls.py</strong> ,we have to import path(to map the views) and views</p><p><strong>from django.urls import path</strong></p><p><strong>from . import views(.(dot) indicates current directory)</strong></p><p>Then ,use urlpatterns to map views to the urls</p><p><strong>urlpatterns=path(‘<em>/url’</em>,views.view_name,name=”name”)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*pMYo8aLKopa6eJnnCrUTEA.png" /></figure><p>path is used to map and “” represents home page.</p><p>In views, we write our first function which simply prints a Http response on our web page</p><p><strong>In views.py,</strong></p><p>def home(request):</p><p>return HttpResponse(“hello world”)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/1*lxRiRe0-C6hUUfKHknqt8Q.png" /></figure><p>OK,Now,we have to map the app to the main project,To do that,go to urls.py in the main project and import include to include the app’s urls.py file to the main app</p><p><strong>path(‘’,include(“test1.urls”))</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*CilfnyQBf8dJzItPDCyspg.png" /></figure><p>Now, we have to add our app to the installed apps in the settings.py file,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*7Cm3wDUqwzcUOgI7OZ15Xg.png" /></figure><p>our app test1 is added successfully,Now,we can run our app using</p><p>&gt;&gt;<strong>python manage.py runserver</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*IznWMb_W9kgCEIjULzizpA.png" /></figure><p>The app is running in the above ip(localhost-port 8000) and you can use any browser to run the app</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*1FNRpOS4BSKXu6v6DLvWyQ.png" /></figure><p>Our app is launched successfully in the localhost and HttpResponse is displayed.YEAh,we have created our first django app.This is our first move and in the upcoming blogs,we are going to create a fully functioning real world django app.</p><p><strong>Summary:</strong></p><p><em>— Create a django project in a virtual environment</em></p><p><em>— Create an app inside the project</em></p><p><em>— Create urls.py file and map the views</em></p><p><em>— Create view in views.py</em></p><p><em>— Map the app to the main project</em></p><p><em>— Run the server</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e1523e2188f" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/build-your-first-app-using-django-8e1523e2188f">Build your first app using Django</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>