Django

Django (hello/hello)

FnMask 2020. 11. 21. 13:56

1.터미널을 끈다

2.manage.pr클릭

3.python Extension이 로드된 것을 확인

django-admin start project hello

#hello라는 프로젝트를 만듭니다.

 

hello/hello/views.py

from django.http import HttpResponse

def imdex (request):
	return HttpResponse('<h1>Hello, World!</h1>')

hello/hello/urls.py

#views.py를 import 합니다.

(18번째줄) from . import views
(20번째줄)urlpatterns = [
  			  path('', views.index),
  			  path('admin/', admin.site.urls),
		]

Teminal

cd hello

python manage.py runserver        

#포트를 다른걸로 바꾸고 싶을땐 python manage.py runserver localhost:8989

localhost:8989에 들어갔을 때 결과화면입니다.

요청이 들어오면 Views.py에서 def를 사용해 만든 index라는 함수가 응답됩니다.