coltonOP
@coltonOP (こるとんくん)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

なぞの文字が挿入される

解決したいこと

Djangoを使いWebアプリを作成しているのですが、謎の文字が勝手に挿入されて困っています。
なにか対処法はありますでしょうか?

html

{% extends "account/base.html" %}

{% block title %}スケジュール{% endblock %}

{% block content %}
{{ formset.management_form }}
  <div class="head">
      <header>
          <a class="headmoji">部署情報変更画面</a>
      </header>
  </div>
  
  <div class="information">
      <a>本日は{% now "F" %}{% now "j" %}日です。</a> <br>
      <a>ようこそ、{{ user.name }}さん</a>
  </div>
  
  
  
  <form id="syozokuform" method="post">
      <div class="table">
          <table class="hyou2">
               <tr>
                    <th>ID</th>
                    <th>所属</th>
                    <th>面談場所</th>
                    <th>面談時間</th>
               </tr>
               {% for syozoku in formset %}
               {% if not forloop.last %}
               <tr class="{{ syozoku.number_b }}">
                    <td class = "hidden">{{ syozoku.id }}</td>
                    <td>{{ syozoku.name_b }}</td>
                    <td>{{ syozoku.mendanplace_b }}</td>
                    <td>{{ syozoku.mendantime_b }}</td>
               </tr>
               {% endif %}
               {% endfor %}
          </table>
      </div>
  </form>

  <div class="button2">
      <a href="{% url 'account:sakusei' %}" class="btn-square-1">更新</a> <br>
      
  </div>
  
   <a class="under" href="{% url 'account:logout' %}"> ログアウト </a>
      <script>
        $('tr[data-href]').click(function (e) {
        if (!$(e.target).is('a')) {
          window.location = $(e.target).data('href');
        };
        });
      </script>
            
{% endblock %}

実際に表示されるhtml

fagsgs.png

なぞの「 "> "> "> "> "> "> "> "> 」

が勝手に差し込まれ、画面にまで影響がでているのですが、どうしたらいいのでしょうか...

0

1Answer

その文字列の下で tr タグが <tr class="<input type=" text... のように壊れています。余った "> が上のほうにあふれているように見えます。(tr タグと同じで8個ありますし)

<tr class="{{ syozoku.number_b }}">

syozoku.number_b に input タグが入っているせいではないでしょうか。構造を見直してください。

2Like

Comments

  1. @coltonOP

    Questioner

    確かに class="{{ syozoku.number_b }} が原因でした
    構造を見直すとは model の構造を見直せばいいのでしょうか?
  2. HTML の構造です。 class にはクラス名が入るべきですし、 input タグをテーブル内に書くなら `<tr><td><input ...></td></tr>` のように td の中に入れる必要があります。

Your answer might help someone💌