Contact For College Project / Project Report / Documentation / Project Training @ heysushil@technokrits.com
YouTube Videos and related Playlist Details which helps to better understand the code on heyKyaKaru channel
- YouTube Channel Link - Python Tutorial Couse Hindi Vido
- Python Couse in Hindi Playlist YouTube - Python Tutorial Couse Hindi Vido
- Tips and Tricks for Programming Playlist YouTube - Python Tutorial Couse Hindi Vido
- PHP Projects Playlist YouTube - Python Tutorial Couse Hindi Vido
- About Our Platform Playlist YouTube - Python Tutorial Couse Hindi Vido
- Live Python Couser in Hindi Playlist YouTube - Python Tutorial Couse Hindi Vido
Hello welcome to this project. It's for beginer because I'm also the beginer when I started this But I just started the prectice this way so it not just hepl me but also others to. I'm trying to make it easy and if others may include thier contribution on this then it will also very better. There is everything but first thing first. At first I'm describe how to install Django and setup it
I'm using visual studio code editor for it. If you don't have much expericne of it no wory just gave it your full day to understand then it will be your first choice of editor but first you must understand the editor to work on it. Because Microsoft put a grate effort on it to make it very user friendly for developers also the best part of the vs code is it's have spacial features for pyhon and it's related library.
So you must consider this at begging of your python and Django.
This is also my first Django app so I also follow the tutorial of Django site.
a. Create one directory mkdir newdirecroty
b. Move on to that directory by your cmd and by cd newdirectory
c. Run django install - pip
install Django
d. Create your project by - django-admin startproject projectname
. After this the admin created with the file sturcte
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
asgi.py
wsgi.py
e. Go into the cd projectname
folder
f. Now you created your project for checking it's run properly run python manage.py runserver
h. After running it's not auto open on your browser. For this you see the IP on your terminal which you copy past on browser to run the page
a. Change time-zone to your local zone
TIME_ZONE = 'Asia/Kolkata'
b. Set static root folder where you can store your css/js/image
files. This folder you create
with the same static
on your root folder.
After that go on setting.py on root. This code you fount on this page at bottom
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
Just before this line past or write this one
STATIC_URL = '/static/'
c. Set host at top of page with this if your ip address this when you start your server is show on the browser
ALLOWED_HOSTS = ['127.0.0.1']
Dont' add any thing else like may you see the 127.0.0.1:8000
but only add main IP otherwise you get error on your terminal
3. After this need to connect with mysql by default Django provides default mysqlLite which is also good but in our case we are going to use mysql
-
I'm using
XAMPP servers MySql
, so for this go to creat on database onphpmyadmin
-
I already have this below file on root folder by the name of
mysqlclient-1.4.6
which have2 version 32 bit and 64 bit
find your suit one by those to or download on form the below link. Go to this site mysqlclient and download the recentmysqlclient
as persystem bit 32/64
. -
Past the file on root folder of prject
-
Then run the command -
pip install mysqlclient-1.4.6-cp38-cp38-win32.whl
in my case the file name is this. After successfully install this. Then add the credincials on setting.py file. -
In root folders setting.py at database section add these lines
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'mydjango', 'USER': 'root', 'PASSWORD':'', 'HOST':'localhost', 'PORT':'3306', } }
-
Port is mysql port which you get on xampp servers mysql section
-
Then at last if get no error on the time of runserver then the last commant which creates table on your connected database -
- Command is -
python manage.py migrate
- After this auto create many tables on database
- Command is -
-
It's very easy app is foldabel and moveable to any were and in any project. Don't focus on this for now because after few time of using the Django you automaitcally understand this concept.
-
For installing the app run following command by having on your root directory which is in my case main folder name is
Mydjango
and then run this cmd -python manage.py startapp polls
After that you found this sturcture on your main folder polls/ __init__.py admin.py apps.py migrations/ __init__.py models.py tests.py views.py
-
Django follow the MVT (
Model=Database View=Controller Templete=HTML
). For html templete folder is not't auto created on the polls folder but we willl creat it after get the apps root structe. For this just ned to creat on new folder with name oftemplate
onpolls folder
. For more information about the [MVT Click here]https://pythonistaplanet.com/difference-between-mvc-and-mvt/ -
In file structe each file is important for know understand the breief of every files
-
view.py file = This file is same as controller and for this have some steps which needs to follow here. For now add the following code into view.py file
polls/views.py from django.http import HttpResponse def index(request): return HttpResponse("Hello, world. You're at the polls index.") Note: This is just basic example but for running this you need to link this with url routing sytem and for that you need to follow below steps.
-
for using view.py must need a urls.py file in polls root directry wich not have here. SO first need to creat this file.
-
On urls.py file past this code
polls/urls.py from django.urls import path from . import views urlpatterns = [ path('', views.index, name='index'), ]
-
After that also inform about this
polls/urls.py
to main root foldersyoursites/urls.py
where your need to import this and add the url onurlpatterns
after this theyoursites/urls.py
lookes like thismysite/urls.py from django.contrib import admin from django.urls import include, path urlpatterns = [ path('polls/', include('polls.urls')), path('admin/', admin.site.urls), ] Note: The idea behind include() is to make it easy to plug-and-play URLs. Since polls are in their own URLconf (polls/urls.py), they can be placed under “/polls/”, or under “/fun_polls/”, or under “/content/polls/”, or any other path root, and the app will still work.
-
After these change run server cmd to check is every thins runs and you will see the output on browse or not. cmd -
python manage.py runserver
Go to http://localhost:8000/polls/ in your browser, and you should see the text “Hello, world. You’re at the polls index.”, which you defined in the index view.
-
-
models.py file for handeling database which we better understand at belows definintions.
-
apps.py file is which use for app also be more know about it at below
-
admin.py is use to made connection with admin panel and front end panel. We more know about this at below to.
Note: There is many ohter changes alos which we know in upcoming lines step by step.
-
-
In app have model.py file which is actually a file which handel all database work here same like mvc's model
-
Great part is model.py auto create db table by the name of class which creates in model
-
On models.py file added new models or classes
Question
andChoice
which is aleray on project. But at firest added these on it.Note: model is made codeing easy because its models name like Question will also became database table name and the fields on the models also became the tables column. Which is realy great part. And that's how pyhone and Django became so easy
-
Also in class all form fields which I define is db tables column fields also that's why at the time of defineing the variable here with datatype and length
-
After creating your class need also need to add /include your app in
root->setting.py
onINSTALLED_APPS = [ 'polls.apps.PollsConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ]
My app which add here where the polls is my app folder name Apps is file in this folder with name of apps.py PollsConfig is in app folder have apps.py folder in which have this classNote: After adding the app here Djano know now about the app and use it with admin also.
-
After all this run this
python manage.py makemigrations polls
Pasted from https://docs.djangoproject.com/en/3.0/intro/tutorial02/ For more information about after this setpes are present here https://docs.djangoproject.com/en/3.0/intro/tutorial02/
-
When you run upper cmd if everyting going right then you will the this on your termianl
Migrations for 'polls': polls/migrations/0001_initial.py: - Create model Choice - Create model Question - Add field question to choice
-
Last cmd to made magic happence
python manage.py sqlmigrate polls 0001
. When you run this on terminal you will see the output where have noraml mysql querys which done the rest work on behalf of you. -
Still you didn't see the new tables on your database because sitll on last cmd is pending which is
python manage.py migrate
This cmd alwas mad last changes on db.Note: If check your database which have many tables on it but polls/models.py class not became table yet because we don't makemigrations yet but after running the avove cmd models.py all class became tabe on database and also in class fields became column on table. After this command.
-
At first we do that on shell so for this run this cmd to change youer terminals default cmd to shell of pyhon for running these cmd -
pyhon manage.py shell
-
After you successfully enterd on shell then try to run these commands line by line on your shell to become familier with these quese which we run on code. But first try these here.
>>> from polls.models import Choice, Question # Import the model classes we just wrote. # No questions are in the system yet. >>> Question.objects.all() <QuerySet []> # Create a new Question. # Support for time zones is enabled in the default settings file, so # Django expects a datetime with tzinfo for pub_date. Use timezone.now() # instead of datetime.datetime.now() and it will do the right thing. >>> from django.utils import timezone >>> q = Question(question_text="What's new?", pub_date=timezone.now()) # Save the object into the database. You have to call save() explicitly. >>> q.save() # Now it has an ID. >>> q.id 1 # Access model field values via Python attributes. >>> q.question_text "What's new?" >>> q.pub_date datetime.datetime(2012, 2, 26, 13, 0, 0, 775217, tzinfo=<UTC>) # Change values by changing the attributes, then calling save(). >>> q.question_text = "What's up?" >>> q.save() # objects.all() displays all the questions in the database. >>> Question.objects.all() <QuerySet [<Question: Question object (1)>]>`
-
At last commend
objects.all()
not feching all on privew way so for that change onpolls/models.py
and add def `polls/models.py¶ from django.db import modelsclass Question(models.Model): # ... def __str__(self): return self.question_text class Choice(models.Model): # ... def __str__(self): return self.choice_text`
-
After that also addind few more custome methods on
polls/models.py
file.Note: Like you know that python have librarys for everythins so same that doind here for everythind we need librarys which we can import. In this cas I need timezone for that i add this line on models.py file from django.utils import timezone
-
Same like shell command on
Djangos
home website also have many sehll cmd which we can not needs yet so I'm left that and mover forward.
- At first if you try to hit the
ip address/admin/
you get the login panel but for that you must have login credential which you don't get from any where. You need to create one. - ss
-
In case of your if you want to change your remote access from one user to another so it's go by changing on you vs code the git global user name and email by running this cmd -> git config --global user.name "yourname" and same for email
-
After that chack how many remote you added previously on your localsystem of the project by git remote -v which show you all remote repository which you added
If you have non used repository here then simply remove this by ctrl+shift+p and type git: remove remote After that you show the drop-down of all existing remotes here and remove form here which of those which you don't want
-
If your new remote repository not yet added on local system then add that by the same way and commit fisrt change to check it's working or not
मेरे Youtube चैनल को सबस्क्राइब करना ना भूलो ताकि आपको कोड का पूरा फ़्लो समझमे आए - Hey Sushil YouTube Channel
कोई भी सवाल है उसको मेरे यूट्यूब चैनल के कमेन्ट या डिस्कशन सेक्शन मे पूछ सकते हो - Hey Sushil YouTube Discussion Point
पाइथान को और अच्छे से समझने के लिए Hey Sushil YouTube चैनल पर उपस्थित इन प्लेलिस्ट को देख सकते हो:
- Full Python Course Video on Hey Sushil
- Numpy Array Video on Hey Sushil
- Django Online Training on Hey Sushil
- Python Project Video Playlist on Hey Sushil
- Tips and Trics for Programming Video Playlist on Hey Sushil
- Python Online Class on Hey Sushil
- PHP Project with Full Details and Source code on Hey Sushil
- GitHub tutorials in Hindi on Hey Sushil
- Hey Kya karu main on Hey Sushil