Django 시작하기2

행행·2022년 5월 14일
post-thumbnail

14) templates / 앱이름 폴더 만들고 안에 index.html 생성

<!--articles/templates/articles/index.html-->
{% extends 'base.html' %}

{% block content %}
<h1>인덱스야 !</h1>

{% endblock content %}

15) 상위 폴더에서 templates 만들고, 안에 base.html 생성

<!--/templates/articles/base.html-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  {% block content %}
  
  
  {% endblock content %}
</body>
</html>

16)settings.py에서 BASE_DIR 설정하기

TEMPLATES = [
    {
        ...
        'DIRS': [BASE_DIR / 'templates'],
        ...}
            ],

throw cathch 넣어보기

17)throw 를 urls 설정, view함수로 만들기

#app/urls.py
	path('throw/', views.throw, name='throw'),
    path('catch/', views.catch, name='catch'),
    
#app/views.py

def throw(request):

    context={
    }
    return render(request, 'articles/throw.html', context,)

def catch(request):
    data = request.GET.get("content")
    context={
        "data" : data,
    }
    return render(request, 'articles/catch.html', context)	

18)각각 html 작성

#app/templates/app/throw.html

{% extends 'base.html' %}

{% block content %}
<h1>throw!</h1>
<form action="{% url 'articles:catch' %}">
  <label for="content">content</label>
  <input type="text", id="content" name="content">
  <br>
  <input type="submit">
</form>

{% endblock content %}

#app/templates/app/catch.html
{% extends 'base.html' %}

{% block content %}
<h1>catch 야!</h1>
<p>{{ data }}</p>


{% endblock content %}
profile
성장하려고 분투 중인 개발자

0개의 댓글