PostgreSQL with Django // how to // tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey in this video i will tell you how can you connect postgres sql database with your django project so at first you have to install the postcase sql okay so if you are using windows so just download postgresql for windows okay now just download the installer and now download the version of postgresql and then installed it okay before start this i just tell you something there are a lot of tutorials so i started react and django tutorials for beginners and the django rest framework tutorial for beginners so if you are a beginner and want to learn it now subscribe the channel for more videos okay when you install the postgres sql it needs a password you have to remember this password for further now you can install cyclops g2psycopg2 for your django project so now copy this and here just open the cmd and paste this in my case already satisfied after post crease is installed so just here create a django project and the django apps okay so now open it with vs code so this is our django project and this is the django application so go to p and here you can see postgresql 13 okay so now inside the settings.pi so here just install the app okay so now go to application and here just create a index view so def index and now pass the request okay so just return and return render and now pass request also and then the template name template name is index dot html okay so now go to app and here create a folder name templates okay so just create a file name index.html now i just copy this bootstrap starter template so just copy this and paste here and here i just type the learning club okay so now go to the project here at the url dot pi so here just add the path so you have to import the index view so just type from app dot views import index okay so now here type the path okay i use the landing page here and now type the function name index okay and the name of the url is index okay so now save it and just save it and go to settings save it okay so at first just run the server so python manage dot py run server okay so now this is working so just go to models here just create a model okay so here i just create a model name student and there are two field name and description field okay so now go to the admin here at first import the model student so from models dot models import student okay now register it admin dot site dot register and register the model student okay so now go to settings.pipe here you have to change the database okay so here just remove this okay so now type the engine name user and the password so type the engine name django.db.backend dot postgres sql backends dot postgres sql okay so just type this okay so now open the post case so just go to postgres sql 13 and here is a pg admin 4 okay so by sql cell you can create the database also so just click it pg admin for so wait sometimes okay so here need a password to open okay so just type the password which you have entered at the installation time so i just enter my password admin and now click on ok ok so now click on servers and here is post trace sql 13 so just expand the login and group rules so just right click here and now create a login okay so just create a name so i just name it moni and now go to the definition here need a password so just password is moa9 and now save it okay so now go to database here and just right click on the database and now create a database okay so just create a database name test one and owner owner is moni money this is the login user okay so now save it okay okay so now go to your django project here what is your name of the database so the name of the database is test one okay so just type here test test one and the user name is moa9 and the password is also moa9 okay so now save it so now just open the cmd and now make migration at first so just type python manage dot py make migrations okay so you will get an error role money is not permanent permitted to login so just go to the post case here is the moni user and now here is the pre villages okay so you have to give a pre villages so just edit this and go to pre villages and can login set it to yes okay so now save it okay so now open the cmd and now type python manage dot py make migration okay now migrate the model python manage dot py migrate okay now you can create the super user also so just type python managed py create super user i just give a name admin and the password is admin okay so now run the server python manage dot py run server okay so now go to the localhost at first and just go to the admin and here type the username and the password and you can see here the students database okay so now click on add student and here just add a student row it okay so description rohit is good boy okay so now save it okay so now go to your django project here is the application and there is a views dot pi and now here just import at first student model so just type from inform dot models import student model and now create an object for student model so obj equal student dot objects dot all okay and now context context is what so just pass obj and obj is what this object okay this object and now pass this here so here just pass this context okay so now go to index.html here just create a class name container okay so now here just create a for loop for grab the all object of student model so just create a for for x in obj and now in the for loop here so just in the for loop and for okay so now grab at first the name of the student and then description so just here grab ex dot name and here just grab x dot d e s description okay so now save it okay so now run it okay you can see here rohit and rohit is a good boy okay so now go to the post database and here is the money and here is the dependents okay so the database is test one okay so now go to test one and go to schemas and here just you can see the table okay so here is the table app student auth group and this is the table we created student okay so just right click on it and go to scripts and insert script okay so now here at first the value of the id is to just give it and the name the name i just choose name ronnie and then the description ronnie is bad boy okay so now i just copy all of this and now paste here also and here i just change the value and the name is debu and just change also the description is not bad boy okay so now run the script okay so now go to the browser and just run the localhost and you can see here ronnie and debu roni is bad boy and debu is not bad boy okay so in this way you can connect the postgres database with your django project here are other database okay so what group permission auth permission or user okay so thanks for watching this video and don't forget to subscribe the channel for more learning videos
Info
Channel: B Learning Club
Views: 46,074
Rating: undefined out of 5
Keywords: PostgreSQL, django, postgreSQL django, django postgresql, how to connect postgres with django, connect postgresql with django, how to connect django with postgresql database, how to connect postgresql database with django project, django with postgresql, django connect to postgresql, django with postgresql tutorial, django with postgresql database, django postgresql setup, django postgresql tutorial, django postgresql crud, django postgres tutorial, django postgres setup
Id: unFGJhIvHU4
Channel Id: undefined
Length: 12min 37sec (757 seconds)
Published: Tue Jan 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.