Skip to content

Latest commit

 

History

History
88 lines (83 loc) · 2.38 KB

File metadata and controls

88 lines (83 loc) · 2.38 KB

django

settings > INSTALLED_APPS

urls > urlpatterns

movies 앱의 주소들 (층별 인포센터 / import path 뒤에 include 추가)

path('movies/', include('movies.urls'))
from django.urls import path
from . import views

app_name = 'movies'
urlpatterns = [
    path('details/', views.details, name='details'),
]

views

def greeting(request, age, word):
    result = False
    if word == word[::-1]:
        result = True

    context = {
        'age': age,
        'result': result,
        'word': word,
    }
    return render(request, 'greeting.html', context)

templates

<h1>index 대리에게 도달 하셨군요!</h1>
    <h2>{{ name }}님 환영합니다!</h2>
    <hr>
    <h2>전체음식 : {{ foods }}</h2>
    <h2>첫번째 : {{ foods.0 }}</h2>
    <h2>사는 도시 : {{ address.city }}</h2>
    <hr>
    <h2>랜덤 넘버 : {{ pick }}</h2>
    {% for food in foods %}
        <p>{{ food }} 마시따</p>
        <p>{{ food|length }}</p>
    {% endfor %}

    {% if '피자' in foods %}
        <p>오늘 나 빼고 피자 먹으러 간다며 ㅠ</p>
    {% endif %}
    <h3>{{ foods|join:', ' }}</h3>
<a href="{% url "throw" %}">다시 던지러 갈까?</a>
<form action="/catch/" method="GET">
    {% comment %} "" 비어있으면 자기 위치 {% endcomment %}
    <label for="link">입력하세요 : </label>
    <input type="text" id="link" name="message">
    <input type="submit" value='전송'>
    <button> 버튼 이름 빙고 </button>
    {% comment %} 인풋은 닫는 태그 없어도 되는 버튼, 버튼은 닫는 태그 필요한 버튼 {% endcomment %}
</form>

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>
    <h1>여기가 내비게이션, 모든 페이지가 공유</h1>
    {% block content %}
    
    {% endblock content %}
</body>
</html>

manage.py

django-admin startproject name .
python manage.py startapp name
python manage.py runserver


sending form data (Client)

form

action 지정하지 않으면 현재 페이지!
method : GET
핵심 속성 : name
input의 value는 그냥 버튼 이미지에 적힐 이름
def 밑에 raise 적으면 에러 발생시킬 수 있다.