You viewed this post!
Score:
420
Followers:
6

How To Make A Django Video Sharing App

*This post doesn't have a lot of support, so there probably we won't be a part 2. I have the code, and i could make an article, if this gets more likes. If you guys would like to see a part 2, like this post or follow me. 

Part 1 - Installation

Hello friends, today I will be sharing with you guys how you can start making a django video sharing app right from today! For those of you who don't know what django is, according to MDN, Django is a...

Django is a high-level Python web framework that enables rapid development of secure and maintainable websites. ... Django can be (and has been) used to build almost any type of website — from content management systems and wikis, through to social networks and news sites.

Basically django is this cool web-development framework, (like flask), that uses python and html. Anyways, enough intro let's get started!

What You Will Need:

  • A Computer
  • Python Installed (Most Already Have It)
  • Django
  • An Software IDE
  • A Brain
  • Time

First, we need to check if python is installed. Python is probably already installed on your system, so you can skip this.

If You Just Want To Check:

   Check & Install:

   - Mac: To check if it’s installed, go to Applications > Utilities and click on Terminal. (You can also press command-spacebar, type terminal, and then press Enter.). Then in the terminal type in:

python --version

    You should get the result of it saying "Python" and then a number for the version. If you do not get this, then you have to install it. Go here to learn how to install it.

     - WindowsTo check if it’s installed, go to Startand search for Command Prompt. (You can also press command-spacebar, type terminal, and then press Enter.). Then in the terminal type in:

python --version

      You should get the result of it saying "Python" and then a number for the version. If you do not get this, then you have to install it. Go here to learn how to install it.

Now we need to install an IDE:

But first... What is an IDE?

An IDE stands for integrated development environment. Basically it is a place where you can write and run code. There are many different IDE's. Personally, my favorite is Pycharm, and to install it, just go here.

Also, in this tutorial, we will be using the terminal. If you are using pycharm, then in the bottom right it should say "Terminal", and you can click on that and open one up. If you are not using pycharm, just open up the terminal, which you can access by using the app Terminal (Mac) or Command Prompt (Windows).

Now Let's Being The Coding!

But first we need to install django. Open up the Terminal. We will need pip, so you can install it from here, and check if you have it install from here.

You'll also need a virtual enviroment. Pycharm will auto make one, but if you are not using this IDE, check out this tutorial.

Once you have installed pip and have a virtual enviorment, run this command in the terminal:

python -m pip install Django

This will install dajngo and we can get started. 

Setting Up Our Website

From the command line, cd into a directory where you’d like to store your code, then run the following command:

django-admin startproject video_app

This will create a video_app directory in your current directory. If it didn’t work, see Problems running django-admin.

Let’s look at what startproject created:

video_app/
    manage.py
    video_app/
        __init__.py
        settings.py
        urls.py
        asgi.py
        wsgi.py

These files are:

  • The outer video_app/ root directory is a container for your project. Its name doesn’t matter to Django; you can rename it to anything you like.
  • manage.py: A command-line utility that lets you interact with this Django project in various ways. You can read all the details aboutmanage.py in django-admin and manage.py.
  • The inner video_app/ directory is the actual Python package for your project. Its name is the Python package name you’ll need to use to import anything inside it (e.g. mysite.urls).
  • video_app/__init__.py: An empty file that tells Python that this directory should be considered a Python package. If you’re a Python beginner, read more about packages in the official Python docs.
  • video_app/settings.py: Settings/configuration for this Django project.  Django settings will tell you all about how settings work.
  • video_app/urls.py: The URL declarations for this Django project; a “table of contents” of your Django-powered site. You can read more about URLs in URL dispatcher.
  • video_app/asgi.py: An entry-point for ASGI-compatible web servers to serve your project. See How to deploy with ASGI for more details.
  • video_app/wsgi.py: An entry-point for WSGI-compatible web servers to serve your project. See How to deploy with WSGI for more details.

Now move into the directory. Type this in your command line:

cd video_app/

We need to know create the tables and columns for our admin site. Run this command:

python manage.py makemigrations

And then run:

python manage.py migrate

