18910140161

将HTML表堆栈溢出中的“无”更改为空

顺晟科技

2022-10-19 14:04:16

73

我有一个web应用程序,前端使用HTML5,后端使用Django和MySQL。 某些列在MySQL中为NULL,它在HTML表中显示为“None”。

如何将HTML表中的所有无更改为空?

               <table>
  <tr>
    <th>S/N</th>
    <th>Course Material Title</th>
      <th>Author/Editor</th>
      <th>Publication Year</th>
                      <th>Edition</th>
                <th>Special Edition</th>
    <th>iSBN or  e-iSBN / VBID</th>
      <th>Cost</th>
      <th>Material Format</th>
      <th>Distribution Mode</th>



  </tr>
{% for query_results_book in query_results_books_list %}
  <tr>
      <td>{{ forloop.counter }}</td>
      {% for obj in query_results_book %}
      {% if obj.title == "StudyGuide" or  obj.title == "Mylab" %}
      <td>{{ obj.title }}</td>
      {% else %}
    <td>{{obj.title}}</td>
      {% endif %}
            <td>{{obj.author}}</td>
                                            <td>{{obj.pub_date}}</td>
                        <td>{{obj.edition}}</td>
                        <td>{{obj.special_edition}}</td>

      {% if obj.Format_issued == "eText" %}
      <td>{{ obj.vbid }}</td>
      {% else %}
       <td>{{ obj.isbn }}</td>
      {% endif %}
                    {% if obj.e_price %}
      <td>{{obj.e_price_cur}}{{obj.e_price}}</td>
          {% else %}
          <td></td>
          {% endif %}
  <td>{{obj.Format_issued}}</td>

            <td>{{obj.Distribution_platform}}</td>


      {%endfor%}
  </tr>
{%endfor%}
</table>

mysql中的某些数据为null,在此HTML表中显示为“none”。Boss希望显示为空白。


顺晟科技:

是否可以在传递数据的地方尝试这样做,例如:

               <table>
  <tr>
    <th>S/N</th>
    <th>Course Material Title</th>
      <th>Author/Editor</th>
      <th>Publication Year</th>
                      <th>Edition</th>
                <th>Special Edition</th>
    <th>iSBN or  e-iSBN / VBID</th>
      <th>Cost</th>
      <th>Material Format</th>
      <th>Distribution Mode</th>



  </tr>
{% for query_results_book in query_results_books_list %}
  <tr>
      <td>{{ forloop.counter }}</td>
      {% for obj in query_results_book %}
      {% if obj.title == "StudyGuide" or  obj.title == "Mylab" %}
      <td>{{ obj.title }}</td>
      {% else %}
    <td>{{obj.title}}</td>
      {% endif %}
            <td>{{obj.author}}</td>
                                            <td>{{obj.pub_date}}</td>
                        <td>{{obj.edition}}</td>
                        <td>{{obj.special_edition}}</td>

      {% if obj.Format_issued == "eText" %}
      <td>{{ obj.vbid }}</td>
      {% else %}
       <td>{{ obj.isbn }}</td>
      {% endif %}
                    {% if obj.e_price %}
      <td>{{obj.e_price_cur}}{{obj.e_price}}</td>
          {% else %}
          <td></td>
          {% endif %}
  <td>{{obj.Format_issued}}</td>

            <td>{{obj.Distribution_platform}}</td>


      {%endfor%}
  </tr>
{%endfor%}
</table>

所以,这将用空字符串/black替换所有nullish值

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航