> For the complete documentation index, see [llms.txt](https://pyohamen.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pyohamen.gitbook.io/til/django/02_variable_routing_and_dtl.md).

# Variable Routing & DTL

> Django - The web framework for perfectionists with deadlines

## Folder structure

### 1. Package folder

#### `settings.py`

> Allowed hosts

```python
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

```python
LANGUAGE_CODE = 'ko-kr' 

TIME_ZONE = 'Asia/Seoul'

#Internalization
USE_I18N = True 
USE_L10N = True
USE_TZ = True
```

#### `manage.py`

* 명령어를 실행 할 수 있도록 도와주는 파일
* 수정하지 말것!

### 2. Apps folder

* `apps.py`

  : app 설정
* `admin.py`

  : 관리자 view
* `models.py`

  : model
* `tests.py`

  : 테스트

## Variable routing

> url의 특정 위치의 값을 변수로 활용

#### 1. urls.py

```python
# django_intro/urls.py
path('hi/<str:name>/', views.hi),
path('add/<int:a>/<int:b>/', views.add),
```

#### 2. views.py

```python
# pages/views.py
def hi(request, name):
    context = {
        'name':name
    }
    return rnder(request, 'hi.html', context)
```

#### 3. template

```markup
<!-- 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.&#x20;
* It’s designed to feel comfortable to those used to working with HTML.

### 기본 문법

#### 1. 출력 `{{ }}`

```markup
{{ name }}
{{ menu.0 }}
```

#### 2. 문법 `{% %}`

```markup
{% for option in options%}

{% endfor %}
```