Now to test if it is all working correctly, go to the command line and type in:

python manage.py runserver

You should get some text saying Running on http://127.0.0.1:8000. Full message:

Performing system checks...

System check identified no issues (0 silenced).

You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.

June 22, 2021 - 15:50:53
Django version 3.2, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Go to the url http://127.0.0.1:8000/ and you should see this message: 

This means it all worked and it was a success the installation of Django. 

If you did not get this message and you had some error while following this tutorial, please consult the documentation to debug your problem.

Our file structure thus far is this:

video_app/
    manage.py
    video_app/
        __init__.py
        settings.py
        urls.py
        asgi.py
        wsgi.py

Part 2 - Basic Setup 

When using Django, we make these small apps which each can have a different task. What we have made thus far is a project. According to Django, the difference between a project and app is:

An app is a Web application that does something – e.g., a Weblog system, a database of public records or a small poll app. A project is a collection of configuration and apps for a particular website. A project can contain multiple apps. An app can be in multiple projects.

To make an app, go to your terminal and type in:

python manage.py startapp video

This should create a file like this:

video/
    __init__.py
    admin.py
    apps.py
    migrations/
        __init__.py
    models.py
    tests.py
    views.py

This directory will host our video sharing site. Now let's test if everything is working and setup our first view in Django. Open the file video/views.py and in it add this Python code:

from django.http import HttpResponse


def index(request):
    return HttpResponse("Hello, world. You're at the video index.")

This is the simplest view possible in Django. To call the view, we need to map it to a URL - and for this we need a URLconf. To create a URLconf, make a python file in the video/ directory and name it urls.py. Our file tree should look like this:

video/
    __init__.py
    admin.py
    apps.py
    migrations/
        __init__.py
    models.py
    tests.py
    urls.py
    views.py
video_app/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        asgi.py
        wsgi.py

In the newly created urls.py file, add this code:

from django.urls import path

from . import views

urlpatterns = [
    path('', views.index, name='index'),
]

The next step is to point the root URLconf at the video.urls module. In video_app/urls.py, add an import for django.urls.include and insert an include() in the urlpatterns list, so you have:

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('', include('video.urls')),
    path('admin/', admin.site.urls),
]

The include() function allows referencing other URLconfs. Whenever Django encounters include(), it chops off whatever part of the URL matched up to that point and sends the remaining string to the included URLconf for further processing. The idea behind include() is to make it easy to plug-and-play URLs. Since polls are in their own URLconf (video/urls.py), they can be placed under “/”, or under “/videos/”, or under “/content/videos/”, or any other path root, and the app will still work. 

You have now wired an index view into the URLconf. Verify it’s working with the following command:

python manage.py runserver

Go to http://127.0.0.1:8000/ and if all is good, you should see the text “Hello, world. You’re at the video index.”, which you defined in the index view.

As always, ask in the comments for any questions or if you find and mistakes, and part 2 is right around the corner, so be sure to smash that follow button so you get notified when it does come. I've been your host, Dheirya Tyagi, signing off for another day. That means goodbye. :)



More From Dheirya_Tyagi_CEO

Trending Posts


Quick Settings


Top Users


Precipitation: %
Wind: m/sec
Weather data updates every 6 hours.

Categories

Not a category you like? Create one.

Sports | March 16, 2021 | 1 followers | 0 posts

Talk about sports in this category!


Lifestyle | March 16, 2021 | 1 followers | 1 posts

Talk about lifestyle in this category!


Political | March 16, 2021 | 1 followers | 0 posts

Talk about political issues in this category!


Travel | March 16, 2021 | 1 followers | 0 posts

Talk about travel in this category!


Fashion | March 16, 2021 | 0 followers | 0 posts

Talk about fashion in this category!


Education | March 16, 2021 | 1 followers | 2 posts

Talk about education in this category!


Music | March 16, 2021 | 0 followers | 1 posts

Talk about music in this category!


News | March 16, 2021 | 0 followers | 0 posts

Talk about news in this category!


Personal | March 16, 2021 | 1 followers | 3 posts

Talk about personal topics in this category.


Not displaying all categories. See all categories.