본문 바로가기

Python_WEB/Project-Noticeboard

[Django]Board > Templates > HTML > Board Write

반응형
{% extends "base.html" %} {% block contents %}
<div class="row mt-5">
  <div class="col-12">
    <form method="POST" action=".">
      {% csrf_token %} {% for field in form %}
      <div class="form-group">
        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
        {{ field.field.widget.name }} {% ifequal field.name 'contents' %}
        <textarea
          class="form-control"
          name="{{ field.name }}"
          placeholder="{{ field.label }}"
        ></textarea>
        {% else %}
        <input
          type="{{ field.field.widget.input_type }}"
          class="form-control"
          id="{{ field.id_for_label }}"
          placeholder="{{ field.label }}"
          name="{{ field.name }}"
        />
        {% endifequal %}
      </div>
      {% if field.errors %}
      <span style="color:red">{{ field.errors }}</span>
      {% endif %} {% endfor %}
      <button type="submit" class="btn btn-primary">글쓰기</button>
      <button
        type="button"
        class="btn btn-primary"
        onclick="location.href='/board/list/'"
      >
        돌아가기
      </button>
    </form>
  </div>
</div>
{% endblock %}
반응형