Backend/Django
django 01. 첫 앱 시작, 그리고 기본적인 view 만들기
meong_j
2021. 10. 5. 18:08
728x90
반응형
장고 앱 생성
터미널 창에 accountapp 이라는 App 생성
python manage.py startapp accountapp
1. account App > view.py > hello world 이름의 변수 생성
Hello world!!! 문자 return
2. main App > urls.py 주소 등록
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('account/', include('accountapp.urls')),
]
- path 경로에서 accountapp 하위에 있는 url들 참조
- 기본적으로 localhost:8000/account/ 주소로 이동
3. account App > urls.py 주소 등록
from django.urls import path
app_name = "accountapp"
urlpatterns = [
path('hello_world/', hello_world, name='hello_world'),
]
- localhost:8000/account/hello_world 주소로 이동
- accountapp:hello_world 도 주소 이동 가능 (app_name쓰는 이유)
- hello_world의 view로 이동
4. 크롬에서 동작 확인
http://127.0.0.1:8000/account/hello_world/
반응형