<?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 Bunny The Compiler on Medium]]></title>
        <description><![CDATA[Stories by Bunny The Compiler on Medium]]></description>
        <link>https://medium.com/@bunnythecompiler?source=rss-fd3da10eba26------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qGWnDVLxR_sODFfouV7rkA.png</url>
            <title>Stories by Bunny The Compiler on Medium</title>
            <link>https://medium.com/@bunnythecompiler?source=rss-fd3da10eba26------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 20:07:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bunnythecompiler/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[How to Build a Flask Rgb to Color Name App — bytexplain]]></title>
            <link>https://medium.com/@bunnythecompiler/how-to-build-a-flask-rgb-to-color-name-app-bytexplain-120aac4501de?source=rss-fd3da10eba26------2</link>
            <guid isPermaLink="false">https://medium.com/p/120aac4501de</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[request]]></category>
            <category><![CDATA[rgb]]></category>
            <category><![CDATA[web-colors]]></category>
            <dc:creator><![CDATA[Bunny The Compiler]]></dc:creator>
            <pubDate>Wed, 14 Jun 2023 22:29:50 GMT</pubDate>
            <atom:updated>2024-06-09T09:51:53.181Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Build a Flask Rgb to Color Name App — bytexplain</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5_2Shlvogv0m1s13.png" /></figure><h3>Introduction</h3><p>In this tutorial, we will be building a Flask app that converts an RGB value to a color name. This application will help in simplifying color identification. For this tutorial, we will be using <a href="https://pypi.org/project/Flask/">Flask</a> as our web server and<a href="https://pypi.org/project/webcolors/"> webcolors</a> as our<a href="https://en.wikipedia.org/wiki/RGB_color_model"> RGB</a> library.</p><h3>File Structure</h3><p>To begin we will first need to create a few files and folders, Create a folder called <strong>rgb-app</strong>, inside it create a folder called <strong>templates</strong> and create a file called <strong>index.html</strong>. Now inside the <strong>rgb-app</strong> folder create a file called<strong> app.py</strong></p><h3>Install modules</h3><p>To begin we will first need to install Flask and webcolors, to do so run the following commands below in your terminal.</p><pre>pip3 install Flask pip3 install webcolors</pre><h3>Create app</h3><p>Inside the <strong>app.py</strong> import the following modules</p><pre>from flask import Flask, render_template, request <br>import webcolors</pre><p>Now let’s initialize our application as shown below.</p><pre>app = Flask(__name__)</pre><p>Next, let’s create a function to convert our RGB values.</p><pre>def rgb_to_color_name(rgb): # Convert RGB value to closest color name <br>    try: <br>        color_name = webcolors.rgb_to_name(rgb)<br>        return color_name <br>    except ValueError: <br>        return None</pre><p><strong>SEE ALSO</strong>: <a href="https://bytexplain.com/how-to-build-a-flask-weather-app-using-python/">How to Build a Flask Weather App Using Python</a></p><p>Now let’s create our route for the application as shown below.</p><pre>@app.route(&#39;/&#39;, methods=[&#39;GET&#39;, &#39;POST&#39;]) <br>def color_converter(): <br>    if request.method == &#39;POST&#39;:   <br>        # Get RGB values from the form <br>        r = int(request.form[&#39;r&#39;]) <br>        g = int(request.form[&#39;g&#39;]) <br>        b = int(request.form[&#39;b&#39;]) <br>        rgb_value = (r, g, b) <br>        color_name = rgb_to_color_name(rgb_value) <br>        return render_template(&#39;index.html&#39;, color_name=color_name)<br>     else: <br>        return render_template(&#39;index.html&#39;) <br>if __name__ == &#39;__main__&#39;: <br>    app.run(debug=True)</pre><p>The above route receives RGB values from the template and then converts them and then returns the color name to the template.</p><h3>Create template</h3><p>Inside the <strong>index.html</strong> file we created earlier insert the code below.</p><pre>&lt;!DOCTYPE html&gt; <br>&lt;html&gt; <br>&lt;head&gt; <br>&lt;title&gt;RGB to Color Name Converter&lt;/title&gt; <br>&lt;/head&gt; <br>&lt;body&gt; <br>&lt;style&gt; <br>div { text-align:center; } <br>&lt;/style&gt; <br>&lt;div&gt; <br>&lt;h1&gt;RGB to Color Name Converter&lt;/h1&gt; <br>&lt;/div&gt; <br>&lt;div&gt; <br>&lt;form method=&quot;POST&quot; action=&quot;/&quot;&gt; <br>&lt;label for=&quot;r&quot;&gt;R:&lt;/label&gt; <br>&lt;input type=&quot;number&quot; name=&quot;r&quot; id=&quot;r&quot; min=&quot;0&quot; max=&quot;255&quot; required&gt;&lt;br&gt;&lt;br&gt; <br>&lt;label for=&quot;g&quot;&gt;G:&lt;/label&gt; <br>&lt;input type=&quot;number&quot; name=&quot;g&quot; id=&quot;g&quot; min=&quot;0&quot; max=&quot;255&quot; required&gt;&lt;br&gt;&lt;br&gt; <br>&lt;label for=&quot;b&quot;&gt;B:&lt;/label&gt; <br>&lt;input type=&quot;number&quot; name=&quot;b&quot; id=&quot;b&quot; min=&quot;0&quot; max=&quot;255&quot; required&gt;&lt;br&gt;&lt;br&gt;<br> &lt;input type=&quot;submit&quot; value=&quot;Convert&quot;&gt; <br>&lt;/form&gt; &lt;/div&gt; <br>&lt;div&gt;<br> {% if color_name %} <br>&lt;h2&gt;Color Name: {{ color_name }}&lt;/h2&gt; <br>{% endif %} <br>&lt;/div&gt; <br>&lt;/body&gt; <br>&lt;/html&gt;</pre><h3>Run</h3><p>To run the app, open your terminal and enter the command below. After running the command below our application should be available at the address [ <a href="http://localhost:5000/"><strong>http://localhost:5000</strong></a> ]</p><pre>python3 app.py</pre><h3>Results</h3><p>Here is a screenshot of the finished application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3fxOVD4lkx3oYcRXzd9HqQ.png" /></figure><p>There you have it, Thanks for reading. Happy Coding.</p><p><em>Originally published at </em><a href="https://bytexplain.com/how-to-build-a-flask-rgb-to-color-name-app/"><em>https://bytexplain.com</em></a><em> on June 14, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=120aac4501de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Turn a Photo to a Sketch Using Python — bytexplain]]></title>
            <link>https://python.plainenglish.io/how-to-turn-a-photo-to-a-sketch-using-python-bytexplain-a8e0239dcdd7?source=rss-fd3da10eba26------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8e0239dcdd7</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[image-editing]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Bunny The Compiler]]></dc:creator>
            <pubDate>Mon, 08 May 2023 21:34:26 GMT</pubDate>
            <atom:updated>2023-05-29T16:29:33.401Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Turn a Photo to a Sketch Using Python — bytexplain</h3><p>/ <a href="https://bytexplain.com/category/python/">Python</a> / May 8, 2023</p><p>In this tutorial, we will be looking at how to convert a photo to a sketch using python. To do this we will use<a href="https://opencv.org/"> OpenCV </a>library as our image manipulation library.</p><p>Advertisements To begin run the command below on your terminal to install opencv.</p><pre>pip install opencv-python</pre><p>After installing OpenCV , create a folder called sketch and create a file called<strong> main.py</strong> . Insert the photo you want to convert into the folder.</p><p>Now let’s code our program, inside the <strong>main.py</strong> import opencv as shown below.</p><p>Now let’s load our image.</p><pre>img = cv2.imread(&#39;sample.jpg&#39;)</pre><p><strong>See also </strong><a href="https://bytexplain.com/how-to-build-a-loan-calculator-web-app-using-python/">https://bytexplain.com/how-to-build-a-loan-calculator-web-app-using-python/</a></p><p>Next convert the loaded image into a gray scale</p><pre>gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)</pre><p>Invert the grayscale image to create a negative image.</p><pre>inverted_gray_img = 255 - gray_img</pre><p>Advertisements Here we will apply a gaussian blur to the inverted grayscale image</p><pre>blurred_img = cv2.GaussianBlur(inverted_gray_img, (21, 21), 0)</pre><p>Now let’s blend the inverted image and the blurred image.</p><pre>def dodgeV2(image, mask): return cv2.divide(image, 255-mask, scale=256) sketch_img = dodgeV2(gray_img, blurred_img) cv2.imshow(&#39;Original Image&#39;, img) cv2.imshow(&#39;Pencil Sketch&#39;, sketch_img) cv2.waitKey(0) cv2.destroyAllWindows()</pre><p>Now run the code as shown below.</p><pre>python3 main.py</pre><p>After running the command above, here is our sketch image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/0*70zv68xHyu99iycg.png" /></figure><p>Advertisements Here is the whole code.</p><pre>import cv2 img = cv2.imread(&#39;sample.jpg&#39;) gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) inverted_gray_img = 255 - gray_img blurred_img = cv2.GaussianBlur(inverted_gray_img, (21, 21), 0) def dodgeV2(image, mask): return cv2.divide(image, 255-mask, scale=256) sketch_img = dodgeV2(gray_img, blurred_img cv2.imshow(&#39;Original Image&#39;, img) cv2.imshow(&#39;Pencil Sketch&#39;, sketch_img) cv2.waitKey(0) cv2.destroyAllWindows()</pre><p>There you have it, thanks for reading. Happy Coding.</p><p><em>Originally published at </em><a href="https://bytexplain.com/how-to-turn-a-photo-to-a-sketch-using-python/"><em>https://bytexplain.com</em></a><em> on May 8, 2023.</em></p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>.</em></p><p><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8e0239dcdd7" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/how-to-turn-a-photo-to-a-sketch-using-python-bytexplain-a8e0239dcdd7">How to Turn a Photo to a Sketch Using Python — bytexplain</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[How to Build a Qrcode Generator Using Django — bytexplain]]></title>
            <link>https://blog.devgenius.io/how-to-build-a-qrcode-generator-using-django-bytexplain-bcbffbe55e32?source=rss-fd3da10eba26------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcbffbe55e32</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[qrcodegenerator]]></category>
            <category><![CDATA[qr-code]]></category>
            <dc:creator><![CDATA[Bunny The Compiler]]></dc:creator>
            <pubDate>Tue, 02 May 2023 20:09:46 GMT</pubDate>
            <atom:updated>2023-05-14T11:42:19.361Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Build a Qrcode Generator Using Django — bytexplain</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c7LwGIrzoP9s7ga7.png" /></figure><h3>Introduction</h3><p>A QR code or rather Quick Response code, is a two-dimensional barcode that can be scanned using a smartphone or a dedicated QR code reader. It is commonly used in marketing and product labeling. In this tutorial, we will create a <a href="https://www.djangoproject.com/">Django</a> app that requests a URL or a link and turns it into a QR code.</p><h3>Modules</h3><p>Advertisements To begin with this project we first need to install a few libraries one is Django, which will be used to build the basic web server and the next is the <a href="https://pypi.org/project/qrcode/">qrcode</a> library responsible for generating the QR code. To install the above modules run the commands below on your terminal.</p><pre>pip3 install django pip3 install qrcode</pre><p>After installing the modules above now let’s create our Django project. To create the Django app run the command below in your terminal.</p><pre>django-admin startproject django_qrcode</pre><p>The above command will create a folder called <strong>django_qrcode</strong>, now cd into the folder, and then run the command below.</p><pre>python3 manage.py startapp qr</pre><p>Now that will create an app called <strong>qr</strong>. Inside the <strong>django_qrcode </strong>folder find the <strong>settings.py </strong>file and add the following to the installed apps list.</p><pre>INSTALLED_APPS = [ &#39;django.contrib.admin&#39;, &#39;django.contrib.auth&#39;, &#39;django.contrib.contenttypes&#39;, &#39;django.contrib.sessions&#39;, &#39;django.contrib.messages&#39;, &#39;django.contrib.staticfiles&#39;, &#39;qr&#39;, ]</pre><p>Now add the following routes inside the <strong>urls.py</strong> file.</p><pre>from django.contrib import admin from django.urls import path,include urlpatterns = [ path(&#39;admin/&#39;, admin.site.urls), path(&#39;&#39;,include(&#39;qr.urls&#39;)), ]</pre><p>Now we need to create the view for our app. Inside the <strong>qr</strong> folder add the following in the <strong>views.py</strong> file.</p><pre>from django.shortcuts import render import qrcode from io import BytesIO from django.core.files import File import base64 def index(request): url = request.POST.get(&#39;url&#39;) img = qrcode.make(url) buffer = BytesIO() img.save(buffer) buffer.seek(0) img_str = base64.b64encode(buffer.read()).decode() return render(request, &#39;qr/index.html&#39;, {&#39;img_str&#39;: img_str})</pre><p>The above code takes a URL from a html template and then uses the qrcode module which makes a unique qrcode. The image is then rendered to the frontend in a template called <strong>index.html</strong>.</p><p>Advertisements Next, we need to create routes for our app, in the <strong>qr</strong> folder create a files called <strong>urls.py</strong>. Inside this file add the code below.</p><pre>from django.urls import path from . import views urlpatterns = [ path(&#39;&#39;, views.index, name=&#39;index&#39;), ]</pre><p>Now we need to make our templates, inside the <strong>qr</strong> folder, create a folder called <strong>templates</strong> and inside the <strong>templates</strong> folder create a file called<strong> index.html.</strong> Inside the <strong>index.html</strong> file add the following.</p><pre>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;{% block title %}{% endblock %}&lt;/title&gt; &lt;meta charset=&quot;utf-8&quot;&gt; &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt; &lt;link rel=&quot;stylesheet&quot; href=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css&quot;&gt; &lt;script src=&quot;https://code.jquery.com/jquery-3.3.1.slim.min.js&quot;&gt;&lt;/script&gt; &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js&quot;&gt;&lt;/script&gt; &lt;script src=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js&quot;&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div class=&quot;container&quot;&gt; &lt;h1&gt;Generate QR Code&lt;/h1&gt; &lt;form method=&quot;post&quot;&gt; {% csrf_token %} &lt;div class=&quot;form-group&quot;&gt; &lt;label for=&quot;url&quot;&gt;Enter Your Url&lt;/label&gt; &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;url&quot; name=&quot;url&quot; placeholder=&quot;Enter URL here &quot;&gt; &lt;/div&gt; &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Generate&lt;/button&gt; &lt;/form&gt; {% if img_str %} &lt;img src=&quot;data:image/png;base64,{{ img_str }}&quot; alt=&quot;QR Code&quot;&gt; {% endif %} &lt;/div&gt; &lt;/body&gt; &lt;/html&gt;</pre><p>The above code takes a URL and is submitted to the backend and then the image produced is rendered.</p><p>Advertisements Now we have finished, to run the project open the terminal and run the code below.</p><pre>python3 manage.py runserver</pre><p>The command above will fire up the server and now you can access the app using the URL below.</p><pre>http://127.0.0.1:8000</pre><p>Open the browser and enter the address above and here are the results below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*B2yiOZXSjK3lYbnL.png" /></figure><p>There you have it, play around with the app and generate QR codes. Thanks for reading.</p><p><em>Originally published at </em><a href="https://bytexplain.com/how-to-build-a-qrcode-generator-using-django/"><em>https://bytexplain.com</em></a><em> on May 2, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcbffbe55e32" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/how-to-build-a-qrcode-generator-using-django-bytexplain-bcbffbe55e32">How to Build a Qrcode Generator Using Django — bytexplain</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Rebuilt my Django App with Flask]]></title>
            <link>https://python.plainenglish.io/how-i-rebuilt-my-django-app-with-flask-a425baddd67a?source=rss-fd3da10eba26------2</link>
            <guid isPermaLink="false">https://medium.com/p/a425baddd67a</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[geocoding-map]]></category>
            <dc:creator><![CDATA[Bunny The Compiler]]></dc:creator>
            <pubDate>Thu, 07 Apr 2022 07:17:48 GMT</pubDate>
            <atom:updated>2022-04-16T19:02:56.325Z</atom:updated>
            <content:encoded><![CDATA[<h3>How I rebuilt my Django App with Flask</h3><h4>Rebuilding a Django app with Flask.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F-T8lmhWyET8jQaM2uCXtQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@photohunter?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jimmy Chang</a> on <a href="https://unsplash.com/s/photos/construct?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>A while ago I made a Django app that you can use to search the latitude and longitude of any location and vice versa. If you need to look at it here is the link.</p><p><a href="https://blog.devgenius.io/django-location-lookup-app-a2608d11fab4">Django Location LookUp app</a></p><p>In this tutorial, I decided to rebuild it entirely with Flask instead and also to enhance the user experience to my very best. Here are a few screenshots of the final app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*shbORBC-thPSemC3wiNYNw.png" /><figcaption>home page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hRNnY90FE7px1QyAIG8ODg.png" /><figcaption>street search</figcaption></figure><p>Enough of the intro. For this project, we will need a few Python libraries.</p><p><strong>Requirements</strong></p><ol><li>Flask</li><li>Geopy</li></ol><p>To install run pip3 install &lt;package name&gt;</p><p>After the installation, now let’s create a few files and folders. Here is the tree structure of the entire project.</p><pre>├── app.py</pre><pre>├── static</pre><pre>│   ├── images</pre><pre>│   │   ├── background.jpeg</pre><pre>│   │   └── logo.png</pre><pre>│   └── style.css</pre><pre>└── templates</pre><pre>├── base.html</pre><pre>├── coord.html</pre><pre>├── index.html</pre><pre>└── street.html</pre><p>First, begin by creating a folder flask-location you can name it anything. Inside the folder create two folders templates and static the templates folder will hold our HTML files as illustrated in the tree above and the static folder will hold the CSS file and some images for the background and logo.</p><p>In this project, we are using the Geopy library which helps with geocoding capabilities such as transforming a street name into accurate coordinates and vice-versa.</p><p>We will create two functions one that converts a street name to the approximate coordinate, the other one takes coordinates and returns an approximate location i.e., street, city, etc.</p><p>Inside the flask-location folder, create a file app.py . Inside let’s import a few libraries.</p><pre>from flask import Flask<br>from flask import render_template, redirect, request<br>from geopy.geocoders import Nominatim</pre><pre>import time</pre><pre>app = Flask(__name__)<br>pop = Nominatim(user_agent=&quot;google&quot;)</pre><p>Let’s first begin with search by street name functionality. Inside the app.py file create this function.</p><pre>def location_by_address(address):    <br>    time.sleep(1)    <br>    try:        <br>        return pop.geocode(address).raw   <br>    except:       <br>        return location_by_address(address)</pre><p>Now let’s create a view for this search functionality.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/852bcd02144e43c3a86ce031d1413dcf/href">https://medium.com/media/852bcd02144e43c3a86ce031d1413dcf/href</a></iframe><p>Next, we need to create a template for our street search. Inside the street.html file we created at the beginning, add the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c71d9f108e8a02ea01a67bdab83cf8f/href">https://medium.com/media/7c71d9f108e8a02ea01a67bdab83cf8f/href</a></iframe><p>We now need to move on to our next functionality which is the reverse of the street search. This is the coordinates search, just enter the coordinates and you will get the street name or city.</p><p>First, create a function that will convert the coordinates. Inside the app.py file, insert the following.</p><pre>def address_by_location(latitude, longitude):    <br>    cordinates = f&quot;{latitude},{longitude}&quot;    <br>    time.sleep(1)   <br>    try:       <br>        return pop.reverse(cordinates, language=&quot;en&quot;)    <br>    except:        <br>        return address_by_location(latitude, longitude)</pre><p>Next is the coordinates view:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56821c3c842f27a187ec6001c583f964/href">https://medium.com/media/56821c3c842f27a187ec6001c583f964/href</a></iframe><p>As described above the view takes value from the frontend and they are later passed on to the function. Here is the template for the coordinates search.</p><p>coord.html</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8282434cad1211f872a4c0ec9c8b6f89/href">https://medium.com/media/8282434cad1211f872a4c0ec9c8b6f89/href</a></iframe><p>Now we need to make a view for our home page.</p><pre>@app.route(&#39;/&#39;)<br>def index():    <br>    return render_template(&#39;index.html&#39;)</pre><p>And now finally the template for the home page.</p><p>index.html</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9669a679d7249fdb166938519f919cf9/href">https://medium.com/media/9669a679d7249fdb166938519f919cf9/href</a></iframe><p>Finally, in the app.py file add the following:</p><pre>if __name__ == &quot;__main__&quot;:    <br>    app.run(debug=True)</pre><p>All our templates are inherited from the base.html template which contains the basic layout of our website.</p><p>Now it’s time to fire up our website. Open your terminal in the same directory as the project and run python3 app.py . This should start a Flask server. Now open your browser and enter the URL. Here is our home page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*shbORBC-thPSemC3wiNYNw.png" /></figure><p>Here is the street search:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hRNnY90FE7px1QyAIG8ODg.png" /></figure><p>Thanks for reading. Stay tuned for more. Here is the source code<strong>:</strong></p><p><a href="https://github.com/bunnythecompiler/flask-location-lookup">GitHub - bunnythecompiler/flask-location-lookup: a flask location lookup app</a></p><p><em>More content at</em><strong><em> </em></strong><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a><em> and </em><a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>. Join our </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>community Discord</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a425baddd67a" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/how-i-rebuilt-my-django-app-with-flask-a425baddd67a">How I Rebuilt my Django App with Flask</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[Let’s edit videos with python]]></title>
            <link>https://blog.devgenius.io/lets-edit-videos-with-python-67d6d9f56ad3?source=rss-fd3da10eba26------2</link>
            <guid isPermaLink="false">https://medium.com/p/67d6d9f56ad3</guid>
            <category><![CDATA[videos]]></category>
            <category><![CDATA[moviepy]]></category>
            <category><![CDATA[video-editing]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Bunny The Compiler]]></dc:creator>
            <pubDate>Thu, 24 Mar 2022 06:45:29 GMT</pubDate>
            <atom:updated>2022-03-24T06:45:29.786Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kFduULO-6R1hQN8pFV6QnA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@onurbinay?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Onur Binay</a> on <a href="https://unsplash.com/s/photos/video-editing?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In this tutorial we will be editing videos using python. We will be leveraging <strong>moviepy </strong>library to edit all our videos. Here is a list of the techniques we will be using for this tutorial.</p><ol><li>Extract a clip from a video</li><li>Stacking videos</li><li>Concatenating videos</li><li>Creating margins in video stacks whilst resizing</li><li>Extract images from a video</li><li>Rotate a video clip</li><li>Extract audio from a video</li><li>Mask a video with an audio</li><li>Create a gif from a video</li></ol><p><strong>Requirements</strong></p><ol><li>python</li><li>moviepy</li></ol><p>To install these packages run pip3 install &lt;package name&gt;</p><ol><li><strong>Extract a clip from a video</strong></li></ol><p>To extract a clip from a video specify the time frame you want inside the subclip function. After extracting the clip you will need to write it to a new file</p><pre>from moviepy.editor import *</pre><pre>clip = VideoFileClip(&#39;snow.mp4&#39;).subclip(12,20)<br>clip.write_videofile(&quot;edited.mp4&quot;)</pre><p>2. <strong>Stacking videos</strong></p><p>Do you need to stack videos together like in a cctv monitor? Check this code out.</p><pre>from moviepy.editor import *</pre><pre>clip1 = VideoFileClip(&#39;snow.mp4&#39;).subclip(4,16)<br>clip2 = VideoFileClip(&#39;clouds.mp4&#39;)<br>clip3 = VideoFileClip(&#39;city.mp4&#39;)<br>clip4 = VideoFileClip(&#39;underwater.mp4&#39;)<br>final_clip = clips_array([<br>    [clip1,clip2],<br>    [clip3,clip4]<br>])<br>final_clip.resize(width=480).write_videofile(&#39;my_stack.mp4&#39;)</pre><p>Here is the output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u2r7EIGJ7pM0h9ye6fAYuA.png" /></figure><p>3. <strong>Concatenate videos</strong></p><p>Concatenating videos means joining several videos together in that when one clip stops playing the other starts immediately.</p><pre>from moviepy.editor import *</pre><pre>clip1 = VideoFileClip(&#39;snow.mp4&#39;).subclip(4,16)<br>clip2 = VideoFileClip(&#39;clouds.mp4&#39;)<br>clip3 = VideoFileClip(&#39;city.mp4&#39;)<br>final_clip = concatenate_videoclips([clip1,clip2,clip3])<br>final_clip.write_videofile(&#39;my_concate.mp4&#39;)</pre><p>4.<strong> Creating margins in video stacks whilst resizing</strong></p><p>Previously we made a stack , here we will be adding a margin between each video in the stack and also resize the last video in the array.</p><pre>from moviepy.editor import *</pre><pre>clip1 = VideoFileClip(&#39;snow.mp4&#39;).subclip(4,16).margin(10)<br>clip2 = VideoFileClip(&#39;clouds.mp4&#39;)<br>clip3 = VideoFileClip(&#39;city.mp4&#39;)<br>clip4 = VideoFileClip(&#39;underwater.mp4&#39;).resize(0.60) #downsize 60%<br>final_clip = clips_array([<br>    [clip1,clip2],<br>    [clip3,clip4]<br>])<br>final_clip.resize(width=480).write_videofile(&#39;my_advanced_stack.mp4&#39;)</pre><p>We have added a margin of 10 pixels and resized the last video to 60%</p><p>Here is the output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cRizuoYBhR4GED0ErEKyeg.png" /></figure><p><strong>5.Extract an image from a video</strong></p><p>First load the video and then use the save_frame function to capture the frame then specify the filename</p><pre>from moviepy.editor import *</pre><pre>clip = VideoFileClip(&#39;snow.mp4&#39;)<br>clip.save_frame(&#39;snow.jpeg&#39;)<br></pre><p><strong>6. Rotate a clip</strong></p><pre>from moviepy.editor import *</pre><pre>clip = VideoFileClip(&#39;snow.mp4&#39;).rotate(270)<br>clip.write_videofile(&#39;rotated.mp4&#39;)</pre><p>This will rotate the video to 270 degrees</p><p><strong>7. Extract audio from a video</strong></p><pre>from moviepy.editor import *</pre><pre>clip = VideoFileClip(&#39;underwater.mp4&#39;)<br>audioclip = clip.audio<br>audioclip.write_audiofile(&#39;underwater.mp3&#39;)</pre><p><strong>8. Mask a video with another audio</strong></p><p>Here we will mask a video with a new audio</p><pre>from moviepy.editor import * </pre><pre>my_audioclip = AudioFileClip(&#39;underwater.mp3&#39;)<br>videoclip = VideoFileClip(&#39;snow.mp4&#39;)<br>videoaudio = videoclip.set_audio(my_audioclip)<br>videoaudio.write_videofile(&#39;videowithaudio.mp4&#39;)</pre><p><strong>9. Create a gif</strong></p><pre>from moviepy.editor import *<br>clip = VideoFileClip(&#39;city.mp4&#39;)<br>clip.write_gif(&#39;city.gif&#39;,fps=2)</pre><p>Here is the output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*Ixgz5sOfCvB-ew2Y5grkfQ.gif" /></figure><p><strong>The End</strong></p><p>Moviepy contains more complex functions most of which i could not cover in this tutorial. You can check the library <a href="https://moviepy.readthedocs.io/en/latest/"><strong>here</strong></a><strong>. </strong>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67d6d9f56ad3" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/lets-edit-videos-with-python-67d6d9f56ad3">Let’s edit videos with python</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a book audit web app with python]]></title>
            <link>https://medium.com/codex/building-a-book-audit-web-app-with-python-e118e749f03a?source=rss-fd3da10eba26------2</link>
            <guid isPermaLink="false">https://medium.com/p/e118e749f03a</guid>
            <category><![CDATA[review]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[books]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Bunny The Compiler]]></dc:creator>
            <pubDate>Mon, 21 Mar 2022 01:48:47 GMT</pubDate>
            <atom:updated>2022-03-21T01:48:47.027Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oqapYUlTiMY1XrURBdIGbQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@anthonytran?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Anthony Tran</a> on <a href="https://unsplash.com/s/photos/book-audit?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In this tutorial we will be building a book review web app. Users can join and rate books uploaded by the admin.</p><p>We will be building our app using django. Here is a screenshot of our final web app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WfG-NaDdsiKopoKYN2cPaw.png" /><figcaption>home page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rTdJhI8Ja8Tl4mNwkIg-dw.png" /><figcaption>review page</figcaption></figure><p>Basic functionalities include leaving a comment and giving a star rating of between 1 to 5. More features coming soon.</p><p><strong>Requirements</strong></p><ol><li>django</li></ol><p>pip3 install django to install it</p><p><strong>Project setup</strong></p><p>To begin we first need to create our project which will house our django app.Run django-admin startproject book_review .Cd into the folder created book_review .Run python3 manage.py startapp book which will create an app called book</p><p>Let’s configure our project , in the settings.py add our app into the installed_apps list. Add the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49510a962c742683677802922b2d48b7/href">https://medium.com/media/49510a962c742683677802922b2d48b7/href</a></iframe><p>Our app will need to store media files such as the book cover images. To do this we need to provide a path to our files .Add the following still in the settings.py</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e887dbf7d2f4640bc649fbc0d2fe93ee/href">https://medium.com/media/e887dbf7d2f4640bc649fbc0d2fe93ee/href</a></iframe><p><strong>Project routes</strong></p><p>We need to create routes for our main project. In the book_review/urls.py add the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/880f1485c3a8ada19a8d3c9d3eafb457/href">https://medium.com/media/880f1485c3a8ada19a8d3c9d3eafb457/href</a></iframe><p>It’s time to move on to our main app. We first need a few models , one is for the book to be reviewed and the next model is for the review.</p><p>Our book model will have a title, book description, a book cover and finally a book cover image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4db050200fcce65961bba9672c9e9d94/href">https://medium.com/media/4db050200fcce65961bba9672c9e9d94/href</a></iframe><p>For the review model we will have the following a user, review_date, a stars slot and a comment slot.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d2084354274476a4dc8fc114f1accd0/href">https://medium.com/media/9d2084354274476a4dc8fc114f1accd0/href</a></iframe><p>Now let’s create our models to do this run python3 manage.py makemigrations this will create tables as defined by our models , next run python3 manage.py migrate this will migrate the data. We still need to create a superuser who will be responsible for uploading books to be reviewed. To create a superuser run python3 manage.py createsuperuser you will be asked to fill in your username, email and a secret password.</p><p>Enough with models and admin setup , we now need to create a review form which our users will have to fill while rating our book. In the book/forms.py add the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71c2ca4e03fb9c67283f05d0724f293c/href">https://medium.com/media/71c2ca4e03fb9c67283f05d0724f293c/href</a></iframe><p>Now we need our admin to recognize our models , in the book/admin.py let’s register our models</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b6257356035a11b1dbc1c96df9422a6/href">https://medium.com/media/2b6257356035a11b1dbc1c96df9422a6/href</a></iframe><p>Our app is now coming up together. Let’s move to our views. First we need a view to list the book we need to get reviewed. In the book/views.py add the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b4b961159197338dd9df5672a77808d/href">https://medium.com/media/6b4b961159197338dd9df5672a77808d/href</a></iframe><p>Create a template for the home page. In the book/templates/book/home.html add the following.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba56fb485a74d231e929eeb50e3b2d40/href">https://medium.com/media/ba56fb485a74d231e929eeb50e3b2d40/href</a></iframe><p><strong>Routes</strong></p><p>Create a file book/urls.py which will hold our routes . Inside add the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c94e3daae922be4d7263aa87bc5f9655/href">https://medium.com/media/c94e3daae922be4d7263aa87bc5f9655/href</a></iframe><p>To see the progress in our app we first need to run our server. Run python3 manage.py runserver . In your browser go to <a href="http://127.0.0.1:8000/admin">http://127.0.0.1:8000/admin</a> and login with the credentials you created in the<strong> createsuperuser </strong>step . In the book slot add the book as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KnlWx4T6JdJ5yMeehd7vHw.png" /></figure><p>Add your book and go back to your home page route you should see something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WfG-NaDdsiKopoKYN2cPaw.png" /></figure><p><strong>Review functionality</strong></p><p>In the book/views.py add the following.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57f473cc4bdd2c2a77f339d1baa3bd20/href">https://medium.com/media/57f473cc4bdd2c2a77f339d1baa3bd20/href</a></iframe><p>Here is the correspondent template in book/rev.html</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fe7edbfce1d387e8acd0d4d41ee0e9c/href">https://medium.com/media/9fe7edbfce1d387e8acd0d4d41ee0e9c/href</a></iframe><p><strong>Success Redirect</strong></p><p>After a successful review we need to redirect our user to a success page . Here is the view and its template</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1859f8ed2747b43a60c2a24185e27f3/href">https://medium.com/media/c1859f8ed2747b43a60c2a24185e27f3/href</a></iframe><p>book/templates/book/success.html</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/274945e91099464fa5abc275d9f7a8d6/href">https://medium.com/media/274945e91099464fa5abc275d9f7a8d6/href</a></iframe><p><strong>Final routes</strong></p><p>Now we need to create routes for our remaining functionalities. Here is our final book/urls.py file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94a23b29d41057e829552f0f06a6645f/href">https://medium.com/media/94a23b29d41057e829552f0f06a6645f/href</a></iframe><p>Now run your server. Do a few reviews and log in to your admin an see the progress in the reviews dashboard. Here is my reviews dashboard</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uLFwvOPshA8W4h7jyMRuNA.png" /></figure><p>Thanks for reading . Feel free to contribute to the project. Here is the <a href="https://github.com/bunnythecompiler/book_review"><strong>source code</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e118e749f03a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/building-a-book-audit-web-app-with-python-e118e749f03a">Building a book audit web app with python</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a spotify knock-off with python]]></title>
            <link>https://blog.devgenius.io/building-a-spotify-knock-off-with-python-dca5f3fe0d5c?source=rss-fd3da10eba26------2</link>
            <guid isPermaLink="false">https://medium.com/p/dca5f3fe0d5c</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[spotify]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[streaming]]></category>
            <dc:creator><![CDATA[Bunny The Compiler]]></dc:creator>
            <pubDate>Sun, 20 Mar 2022 17:51:42 GMT</pubDate>
            <atom:updated>2023-01-24T20:01:52.393Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wpif-KSGfEovM8TE-tmjRg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@thibaultpenin?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Thibault Penin</a> on <a href="https://unsplash.com/s/photos/spotify?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Spotify is the largest music streaming service as of 2022. In this tutorial i will be building a knock-off of it using django.</p><p><strong>DISCLAIMER!!! The ui is not that appealing. We have limited functionalities for this project. More features coming soon.</strong></p><figure><a href="https://bytexplain.com/how-to-build-a-fruit-classifier-app-using-flask/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mOX5Q-vy_3jHWWMSQQyeaQ.png" /></a></figure><figure><a href="https://bytexplain.com/how-to-build-a-flask-joke-generator/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mpcZAOpBUJiLlZ7srVJDwA.png" /></a></figure><figure><a href="https://bytexplain.com/how-to-build-a-password-generator-using-python/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SuLVv_ktD1gggYX9xWUeXQ.png" /></a></figure><p>Here are a few screenshots our final product.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zEoz0JMM3v24VKqGnEifxw.png" /><figcaption>registration page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mSbR4J73IcPF3PSfJM-UEg.png" /><figcaption>home page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BZW28lvu1vsUUpj4VaMmWQ.png" /></figure><p><strong>App Features</strong></p><ol><li>User authentication and authorization</li><li>Music Upload</li><li>Music Stream</li><li>etc</li></ol><p><strong>Requirements</strong></p><ol><li>django</li><li>python</li></ol><p>To install django run pip3 install &lt;django&gt;</p><p><strong>Project setup</strong></p><p>Let’s begin by setting up our project.Make sure django is installed. Run django-admin startproject spotify_django This will create a folder spotify_django Cd into the spotify_django folder and run python3 manage.py startapp spotify</p><p>In the settings.py file add the following in the installed_apps list</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fa26f31ed1937189e61b1e33a4b27d0/href">https://medium.com/media/7fa26f31ed1937189e61b1e33a4b27d0/href</a></iframe><p>For our app to be able to store and retrieve media files such as cover_photos and audio we need to set the path and location from which they will be accessed from. In the settings.py file add the following.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f02012cce9f7e42b6c16399b9b613c02/href">https://medium.com/media/f02012cce9f7e42b6c16399b9b613c02/href</a></iframe><p>In the same folder add the following in the urls.py file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee473bde892f193cb1dc7e90126dfcb0/href">https://medium.com/media/ee473bde892f193cb1dc7e90126dfcb0/href</a></iframe><p>Here we have included the routes for our app and also set the route for our static media files.</p><p><strong>Models creation</strong></p><p>Let’s create some models for our app. In the models.py add the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be6844335995a99f60a0d5949895ee20/href">https://medium.com/media/be6844335995a99f60a0d5949895ee20/href</a></iframe><p>Our app will have to take in a user , a song author who will be created by the registered user, a song title,image and audio file to be uploaded. A date of audio upload will also be created.</p><p><strong>Authentication</strong></p><p>We need to create our signup, login, logout functionalities before proceeding with our project. Let’s create our registration form.</p><p>In the forms.py file add the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2371dd9ce4a79f30e4d4d047bea6f704/href">https://medium.com/media/2371dd9ce4a79f30e4d4d047bea6f704/href</a></iframe><p>Here is the view for the registration functionality. In the views.py add the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b8a63c2262ec6fa805f7905b1e302af/href">https://medium.com/media/2b8a63c2262ec6fa805f7905b1e302af/href</a></iframe><p>Finally the template for the registration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d47be363c9ce3b9a94b2799c3fde398/href">https://medium.com/media/6d47be363c9ce3b9a94b2799c3fde398/href</a></iframe><p><strong>Login functionality</strong></p><p>Let’s create a view for our login functionality. Still in the views.py file add the following ;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94cab777126b58305bd7440b99c2ef8e/href">https://medium.com/media/94cab777126b58305bd7440b99c2ef8e/href</a></iframe><p>And now our template spotify/login.html</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abcb984b12debee584a2cc8fb4a7f9b8/href">https://medium.com/media/abcb984b12debee584a2cc8fb4a7f9b8/href</a></iframe><p><strong>Logout</strong></p><p>After our user has logged in we still need a way to leave the session safely. To do this we create a logout view. Still in the views.py file add the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f3c09c190d5d266a1b70359e84aac63/href">https://medium.com/media/0f3c09c190d5d266a1b70359e84aac63/href</a></iframe><p><strong>Create a song</strong></p><p>Here we will create our song. A song image , author or publisher and finally the audio file to be shared will be created here. To begin, let’s first create a view. We will be using a class based view. In the spotify/views.py add the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38356d03b43b53427ab0de972777a142/href">https://medium.com/media/38356d03b43b53427ab0de972777a142/href</a></iframe><p>We have added a loginrequiredmixin mixin which means that only a logged in user can upload a song.</p><p>Here is it corresponding template spotify/song-create.html</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3f3b8f455ef2ec7881551f7108646f6/href">https://medium.com/media/b3f3b8f455ef2ec7881551f7108646f6/href</a></iframe><p><strong>Home Page</strong></p><p>Now it’s time to display all songs that have been uploaded in the platform. Here is our view in spotify/views.py</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38cd5d330358705600d18ad1529c3c38/href">https://medium.com/media/38cd5d330358705600d18ad1529c3c38/href</a></iframe><p>The template too at spotify/home.html</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2f283c74e41b9c8f7b994e6711fc065/href">https://medium.com/media/e2f283c74e41b9c8f7b994e6711fc065/href</a></iframe><p><strong>Play Audio</strong></p><p>Now we need to play our selected audio. Here is our view still in the views.py file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b24f9fe087a9620c132261755800c530/href">https://medium.com/media/b24f9fe087a9620c132261755800c530/href</a></iframe><p>And finally it’s template spotify/playSong.html</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4042e3b1c7313c60b949103b0f7573a/href">https://medium.com/media/f4042e3b1c7313c60b949103b0f7573a/href</a></iframe><p><strong>Routes</strong></p><p>Our app needs to have some routes. To create them first create a file urls.py file in the same directory as the views and models add the following lines in it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9805b01d89a6049e5f17774343c42190/href">https://medium.com/media/9805b01d89a6049e5f17774343c42190/href</a></iframe><p><strong>Final Touches</strong></p><p>To make our admin page convenient in laying the songs uploaded we need to configure our admin.py file by adding the following.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d7a9e72b7701610eb038e87db37fd69/href">https://medium.com/media/7d7a9e72b7701610eb038e87db37fd69/href</a></iframe><p><strong>Finalizing</strong></p><p>Now run python3 manage.py makemigrations to make the tables. The python3 manage.py migrate to migrate the data. Now run python3 manage.py runserver Open your browser and enter the url <a href="http://127.0.0.1:8000/">http://127.0.0.1:8000</a></p><p>You are good to go. Create your account, login and share the fun. Here are a few screenshots of our finished product</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zEoz0JMM3v24VKqGnEifxw.png" /><figcaption>registration page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mSbR4J73IcPF3PSfJM-UEg.png" /><figcaption>home page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BZW28lvu1vsUUpj4VaMmWQ.png" /><figcaption>song on play mode</figcaption></figure><p>I admit the app has a long way to go , let me know what you think. Thanks for reading. You can also contribute to the project .Here is the <a href="https://github.com/bunnythecompiler/spotify_django"><strong>source code</strong></a><strong> .</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dca5f3fe0d5c" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/building-a-spotify-knock-off-with-python-dca5f3fe0d5c">Building a spotify knock-off with python</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s build a movie review django app]]></title>
            <link>https://blog.devgenius.io/lets-build-a-movie-review-django-app-47658f8e3751?source=rss-fd3da10eba26------2</link>
            <guid isPermaLink="false">https://medium.com/p/47658f8e3751</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Bunny The Compiler]]></dc:creator>
            <pubDate>Mon, 07 Mar 2022 13:38:33 GMT</pubDate>
            <atom:updated>2023-05-18T19:10:11.044Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a django based web app used to review movies by leaving a comment and giving a star rating.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rbc0ZDSPxVhxXooLRSUyJA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@nik1toss?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Nikita Katsevich</a> on <a href="https://unsplash.com/s/photos/tech?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Before we begin with our tutorial here are a few screenshots of our app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DVYuJgF23l8nLO8wah36vA.png" /><figcaption>home page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZF07FB1i7RJbl2R4gmAXTg.png" /><figcaption>rate page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uM6XJIRMa-JBPX4rZJzoBQ.png" /><figcaption>admin dashboard</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KN2vkjqsAub99ffpgR_PFQ.png" /><figcaption>admin dashboard showing a review</figcaption></figure><p>How this app works is that the admin uploads a movie title, description,cover image and the users then can leave a comment and a star rating to the respective movie.</p><p>Hope you now have a clue of what we will be building. To kick off we first need to install <strong>django .</strong>To install django run pip3 install django</p><p>Now let’s set up our django project. Type django-admin startproject movie_review .Movie_review is the name of our django project. Cd into the movie_review directory and run python3 manage.py startapp movie .This will create a django app called<strong> movie</strong>.</p><p>Next we need to configure our app, to do this append the following lines to the settings.py file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7b2f75e82ffbd225b6a69f6ea434fd1/href">https://medium.com/media/e7b2f75e82ffbd225b6a69f6ea434fd1/href</a></iframe><p>Next we need to configure routes for our app. Append the following lines to the movie_review/urls.py</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7565b73985c55da0bee6cb7d12ea3f8b/href">https://medium.com/media/7565b73985c55da0bee6cb7d12ea3f8b/href</a></iframe><p>In the movie_review/settings.py file append the following at the bottom. This is to help django locate images or rather static files</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f849004873925c78795a6f6236ea1170/href">https://medium.com/media/f849004873925c78795a6f6236ea1170/href</a></iframe><p>Now we can go to our main app. Let’s create some models. We will be having two models ,one is the movie and the other one is the review. Our review model will be having a many to one relationship with the movie. Here is our models.py</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2bcaefa24a92e58add464d32c57727f7/href">https://medium.com/media/2bcaefa24a92e58add464d32c57727f7/href</a></iframe><p>Now let’s create a form for our review model so as to collect some reviews from users. Create a file called forms.py</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bfc6601a01cb15aa8266404deb7155a/href">https://medium.com/media/8bfc6601a01cb15aa8266404deb7155a/href</a></iframe><p>Now let’s register our models so as to be accessed by the admin. In the admin.py file append the following.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8fe6bdec22e7fb0143c143a1edb0c19/href">https://medium.com/media/c8fe6bdec22e7fb0143c143a1edb0c19/href</a></iframe><p>Now let’s create our views. We will begin with our home view which will display the movie to be rated. Here is the view in the views.py file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19124848837bc94dbfcc1c14f8abc71a/href">https://medium.com/media/19124848837bc94dbfcc1c14f8abc71a/href</a></iframe><p>Now let’s create a template for our home functionality. Here is the home.html template</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1626f8cda48449a86fffeb414edce1a/href">https://medium.com/media/e1626f8cda48449a86fffeb414edce1a/href</a></iframe><p>It’s now time for our review view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/794ab49554c241d714610e15c49778d7/href">https://medium.com/media/794ab49554c241d714610e15c49778d7/href</a></iframe><p>After a user has finished reviewing a movie we need to redirect him to a success page. Here is the view for the success functionality.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3295d9d615afbbc0a13c4a0046ca6072/href">https://medium.com/media/3295d9d615afbbc0a13c4a0046ca6072/href</a></iframe><p>Here is its template, success.html</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6582a15fc93530828961adb3b7efc0af/href">https://medium.com/media/6582a15fc93530828961adb3b7efc0af/href</a></iframe><p>Now let’s create routes for our app. Create a file urls.py and append the following.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30c82314a355bad6aee2d79e8d593072/href">https://medium.com/media/30c82314a355bad6aee2d79e8d593072/href</a></iframe><p>Now we need to run some commands so as to create some tables for our app. To do this run python3 manage.py makemigrations . After that run successfully run python3 manage.py migrate. Now our tables are created successfully but we need to create a super user who will be the administrator and also responsible for uploading movies to be reviewed. To create the superuser run python3 manage.py createsuperuser . You will be asked to enter your username , email and password . After all is set now run python3 manage.py runserver .</p><p>Open your browser and enter <a href="http://127.0.0.1:8000/admin">http://127.0.0.1:8000/admin</a> . You will need to login with the credentials you used in creating the superuser. Now go to the Movie option and click on add movie and enter the movie you want users to review. You will need the movie title, description and the date of the movie upload but this will be done automatically as we defined in our models. You can now hit save.</p><p>Here is a picture of the process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L7489TaBNWRW4GOZgpmG8g.png" /><figcaption>movie upload</figcaption></figure><p>Now after uploading the movie go back to the home page and you should see something like this depending on the title of your upload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DVYuJgF23l8nLO8wah36vA.png" /><figcaption>home page</figcaption></figure><p>Now you can proceed to rate your movie like shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JluLB5VX8VYp8IEINcsV5w.png" /><figcaption>review page</figcaption></figure><p>That’s it for this tutorial . Thanks for reading . To get the source code click <a href="https://github.com/bunnythecompiler/movie_review"><strong>here</strong></a><strong> .</strong></p><h3>More Projects</h3><figure><a href="https://bytexplain.com/how-to-build-a-contact-app-using-django/"><img alt="django contact app" src="https://cdn-images-1.medium.com/max/1024/1*dnC9tAyMkGjynw64ydSOtA.png" /></a></figure><figure><a href="https://bytexplain.com/how-to-build-a-video-sharing-app-using-django/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mImHRXie5aYMACJ_tjt4pQ.png" /></a></figure><figure><a href="https://bytexplain.com/how-to-build-a-music-sharing-app-using-django/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ccUmI8VfYDmXwnkypV8XNg.png" /></a></figure><figure><a href="https://bytexplain.com/how-to-build-a-qrcode-generator-using-django/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ezDHQ2znWTNb3GDkD9M39w.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47658f8e3751" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/lets-build-a-movie-review-django-app-47658f8e3751">Let’s build a movie review django app</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django Location LookUp app]]></title>
            <link>https://blog.devgenius.io/django-location-lookup-app-a2608d11fab4?source=rss-fd3da10eba26------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2608d11fab4</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Bunny The Compiler]]></dc:creator>
            <pubDate>Sat, 26 Feb 2022 13:23:50 GMT</pubDate>
            <atom:updated>2022-02-26T15:54:08.962Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a django app to help you get the location of a certain street address ,city or any location on the planet earth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A2bbpPmmkl0nFJ5qRl5zMg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@tamas_tuzeskatai?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Tamas Tuzes-Katai</a> on <a href="https://unsplash.com/s/photos/map?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Here are a few screenshots of our final app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JIfj-qhBstLz4WmR7nM0LQ.png" /><figcaption>landing page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N2RrQA8HkqG8DhZmxzIPZA.png" /><figcaption>locating wall street</figcaption></figure><p>I was even curious enough to search the lat 0.0 long 0.0 to see what i would find out. Here is what i found out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iW3aeaZV9749lEu88i0tLw.png" /><figcaption>soul bouy</figcaption></figure><p>More about the soul bouy you can click <a href="https://en.wikipedia.org/wiki/Soul_Buoy"><strong>here</strong></a></p><p>Now let’s begin.</p><p><strong>Requirements</strong></p><ol><li>django</li><li>geopy</li></ol><p>To install these packages type pip3 install &lt;package name&gt;</p><p>Now lets’s begin run django-admin startproject django_location .Cd into the folder django_location .Now run python3 manage.py startapp location .Now let’s first add our app in the project settings.py</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/39d372a664c83f62dd3640f6ea37e011/href">https://medium.com/media/39d372a664c83f62dd3640f6ea37e011/href</a></iframe><p>Now let’s create routes for our app. Add the following in the project urls.py</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2f071a20dfe1cbd5ea4ab04415f4d99/href">https://medium.com/media/a2f071a20dfe1cbd5ea4ab04415f4d99/href</a></iframe><p>Now let’s move to our main app.First of all let’s see the tree for this folder.</p><p>├── admin.py</p><p>├── apps.py</p><p>├── __init__.py</p><p>├── migrations</p><p>│ ├── __init__.py</p><p>│ └── __pycache__</p><p>│ └── __init__.cpython-39.pyc</p><p>├── models.py</p><p>├── __pycache__</p><p>│ ├── admin.cpython-39.pyc</p><p>│ ├── __init__.cpython-39.pyc</p><p>│ ├── models.cpython-39.pyc</p><p>│ ├── urls.cpython-39.pyc</p><p>│ ├── utilities.cpython-39.pyc</p><p>│ └── views.cpython-39.pyc</p><p>├── static</p><p>│ ├── css</p><p>│ │ ├── bootstrap.css</p><p>│ │ ├── bootstrap.css.map</p><p>│ │ ├── bootstrap-grid.css</p><p>│ │ ├── bootstrap-grid.css.map</p><p>│ │ ├── bootstrap-grid.min.css</p><p>│ │ ├── bootstrap-grid.min.css.map</p><p>│ │ ├── bootstrap.min.css</p><p>│ │ ├── bootstrap.min.css.map</p><p>│ │ ├── bootstrap-reboot.css</p><p>│ │ ├── bootstrap-reboot.css.map</p><p>│ │ ├── bootstrap-reboot.min.css</p><p>│ │ ├── bootstrap-reboot.min.css.map</p><p>│ │ └── style.css</p><p>│ ├── images</p><p>│ │ └── maglens.jpg</p><p>│ └── js</p><p>│ ├── bootstrap.bundle.js</p><p>│ ├── bootstrap.bundle.js.map</p><p>│ ├── bootstrap.bundle.min.js</p><p>│ ├── bootstrap.bundle.min.js.map</p><p>│ ├── bootstrap.js</p><p>│ ├── bootstrap.js.map</p><p>│ ├── bootstrap.min.js</p><p>│ ├── bootstrap.min.js.map</p><p>│ └── jquery.min.js</p><p>├── templates</p><p>│ └── location</p><p>│ ├── base.html</p><p>│ ├── home.html</p><p>│ ├── index.html</p><p>│ └── landing.html</p><p>├── tests.py</p><p>├── urls.py</p><p>├── utilities.py</p><p>└── views.py</p><p>Now let’s first begin by search by street name functionality. Create a file called utilities.py Inside insert the following .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67d3993ba1443685dfa6f3ba41c4104c/href">https://medium.com/media/67d3993ba1443685dfa6f3ba41c4104c/href</a></iframe><p>Here we have imported the geopy library which helps with geocoding capabilities such as transforming a street name to accurate co-ordinates and vice-versa.</p><p>We have also added a time delay of one second so as to abide with OpenStreet Nominatim usage policy of a max of one request per second since it’s a free service. We have then created a function that will take an address or a street name and return a longitude and a latitude of the specific address.</p><p>Now let’s create a view for our search by street function</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c9200acdb768f10f00476edae4f191f/href">https://medium.com/media/3c9200acdb768f10f00476edae4f191f/href</a></iframe><p>Here is the template for the search by address function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8afe90a6e51351d0ad14a8ca63fb406/href">https://medium.com/media/e8afe90a6e51351d0ad14a8ca63fb406/href</a></iframe><p>Next we move to the search by co-ordinates function.</p><p>Inside the utilities.py add the following.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee258ae63db89edc0ca1d8b1c71ec746/href">https://medium.com/media/ee258ae63db89edc0ca1d8b1c71ec746/href</a></iframe><p>Now let’s create a view for search by co-ordinates function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e048bb9047668633d44002ffd440e09/href">https://medium.com/media/3e048bb9047668633d44002ffd440e09/href</a></iframe><p>Finally here is the template for the search by co-ordinates function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a3a5090c06e185fc05d17625f3e6dfa/href">https://medium.com/media/4a3a5090c06e185fc05d17625f3e6dfa/href</a></iframe><p>Now lets create a landing page for our app. Here is the view</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/035b4408c9919a7e3a351be0b4df5a69/href">https://medium.com/media/035b4408c9919a7e3a351be0b4df5a69/href</a></iframe><p>Let’s now add a template for our view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd25f88e1a261d197a51a5bcc943a7cd/href">https://medium.com/media/bd25f88e1a261d197a51a5bcc943a7cd/href</a></iframe><p>Now we have to create routes for our location app. Create a file called urls.py and add the following;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7555c9722e8580af2e80c02edde3d706/href">https://medium.com/media/7555c9722e8580af2e80c02edde3d706/href</a></iframe><p>Now to launch your app run python3 manage.py runserver , make sure you have an internet connection. Type the following http://127.0.0.1:8000in your browser and hit enter. Here is the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JIfj-qhBstLz4WmR7nM0LQ.png" /><figcaption>landing page</figcaption></figure><p>Now you can enter your address in the street search and search like shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N2RrQA8HkqG8DhZmxzIPZA.png" /></figure><p>Thanks for reading. Here is the source code <a href="https://github.com/bunnythecompiler/django_location"><strong>here</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2608d11fab4" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/django-location-lookup-app-a2608d11fab4">Django Location LookUp app</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s build a video sharing app with Django]]></title>
            <link>https://blog.devgenius.io/lets-build-a-video-sharing-app-with-django-dacde3660a7d?source=rss-fd3da10eba26------2</link>
            <guid isPermaLink="false">https://medium.com/p/dacde3660a7d</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Bunny The Compiler]]></dc:creator>
            <pubDate>Sat, 12 Feb 2022 22:03:33 GMT</pubDate>
            <atom:updated>2023-01-22T09:38:54.585Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a video-sharing app built using Django with authentication and authorization support.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35cQKzxEKRfRGuqbrjq2Yw.jpeg" /><figcaption>Photo by Thomas Russel from unsplash</figcaption></figure><p>In this tutorial, we will be building a video sharing app with advanced features such as profile creation, authentication and authorization.</p><p>Here are a few screenshots of our final app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yrqMhqFxGrWKESSlWqjLgQ.png" /><figcaption>This is the home page displaying all the videos created by various users</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NGTRjWZus9RP_-SWOvLGyQ.png" /><figcaption>This is the search page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zcaYyzX4kU6ZMdn1O_jThA.png" /><figcaption>This is our users page containing all their uploaded videos</figcaption></figure><p>Hope you now have a clue of what we are going to be building. Stick to the end as I’ll be sharing my final thoughts on the project.</p><p><strong>Disclaimer!!! The user interface for this project is not that appealing since I’m more of a backend guy, my primary focus was on the backend logic.</strong></p><figure><a href="https://bytexplain.com/how-to-create-a-news-app-using-flask/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wEZQ6jmF1RF6seIjOduz5Q.png" /></a></figure><p><strong>Current App Features</strong></p><ol><li>User Creation</li><li>Video upload</li><li>Video Delete</li><li>Video Search</li><li>Video Upload</li><li>Login Logout functionality</li><li>See videos uploaded by a certain user</li><li>And more</li></ol><p><strong>Upcoming Features</strong></p><ol><li>Like</li><li>Dislike</li><li>Account deletion</li><li>Redefined UI</li><li>Many More</li></ol><p>Now let’s begin.</p><p><strong>Requirements</strong></p><ol><li>django</li><li>pillow</li></ol><p>To install these packages run pip3 install &lt;package name&gt;</p><p>After installation now open your terminal and run the following</p><p>django-admin startproject video_app</p><p>This will create a folder called video_app</p><p>Cd into the folder and run the following;</p><p>python3 manage.py startapp stream</p><p>This is the app that will handle the videos, next let’s create an app that will handle the users. In this project, our users will be referred to as streamers</p><p>Now run the following to create the streamers app</p><p>python3 manage.py startapp streamers</p><p>Now that’s all with the creation of the app, here is a directory structure of our entire project.</p><p>db.sqlite3</p><p>manage.py</p><p>media</p><p>└── profile-pics</p><p>stream</p><p>├── migrations</p><p>│ └── __pycache__</p><p>├── __pycache__</p><p>├── static</p><p>│ ├── css</p><p>│ └── js</p><p>└── templates</p><p>└── stream</p><p>streamers</p><p>├── migrations</p><p>│ └── __pycache__</p><p>├── __pycache__</p><p>└── templates</p><p>└── streamers</p><p>video_app</p><p>└── __pycache__</p><p>Now let’s configure our app in the <strong>settings.py </strong>for our apps to be recognized.</p><p>In the settings.py file add the following;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/121923090b023a27f4ae6f8a2cf01410/href">https://medium.com/media/121923090b023a27f4ae6f8a2cf01410/href</a></iframe><p>We will now start building our stream app first. First lets create our models, in the stream/models.py file add the following;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8563387a400c2ca0d1b6695c416d5b7f/href">https://medium.com/media/8563387a400c2ca0d1b6695c416d5b7f/href</a></iframe><p>Here we have defined items we need in our database, we will have our streamer who is the user in other words.</p><p>Next we need to create our views. Let’s start with video-createview. Add the following lines in the views<strong>.py </strong>file;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05531900ccfb34c875966c5060c469f4/href">https://medium.com/media/05531900ccfb34c875966c5060c469f4/href</a></iframe><p>Here we have our class-based VideoCreateView which inherits from the generic CreateView. We have also added loginrequiredmixin which will ensure only the logged-in user can access the upload video route. We have also added a form_valid function that will ensure that the logged-in user is the one to upload the video.</p><p>Next is our video creation template. All our templates for this entire project will inherit from the base.html template.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c52890feae0738ecf0fff286672b611/href">https://medium.com/media/4c52890feae0738ecf0fff286672b611/href</a></iframe><p>Next is our video_list view which will list all the videos from all the users in the home page. Here is its view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4942a0baa19633c983ebc3e3e8f2b061/href">https://medium.com/media/4942a0baa19633c983ebc3e3e8f2b061/href</a></iframe><p>We order our videos by the upload date in that the latest video will appear first. Next we have our video-list template.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05f30fab8af58f4d9b6116a3e3b907b8/href">https://medium.com/media/05f30fab8af58f4d9b6116a3e3b907b8/href</a></iframe><p>Now let’s move to our video_update view. In the <strong>stream/views.py</strong> insert the following;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16de37dc03fc819a405b39da7b1697c4/href">https://medium.com/media/16de37dc03fc819a405b39da7b1697c4/href</a></iframe><p>Here we have inserted the <strong>userpassestestmixin </strong>which will ensure that only the video owner can update the video. We have also defined a form valid function which will ensure that the user is added before the form is saved thus avoiding an integrity error. We have also defined a <strong>test_func</strong> function which will ensure only the only the logged in user and owner of the video can update the form.</p><p>Next we have the video update template.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c464340c64339c1d9189baeab07e201/href">https://medium.com/media/8c464340c64339c1d9189baeab07e201/href</a></iframe><p>Now we move to the detail view which will help help us see each individual post in detail.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f99649f7a9d1c838827ad30f0784bad9/href">https://medium.com/media/f99649f7a9d1c838827ad30f0784bad9/href</a></iframe><p>Here is the video-detail template.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7ed1c253f4d8d04ce5d05529efb239f/href">https://medium.com/media/d7ed1c253f4d8d04ce5d05529efb239f/href</a></iframe><p>In the detail template we will display the streamer profile picture , the username, video title , description and the video itself. We have also created a conditional statement which will display the update and delete buttons only if you are the logged in owner of the video.</p><p>Next we move to the search view. We will be querying videos based on their title.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f14212c8adaa382287a097e6eaf7b9d2/href">https://medium.com/media/f14212c8adaa382287a097e6eaf7b9d2/href</a></iframe><p>Next we create the search template where we will be having our search bar.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fdb1b3a31bc23b8924299379418f8522/href">https://medium.com/media/fdb1b3a31bc23b8924299379418f8522/href</a></iframe><p>In the template above we have named our search bar title which will be used in the search view to query the videos. The output will then be rendered below the search bar as illustrated.</p><p>Next we move to the delete view which will be used to delete videos.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61a5827e56d96c612099b55f259b494f/href">https://medium.com/media/61a5827e56d96c612099b55f259b494f/href</a></iframe><p>Here we have inserted the <strong>loginrequired</strong> and the <strong>userpassestest </strong>mixins to our delete view which will restrict the delete functionality to logged in users and the said video author respectively. The test_func function is meant to assert that.</p><p>Next we need to create a template to confirm our delete activity. When users or rather streamers as per my project definition press the delete button they will be directed to this page to confirm the deletion of a specific video</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bac7fc56ada99db8e8caebc518c8488d/href">https://medium.com/media/bac7fc56ada99db8e8caebc518c8488d/href</a></iframe><p>Now we need to create a view to query all videos belonging to a certain user. If you click the username of a certain video you will be directed to a page containing all the content that certain user has ever uploaded.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c59943a30aa94255f80f93e1ff9ecbc0/href">https://medium.com/media/c59943a30aa94255f80f93e1ff9ecbc0/href</a></iframe><p>Now let’s create a template for our view above.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e1c75922679b0946b165543fee61bf7/href">https://medium.com/media/4e1c75922679b0946b165543fee61bf7/href</a></iframe><p>Now let’s create routes for our stream app. In the stream/urls.pyfile add the following.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d06b89c7b06115c62947a3aaf2fde28/href">https://medium.com/media/3d06b89c7b06115c62947a3aaf2fde28/href</a></iframe><p>That’s it with our stream app, now we need to move to our streamers app which contains our user creation functionalities.</p><p>We first begin by creating models for our profile. We have then imported the pillow library which will help us resize our uploaded profile pictures. We have then created our image model which has an image as its default value. We have then defined the path for our uploaded photos which will be stored in the profile-pics folder inside the project directory. We have then created a save function which will override the default save function so as to save a much smaller image to save on space in the file system and enhance faster page loads.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a507c6ca0131245e67148dd2003703d/href">https://medium.com/media/0a507c6ca0131245e67148dd2003703d/href</a></iframe><p>Next we need to create a forms.py file which will store our registration, userupdate and profileupdateforms.</p><p>First let’s create a registration functionality . Inside the forms.py we have imported the django builtin usercreationform . We have then created a registration form which inherits from the usercreationform . An email field is also created.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/827eef82aa50a9e89ce9e13997eb5714/href">https://medium.com/media/827eef82aa50a9e89ce9e13997eb5714/href</a></iframe><p>Now let’s create a template for the registration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62574c98065a958f529f9dc9ebad8a2a/href">https://medium.com/media/62574c98065a958f529f9dc9ebad8a2a/href</a></iframe><p>Next we move to the profile update function. Here is the form for the profile picture field and the username and email.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd310450f540fe83a3b3fb53c681c9dd/href">https://medium.com/media/cd310450f540fe83a3b3fb53c681c9dd/href</a></iframe><p>Here is the template for the profile update.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f5e2d73dcd5e218662f329e8864791d/href">https://medium.com/media/0f5e2d73dcd5e218662f329e8864791d/href</a></iframe><p>Now we will need to create our login and logout functionality. To enable these functionalities we first need to import the django builtin login/logout functionalities.</p><p>To enable that we need to go to the urls.py in our main project video_app</p><p>Inside the urls.py add the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/020ee3ac6c60136cd116efcafab37c25/href">https://medium.com/media/020ee3ac6c60136cd116efcafab37c25/href</a></iframe><p>Now lets create templates for the respective functionalities. This is the login template.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9086df9061d60e305350c37ca3f72381/href">https://medium.com/media/9086df9061d60e305350c37ca3f72381/href</a></iframe><p>Now let’s create the logout template.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f0011637195c46c034f3417422b956e/href">https://medium.com/media/7f0011637195c46c034f3417422b956e/href</a></iframe><p>Now we need to create routes for our entire project. Inside the video_app add the following to the urls.py file. Here we have registered all the routes for our entire project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3819905cc97229f81b95f01e88c4e296/href">https://medium.com/media/3819905cc97229f81b95f01e88c4e296/href</a></iframe><p>When a user registers for an account we need to redirect him to a login page so as to affirm his credentials . To do that we need to add this line in the video_app/settings.pyfile.</p><p>LOGIN_URL = &#39;login&#39;</p><p>This will bring up the login page as defined in the video_app/urls.pywhich will fire up the login functionality.</p><p>Next we need to redirect the user to the home page after he has logged in. To do this we will append the following line in the video_app/settings.py</p><p>LOGIN_REDIRECT_URL = &#39;/&#39;</p><p>Now we need to configure a few things before we end our project.</p><p>For our app to be able to store and retrieve media files such as the profile pics and the videos we need to first set the path and location in which they are going to be accessed form .</p><p>In the settings.py add the following ;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76233ecb811caa91a9b67f320d76d4e1/href">https://medium.com/media/76233ecb811caa91a9b67f320d76d4e1/href</a></iframe><p>Now we need to configure our urls.py file. Add the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/875e5394e0db5778ec35d04d4a9b0c0e/href">https://medium.com/media/875e5394e0db5778ec35d04d4a9b0c0e/href</a></iframe><p>In order for a profile to be created after every successful registration we need to create signals. First we need to create a file called signals.py in the streamersdirectory. Inside the signals.py file let’s add the following.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbbc711959bf0675a5ffb14f99b6ad03/href">https://medium.com/media/cbbc711959bf0675a5ffb14f99b6ad03/href</a></iframe><p>First we have the create_profilefunction which receives an argument Useras the sender and then creates the profile. We then have a save_profile function which also takes an argument Useras the sender but now saves instead of creating. To finish off with the signals we then need to import them in the streamers/apps.pyfile as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c94cb0e11d134ee53624a9ed4629336/href">https://medium.com/media/2c94cb0e11d134ee53624a9ed4629336/href</a></iframe><p>We then finally need to register our streamers models in the admin.py file as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bebe41dca3d51f2229e2e4d6e2c4fc2e/href">https://medium.com/media/bebe41dca3d51f2229e2e4d6e2c4fc2e/href</a></iframe><p>Our project is finally coming to an end but we need to do one thing. Inside the video_app project folder we need to create a folder called mediaand inside we need to insert a photo called mountain.jpg as defined in the streammodels. This will act as our default profile photo whenever someone creates an account.</p><p>Now we need to create tables and migrate all our data. To do this first run python3 manage.py makemigrations after that has been successful two tables will be created stream and streamers . Now we need to migrate all our data. To do this run python3 manage.py migrate after this is done we need to bring our server to life run python3 manage.py runserver .If the <strong>runserver</strong> command run successfully now we can create a new account and start uploading videos.</p><p><strong>Final thoughts</strong></p><p>This projects still lacks a lot of functionalities but I’m still working on the next version with some of the upcoming features as mentioned earlier. Stay tuned for that. You can get the source code for this project <a href="https://github.com/bunnythecompiler/video_app/tree/master">here</a>. As always thank you for reading. You can support us by donating here. Thank you.</p><p><a href="https://www.paypal.com/donate/?hosted_button_id=ERQPL5YQWQX6J">Donate to bunnythecompiler</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dacde3660a7d" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/lets-build-a-video-sharing-app-with-django-dacde3660a7d">Let’s build a video sharing app with Django</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>