Saturday, 15 October 2022

Django tutorial part 2

step 1

 create an environment

open 'cmd ' from address bar











python -m venv myenv -> enter

step 2

activate by 


PS E:\project> .\myenv\Scripts\activate


step 3

Install django library


step 4

Install djangorestframework


step 5

Show installed libraries in current environment


step 6 

listing installed libraries in current environment


step 7

After installing django we can see a django-admin.exe file is created in myenv ->Scripts-
>

step 8

listing django admiṇ command

django-admin


Step 9

create project using django admin


step 10

create app 



step 11

open vs code



step 12

project file structure












step 13

register app 

add myapp in INSTALLED_APPS list variable 


INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'myapp',
]


step 14

create urls.py in myapp











STEP 15

Create a funtion home in views.py of myapp

from django.http import HttpResponse

def home(request):
    return HttpResponse("HELLO WORLD")


step 16

myproject-> urls.py

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

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

step 17

create routing for home

from django.urls import path
from myapp.views import home
urlpatterns = [
    path('index',home)
]

step 18

runserver

(myenv) PS E:\project> python manage.py runserver

Watching for file changes with StatReloader

Performing system checks...


System check identified no issues (0 silenced).


You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, 

sessions.

Run 'python manage.py migrate' to apply them.

October 16, 2022 - 12:03:14

Django version 4.1.2, using settings 'myproject.settings'

Starting development server at http://127.0.0.1:8000/    

Quit the server with CTRL-BREAK.


step 19

goto browser and type url

http://127.0.0.1:8000/index









































No comments:

Post a Comment