Connect to a MongoDB to Django Using Djongo

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome to programming knowledge in today's tutorial we are going to learn about django with so basically in today's tutorial we are going to connect the django with mongodb and i will illustrate all the process how you can create a mongodb database and how you can connect that mongodb database with your django application so let's get started with today's tutorial the first thing we need to do we can open our code editor and then we need to type the command pip install django so this will install the django on our local machine and with this command we can create a django project as well as django app on our machine then then i would like to tell you that till the time this is being installed on my machine what you can do yeah here you can see that it is installed in django on my machine and you can install django with this simple command pip install django and then we have a mongodb plus i will show you how the we can go here you can refer to this website uh first this is the website for django i have already told you how you can install django then this is the website from here you can install the mongodb community edition and this works as a interface with you uh with the mongodb database as a user interface uh very similar to phpmyadmin which is used for sql then this is the package we are going to use this package has a very similar name jungle the word jungle is derived from uh like uh this is used to connect django with mongodb so jungle is the package we are going to use so let's get back to our code editor so first what you can do you can connect you to the uh connect to the local host server using this mongodb compass community edition and you can click on the connect button then this would connect to the local host now here you can see that it has been connected to the local host now what you can do you can create your own database so let's click on here uh so first let's continue with installation part so after installing uh after installing django you can install it install jungle so this is the command we are going to use to connect with the package this is the package we are going to use to connect django with the mongodb database so it's very easy so till the time it's being installed yeah it's a very easy process and next what we can do then we can create a django project and then we would i will show you how you can make a migration in your app then how the how when you can change see the changes detected in the mongodb database so let's what we what we can do uh next uh what i have so then you have to make some changes in your settings dot py file i'll also come to that then you can see the changes on the mongodb com compass so that's very easy so let's create a django project so i'll type django admin start project a demo project so i'll create a project then what you can do you can open a folder and i've created this project on my desktop so here i can open it so now the project is open on my vs code so next thing you can do you will i'll navigate you to the settings dot py file so you can press ctrl dot p and if setting dot ui file so this would simply uh direct you to the settings.py file and here you can see that there is a section for databases so we would be doing this and i will open my terminal as well so we would be connecting this uh so what we can do uh first since we have installed jungle now what we can do first we'll create a database i will show you like from here you can disconnect and connect so i'll show you again very first you disconnect then you can click on connect so this would connect you to the localhost database and now click on create database and type demo database remove database and you can give a collection name a demo collection so i would click on create database so here you can just copy the you can keep this as a referral demo database so and demo collection so i click on create database so here you can see a database has been created and which is having just a demo collection right now but what we can do uh we will connect to our uh our project and then run the app so i'll sorry run the migration so what you can do you can simply copy this and you can paste this code i'll comment this out databases so i'll put triple quotes here so this would basically come in this section double quotes and now i would miss this you can do one thing you can remove this client part because you are right now dealing with the local host and by default it would detect this so now you need to define your database name so i would define my database oh sorry so my database name is this this is my database demo database so i'll move to this here and i'll type demo data base okay so this looks perfect now uh since i'm my connection is on so i'll type a python manage dot ui make migrations and this would make the migrations in my uh database so so it says no change is detected so now i can type python manage dot py migrate so here you can see the all the migrations uh are being applied so here you can see the migrations has been applied now i will move to my database and i'll click on the refresh button and here you can see and i click on the demo database perfect so i have got all the migrations of the django here in my mongodb database so this looks perfectly fine so you can create your models and then run the previous two command that is migrate and migrations and then you are get to go with this project running so thank you guys for watching this video so i'll catch up in the next tutorial so here you can see i have made the project uh you can also do one thing you can type python manage dot ui run server so this would run the app on your local machine so you can simply copy this and you can place this on your browser and here you can see your django project is perfectly running so everything looks perfect so this is how i made the settings in my database uh this is the mongodb collections what i've got and this the project is already running so this looks perfect so thank you guys for watching this video so so keep watching this channel for many such tutorials
Info
Channel: ProgrammingKnowledge
Views: 69,472
Rating: undefined out of 5
Keywords: Django Tutorial, Django Tutorial for Beginners, What is Django, Python (Programming Language), Python, Python Tutorial, Python Tutorial for Beginners, Python for Beginners, Python for Beginners course, program in Python, Python course, python tutorial, python scripting tutorial, Introduction to Python, Online Course, Python Guru, Learn Python, python 3, Full Python Programming Course, MongoDb, Django with MongoDb
Id: MiS6y9kffBs
Channel Id: undefined
Length: 7min 50sec (470 seconds)
Published: Fri Aug 28 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.