Variable Routing & DTL
Django - The web framework for perfectionists with deadlines
Folder structure
1. Package folder
settings.py
settings.py
Allowed hosts
ALLOWED_HOSTS = ['*']
'*' ์ ๋ชจ๋ ๊ฒ์ ์๋ฏธํ๋ wildcard
Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pages', #app register
]
์๋ก์ด app์ ๋ง๋ค ๋๋ง๋ค ์ถ๊ฐํด์ค์ผํจ
Language setting & Internalization
LANGUAGE_CODE = 'ko-kr'
TIME_ZONE = 'Asia/Seoul'
#Internalization
USE_I18N = True
USE_L10N = True
USE_TZ = True
manage.py
manage.py
๋ช ๋ น์ด๋ฅผ ์คํ ํ ์ ์๋๋ก ๋์์ฃผ๋ ํ์ผ
์์ ํ์ง ๋ง๊ฒ!
2. Apps folder
apps.py
: app ์ค์
admin.py
: ๊ด๋ฆฌ์ view
models.py
: model
tests.py
: ํ ์คํธ
Variable routing
url์ ํน์ ์์น์ ๊ฐ์ ๋ณ์๋ก ํ์ฉ
1. urls.py
# django_intro/urls.py
path('hi/<str:name>/', views.hi),
path('add/<int:a>/<int:b>/', views.add),
2. views.py
# pages/views.py
def hi(request, name):
context = {
'name':name
}
return rnder(request, 'hi.html', context)
3. template
<!-- pages/templates/hi.html -->
<h1>
Hi, {{name}}
</h1>
DTL (Django Template Language)
Template file (HTML) ์ django template language๋ฅผ ํตํด ๊ตฌ์ฑํ ์ ์๋ค!
Djangoโs template language is designed to strike a balance between power and ease.
Itโs designed to feel comfortable to those used to working with HTML.
๊ธฐ๋ณธ ๋ฌธ๋ฒ
1. ์ถ๋ ฅ {{ }}
{{ }}
{{ name }}
{{ menu.0 }}
2. ๋ฌธ๋ฒ {% %}
{% %}
{% for option in options%}
{% endfor %}
Last updated
Was this helpful?