You are on page 1of 2

-In order to start with Django you need to have python installed.

-Now in windows powershell write pip install django.


-In order to check it we can write
python -m django --version
-Make a directory DJANGO TUTORIAL
-To start project type django-admin startproject text
-So now we have Django TUTORIAL/text->text,manage.py
-Now the text contain _init_.py,settings.py,url.py,wsgi.py,manage.py
-manage.py is a command line utility create databases for migrations
hence it is used to launch server,manage database,create tables in db
settings.py is all settings of your project.
_init_.py is a blank file it tells it is a python package
url.py is a file containing all the url.It basically tells where to go
when a basic url is entered in django
wsgi.py is to deploy file on server

-Now in order to run a dummy server type "python manage.py runserver"


Once the server is running we can copy the address shown as
"http://127.0.0.1:8000/" in web browser and run it.

-Now here text is a project which is a collection of many apps.Suppose


you created a project named e-commerce website no in this you can have
many apps namely shop,pay,return etc.

-Now in order to create a app type "python manage.py startapp utilities"


-A utilities folder will appear whic contain:
migrations->_init_.py,admin.py,models.py,tests.py,views.py
Here migration carries the information abt db change
_init_ is a blank file and it tells python that it can be imported
views.py is a most imp file and contain all the functions responsible
for displaying all the views.

-->Now in text make urls.py


from django.contrib import admin
from django.urls import path,include
urlpatterns=[
path('admin/',admin.site.url),
path('utilities/',include('utilities.url))
]
"http://127.0.0.1:8000/utilities"

-Now we are in urls.py of utilities


from django.url import path
from . import views

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

-Now since there is no index we will create one in views.py so open


views.py and write
from django.shortcuts import render
from django.http import HttpResponse

def index(requests):
return HttpsResponse('We are at index function we created')

-Now run "python manage.py makemigrations"


-Go to utilities->models.py models are python classes having information
abt how your db is structured,which tables are containing your db and how
you want django to store your data.
-Now run "manage.py migrate" Every time you make some chages you have to
come here again
-If you want to manage some media go to setting.py and write
MEDIA_ROOT=os.path.join(BASE_DIR,'media')
MEDIA_URL='/media/'

->Lets again go to views and create more views


def index(request):
return HttpRequest('''

<b>This is a bold tag</b>

''')

-Here abve cannot be done again and again so inorder to skip it go to app
folder and create two directories named "static" "template".
Also create a "utility" directory in static and template as we might
have some conflicting files of different apps.
static-->"utilities"
templates-->"utilities"-->"index.html"

---->Write any webpage code in "index.html"


-Now again goes to views.py
def index(request):
return render(request,'utilities/index.html')

From nowonwards page will load successfully.

You might also like