Django 2 "Make New PAGE !"

Now we know how to start off and make the webpage. This time I'm going to show you how to make new page ! 


You see the address  "127.0.0.1:8000" ,   what if it moves on to the other page ? like 127.0.0.1:8000/login,  127.0.0.1:8000/main, 127.0.0.1:8000/post.

("/" shows where it goes next) 


we already have path into urls.py under mysite

path('admin/', admin.site.urls),
path('', include('main.urls')),

' ' this blank means we just put in this main URL, bring us to whatever page we define next comma. 

'' -> 'main.urls'


Now in main folder you see this 

path("", views.index, name="index"),

it means if we don't type anything after address, it goes path views.index 


Let's make another path like this 

path("a1/", views.a1, name="view 1")

it means if type a1  (127.0.0.1:8000/a1) it goes view.a1 


"Main -> views.py" 

we already have this function from last time

def index(response):
    return HttpResponse("<h1>Welcome to my world</h1>")


Now we're going to make new function since we made another path on main.urls

in Main -> views.py , I add one more function like this 

def index(response):
    return HttpResponse("<h1>Welcome to my world</h1>")

def a1(response):
    return HttpResponse("<h1>This is a1</h1>")


Let's save and go to the webpage again. 

on 127.0.0.1:9090 , you see "Welcome to my world"   
( The reason the address shows "9090" is that I made "python manage.py runserver 9090") 


NEXT, let's move to 127.0.0.1:9090/a1 


You see "This is a1", which is the function we made on view.py / main 


The bottom line; we can designate the path; mysite urls.py -> main urls.py -> main views.py -> on the screen

Popular posts from this blog

[Python] Dictionary

[Visual Design 2/3]

[JavaScript] For loop , Function