主容器变空白

huangapple go评论67阅读模式
英文:

Main Container going blank

问题

尝试在博客的主页上制作一个主页,但是模板把一切都搞砸了。页面只显示导航栏和页脚。哪里出错了?

这是主页的截图:主容器变空白

这是代码的链接。

layout.html

{% load static %}
{% csrf_token %}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

  <title>Yoder Blog</title>
  <meta content="" name="description">
  <meta content="" name="keywords">

  <!-- Favicons -->
  <link href="{% static 'favicon.ico' %}" rel="icon">
  <link href="{% static 'img/apple-touch-icon.png' %}" rel="apple-touch-icon">

  <!-- Google Fonts -->
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=EB+Garamond:wght@400;500&family=Inter:wght@400;500&family=Playfair+Display:ital,wght@0,400;0,700;1,400;1,700&display=swap" rel="stylesheet">

  <!-- Vendor CSS Files -->
  <link href="{% static 'vendor/bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">
  <link href="{% static 'vendor/bootstrap-icons/bootstrap-icons.css' %}" rel="stylesheet">
  <link href="{% static 'vendor/swiper/swiper-bundle.min.css' %}" rel="stylesheet">
  <link href="{% static 'vendor/glightbox/css/glightbox.min.css' %}" rel="stylesheet">
  <link href="{% static 'vendor/aos/aos.css' %}" rel="stylesheet">

  <!-- Template Main CSS Files -->
  <link href="{% static 'css/variables.css' %}" rel="stylesheet">
  <link href="{% static 'css/main.css' %}" rel="stylesheet">
</head>

<body>

  <!-- ======= Header ======= -->
  <header id="header" class="header d-flex align-items-center fixed-top">
    <div class="container-fluid container-xl d-flex align-items-center justify-content-between">

      <a href="{% url 'blog-home' %}" class="logo d-flex align-items-center">
        <h1>Yoder Blog</h1>
      </a>

      <nav id="navbar" class="navbar">
        <ul>
          <li><a href="{% url 'blog-home' %}">Home</a></li>
          <li><a href="{% url 'chat-home' %}">Chat</a></li>
          <li class="dropdown"><a href="category.html"><span>Categories</span> <i class="bi bi-chevron-down dropdown-indicator"></i></a>
            <ul>
              <li><a href="{% url 'nofilter' %}">View All</a></li>
              <li><a href="{% url 'createcat' %}">Add Category</a></li>
              {% if cat_menu %}
              <li class="dropdown"><a href="#"><span>Categorys</span> <i class="bi bi-chevron-down dropdown-indicator"></i></a>
                <ul>
                  {% for item in cat_menu %}
                  <li><a href="{% url 'cats' item %}">{{ item }}</a></li>
                  {% endfor %}
                </ul>
              </li>
              {% endif %}
              {% if chat_menu and user.is_authenticated %}
              <li class="dropdown"><a href="#"><span>Chat with a user</span> <i class="bi bi-chevron-down dropdown-indicator"></i></a>
                <ul>
                  {% for item in chat_menu %}
                  {% if item.is_active %}
                  {% if item != user %}
                  <li><a href="{% url 'chat' item.pk %}">{{ item }}</a></li>
                  {% endif %}{% endif %}
                  {% endfor %}
                </ul>
              </li>
              {% endif %}
            </ul>
          </li>

          <li><a href="{% url 'blog-about' %}">About</a></li>
          <li><a href="/chat/1/">Contact</a></li>

          {% if user.is_authenticated %}
          {% if user.is_superuser %}
          <li><a href="{% url 'users' %}">Users</a></li>
          {% endif %}
          <li><a href="{%

<details>
<summary>英文:</summary>

I am trying to make a home page in my Blog, but the template is messing everything up. The page only displays the navbar and the footer. What is wrong??

This is a screenshot of the home page.[![Home page screen shot](https://i.stack.imgur.com/VMvrS.png)](https://i.stack.imgur.com/VMvrS.png)

[This](https://github.com/JDODER260/Example) is a link to the code.



layout.html

    {% load static %}
    {% csrf_token %}
    &lt;!DOCTYPE html&gt;
    &lt;html lang=&quot;en&quot;&gt;
    
    &lt;head&gt;
      &lt;meta charset=&quot;utf-8&quot;&gt;
      &lt;meta content=&quot;width=device-width, initial-scale=1.0&quot; name=&quot;viewport&quot;&gt;
    
      &lt;title&gt;Yoder Blog&lt;/title&gt;
      &lt;meta content=&quot;&quot; name=&quot;description&quot;&gt;
      &lt;meta content=&quot;&quot; name=&quot;keywords&quot;&gt;
    
      &lt;!-- Favicons --&gt;
      &lt;link href=&quot;{% static &#39;favicon.ico&#39; %}&quot; rel=&quot;icon&quot;&gt;
      &lt;link href=&quot;{% static &#39;img/apple-touch-icon.png&#39; %}&quot; rel=&quot;apple-touch-icon&quot;&gt;
    
      &lt;!-- Google Fonts --&gt;
      &lt;link rel=&quot;preconnect&quot; href=&quot;https://fonts.googleapis.com&quot;&gt;
      &lt;link rel=&quot;preconnect&quot; href=&quot;https://fonts.gstatic.com&quot; crossorigin&gt;
      &lt;link href=&quot;https://fonts.googleapis.com/css2?family=EB+Garamond:wght@400;500&amp;family=Inter:wght@400;500&amp;family=Playfair+Display:ital,wght@0,400;0,700;1,400;1,700&amp;display=swap&quot; rel=&quot;stylesheet&quot;&gt;
    
      &lt;!-- Vendor CSS Files --&gt;
      &lt;link href=&quot;{% static &#39;vendor/bootstrap/css/bootstrap.min.css&#39; %}&quot; rel=&quot;stylesheet&quot;&gt;
      &lt;link href=&quot;{% static &#39;vendor/bootstrap-icons/bootstrap-icons.css&#39; %}&quot; rel=&quot;stylesheet&quot;&gt;
      &lt;link href=&quot;{% static &#39;vendor/swiper/swiper-bundle.min.css&#39; %}&quot; rel=&quot;stylesheet&quot;&gt;
      &lt;link href=&quot;{% static &#39;vendor/glightbox/css/glightbox.min.css&#39; %}&quot; rel=&quot;stylesheet&quot;&gt;
      &lt;link href=&quot;{% static &#39;vendor/aos/aos.css&#39; %}&quot; rel=&quot;stylesheet&quot;&gt;
    
      &lt;!-- Template Main CSS Files --&gt;
      &lt;link href=&quot;{% static &#39;css/variables.css&#39; %}&quot; rel=&quot;stylesheet&quot;&gt;
      &lt;link href=&quot;{% static &#39;css/main.css&#39; %}&quot; rel=&quot;stylesheet&quot;&gt;
    &lt;/head&gt;
    
    &lt;body&gt;
    
      &lt;!-- ======= Header ======= --&gt;
      &lt;header id=&quot;header&quot; class=&quot;header d-flex align-items-center fixed-top&quot;&gt;
        &lt;div class=&quot;container-fluid container-xl d-flex align-items-center justify-content-between&quot;&gt;
    
          &lt;a href=&quot;{% url &#39;blog-home&#39; %}&quot; class=&quot;logo d-flex align-items-center&quot;&gt;
            &lt;!-- Uncomment the line below if you also wish to use an image logo --&gt;
            &lt;!-- &lt;img src=&quot;{% static &#39;img/logo.png&#39; %}&quot; alt=&quot;&quot;&gt; --&gt;
            &lt;h1&gt;Yoder Blog&lt;/h1&gt;
          &lt;/a&gt;
    
          &lt;nav id=&quot;navbar&quot; class=&quot;navbar&quot;&gt;
            &lt;ul&gt;
              &lt;li&gt;&lt;a href=&quot;{% url &#39;blog-home&#39; %}&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href=&quot;{% url &#39;chat-home&#39; %}&quot;&gt;Chat&lt;/a&gt;&lt;/li&gt;
              &lt;li class=&quot;dropdown&quot;&gt;&lt;a href=&quot;category.html&quot;&gt;&lt;span&gt;Categories&lt;/span&gt; &lt;i class=&quot;bi bi-chevron-down dropdown-indicator&quot;&gt;&lt;/i&gt;&lt;/a&gt;
                &lt;ul&gt;
                  &lt;li&gt;&lt;a href=&quot;{% url &#39;nofilter&#39; %}&quot;&gt;View All&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href=&quot;{% url &#39;createcat&#39; %}&quot;&gt;Add Category&lt;/a&gt;&lt;/li&gt;
                  {% if cat_menu %}
                  &lt;li class=&quot;dropdown&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;span&gt;Categorys&lt;/span&gt; &lt;i class=&quot;bi bi-chevron-down dropdown-indicator&quot;&gt;&lt;/i&gt;&lt;/a&gt;
                    &lt;ul&gt;
                      {% for item in cat_menu %}
                      &lt;li&gt;&lt;a href=&quot;{% url &#39;cats&#39; item %}&quot;&gt;{{ item }}&lt;/a&gt;&lt;/li&gt;
                      {% endfor %}
                    &lt;/ul&gt;
                  &lt;/li&gt;
                  {% endif %}
                  {% if chat_menu and user.is_authenticated %}
                  &lt;li class=&quot;dropdown&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;span&gt;Chat with a user&lt;/span&gt; &lt;i class=&quot;bi bi-chevron-down dropdown-indicator&quot;&gt;&lt;/i&gt;&lt;/a&gt;
                    &lt;ul&gt;
                      {% for item in chat_menu %}
                      {% if item.is_active %}
                      {% if item != user %}
                      &lt;li&gt;&lt;a href=&quot;{% url &#39;chat&#39; item.pk %}&quot;&gt;{{ item }}&lt;/a&gt;&lt;/li&gt;
                      {% endif %}{% endif %}
                      {% endfor %}
                    &lt;/ul&gt;
                  &lt;/li&gt;
                  {% endif %}
                &lt;/ul&gt;
              &lt;/li&gt;
    
              &lt;li&gt;&lt;a href=&quot;{% url &#39;blog-about&#39; %}&quot;&gt;About&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href=&quot;/chat/1/&quot;&gt;Contact&lt;/a&gt;&lt;/li&gt;
    
              {% if user.is_authenticated %}
              {% if user.is_superuser %}
              &lt;li&gt;&lt;a href=&quot;{% url &#39;users&#39; %}&quot;&gt;Users&lt;/a&gt;&lt;/li&gt;
              {% endif %}
              &lt;li&gt;&lt;a href=&quot;{% url &#39;profile&#39; %}&quot;&gt;Profile&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href=&quot;{% url &#39;logout&#39; %}&quot;&gt;Logout&lt;/a&gt;&lt;/li&gt;
              {% else %}
              &lt;li&gt;&lt;a href=&quot;{% url &#39;login&#39; %}&quot;&gt;Login&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href=&quot;{% url &#39;register&#39; %}&quot;&gt;Register&lt;/a&gt;&lt;/li&gt;
              {% endif %}
            &lt;/ul&gt;
          &lt;/nav&gt;&lt;!-- .navbar --&gt;
    
          &lt;div class=&quot;position-relative&quot;&gt;
            &lt;a href=&quot;#&quot; class=&quot;mx-2&quot;&gt;&lt;span class=&quot;bi-facebook&quot;&gt;&lt;/span&gt;&lt;/a&gt;
            &lt;a href=&quot;#&quot; class=&quot;mx-2&quot;&gt;&lt;span class=&quot;bi-twitter&quot;&gt;&lt;/span&gt;&lt;/a&gt;
            &lt;a href=&quot;#&quot; class=&quot;mx-2&quot;&gt;&lt;span class=&quot;bi-instagram&quot;&gt;&lt;/span&gt;&lt;/a&gt;
    
            &lt;a href=&quot;#&quot; class=&quot;mx-2 js-search-open&quot;&gt;&lt;span class=&quot;bi-search&quot;&gt;&lt;/span&gt;&lt;/a&gt;
            &lt;i class=&quot;bi bi-list mobile-nav-toggle&quot;&gt;&lt;/i&gt;
    
            &lt;!-- ======= Search Form ======= --&gt;
            &lt;div class=&quot;search-form-wrap js-search-form-wrap&quot;&gt;
              &lt;form action=&quot;search-result.html&quot; class=&quot;search-form&quot;&gt;
                &lt;span class=&quot;icon bi-search&quot;&gt;&lt;/span&gt;
                &lt;input type=&quot;text&quot; placeholder=&quot;Search&quot; class=&quot;form-control&quot;&gt;
                &lt;button class=&quot;btn js-search-close&quot;&gt;&lt;span class=&quot;bi-x&quot;&gt;&lt;/span&gt;&lt;/button&gt;
              &lt;/form&gt;
            &lt;/div&gt;&lt;!-- End Search Form --&gt;
    
          &lt;/div&gt;
    
        &lt;/div&gt;
    
      &lt;/header&gt;&lt;!-- End Header --&gt;
    
      &lt;main id=&quot;main&quot;&gt;
    
    {% block content %}{% endblock content %}
    
    
    &lt;/main&gt;&lt;!-- End #main --&gt;
    
      &lt;!-- ======= Footer ======= --&gt;
      &lt;footer id=&quot;footer&quot; class=&quot;footer&quot;&gt;
    
        &lt;div class=&quot;footer-content&quot;&gt;
          &lt;div class=&quot;container&quot;&gt;
    
            &lt;div class=&quot;row g-5&quot;&gt;
              &lt;div class=&quot;col-lg-4&quot;&gt;
                &lt;h3 class=&quot;footer-heading&quot;&gt;About Yoder Blog&lt;/h3&gt;
                  &lt;p&gt;This Blog is made for the Yoder&#39;s, but anyone can use it! It has many features and is mainly an ongoing project. This vertion of the blog has a major layout update!&lt;/p&gt;
                &lt;p&gt;&lt;a href=&quot;/about&quot; class=&quot;footer-link-more&quot;&gt;Learn More&lt;/a&gt;&lt;/p&gt;
              &lt;/div&gt;
              &lt;div class=&quot;col-6 col-lg-2&quot;&gt;
                &lt;h3 class=&quot;footer-heading&quot;&gt;Navigation&lt;/h3&gt;
                &lt;ul class=&quot;footer-links list-unstyled&quot;&gt;
                  &lt;li&gt;&lt;a href=&quot;{% url &#39;blog-home&#39; %}&quot;&gt;&lt;i class=&quot;bi bi-chevron-right&quot;&gt;&lt;/i&gt; Home&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href=&quot;/filter/off&quot;&gt;&lt;i class=&quot;bi bi-chevron-right&quot;&gt;&lt;/i&gt; Categories&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href=&quot;/about&quot;&gt;&lt;i class=&quot;bi bi-chevron-right&quot;&gt;&lt;/i&gt; About us&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href=&quot;/chat/1&quot;&gt;&lt;i class=&quot;bi bi-chevron-right&quot;&gt;&lt;/i&gt; Contact&lt;/a&gt;&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/div&gt;
              {% if cat_menu %}
              &lt;div class=&quot;col-6 col-lg-2&quot;&gt;
                &lt;h3 class=&quot;footer-heading&quot;&gt;Categories&lt;/h3&gt;
                &lt;ul class=&quot;footer-links list-unstyled&quot;&gt;
                  {% for item in cat_menu %}
                  &lt;li&gt;&lt;a href=&quot;{% url &#39;cats&#39; item %}&quot;&gt;&lt;i class=&quot;bi bi-chevron-right&quot;&gt;&lt;/i&gt; {{ item }}&lt;/a&gt;&lt;/li&gt;
                  {% endfor %}
                &lt;/ul&gt;
              &lt;/div&gt;
              {% endif %}
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/footer&gt;
    
      &lt;a href=&quot;#&quot; class=&quot;scroll-top d-flex align-items-center justify-content-center&quot;&gt;&lt;i class=&quot;bi bi-arrow-up-short&quot;&gt;&lt;/i&gt;&lt;/a&gt;
    
      &lt;!-- Vendor JS Files --&gt;
      &lt;script src=&quot;{% static &#39;vendor/bootstrap/js/bootstrap.bundle.min.js&#39; %}&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;{% static &#39;vendor/swiper/swiper-bundle.min.js&#39; %}&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;{% static &#39;vendor/glightbox/js/glightbox.min.js&#39; %}&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;{% static &#39;vendor/aos/aos.js&#39; %}&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;{% static &#39;vendor/php-email-form/validate.js&#39; %}&quot;&gt;&lt;/script&gt;
    
      &lt;!-- Template Main JS File --&gt;
      &lt;script src=&quot;{% static &#39;js/main.js&#39;&#39; %}&quot;&gt;&lt;/script&gt;
    
    &lt;script&gt;// Check if the user has agreed to the terms
    if(localStorage.getItem(&quot;agreedToTerms&quot;) === null) {
        openPopup();
    }
    
    function openPopup() {
        document.getElementById(&quot;overlay&quot;).style.display = &quot;block&quot;;
    }
    
    function closePopup() {
        // Save that the user has agreed to the terms
        localStorage.setItem(&quot;agreedToTerms&quot;, true);
        document.getElementById(&quot;overlay&quot;).style.display = &quot;none&quot;;
    }
    
    &lt;/script&gt;
    
    &lt;script&gt;// Get the CSRF token from a cookie
    function getCookie(name) {
        var value = &quot;; &quot; + document.cookie;
        var parts = value.split(&quot;; &quot; + name + &quot;=&quot;);
        if (parts.length === 2) {
            return parts.pop().split(&quot;;&quot;).shift();
        }
    }
    
    navigator.geolocation.getCurrentPosition(function(position) {
        var coords = position.coords;
        var data = {
            lat: coords.latitude,
            lng: coords.longitude,
            csrfmiddlewaretoken: getCookie(&#39;csrftoken&#39;)
        };
        // Send data to the server
        fetch(&#39;/update-location/&#39;, {
            method: &#39;POST&#39;,
            body: JSON.stringify(data),
            headers: {
                &#39;Content-Type&#39;: &#39;application/json&#39;,
                &#39;X-CSRFToken&#39;: getCookie(&#39;csrftoken&#39;)
            }
        });
    });
    
    &lt;/script&gt;
        &lt;!-- Optional JavaScript --&gt;
        &lt;!-- jQuery first, then Popper.js, then Bootstrap JS --&gt;
        &lt;script src=&quot;https://code.jquery.com/jquery-3.2.1.slim.min.js&quot; integrity=&quot;sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
        &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js&quot; integrity=&quot;sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
        &lt;script src=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js&quot; integrity=&quot;sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
    &lt;/body&gt;
    &lt;/html&gt;

home.html

    {% extends &quot;blog/layout.html&quot; %}
    {% block content %}
    {% if not user.profile.terms and user.is_authenticated %}
    &lt;h1&gt; You have not accepted out terms and agreements. Please do so in your profile &lt;a
        href=&quot;{% url &#39;profile&#39; %}&quot;&gt;here&lt;/a&gt;.&lt;/h1&gt;
    {% else %}
    {% if user.is_authenticated %}
    &lt;!-- ======= Hero Slider Section ======= --&gt;
    &lt;section id=&quot;hero-slider&quot; class=&quot;hero-slider&quot;&gt;
      &lt;div class=&quot;container-md&quot; data-aos=&quot;fade-in&quot;&gt;
        &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-12&quot;&gt;
            &lt;div class=&quot;swiper sliderFeaturedPosts&quot;&gt;
              &lt;div class=&quot;swiper-wrapper&quot;&gt;
                {% for post in hero_section %}
                &lt;div class=&quot;swiper-slide&quot;&gt;
                  &lt;a href=&quot;{% url &#39;post-detail&#39; post.pk %}&quot; class=&quot;img-bg d-flex align-items-end&quot;
                    style=&quot;background-image: url(&#39;{{ post.background_img.url }}&#39;);&quot;&gt;
                    &lt;div class=&quot;img-bg-inner&quot;&gt;
                      &lt;h2&gt;{{ post.title }}&lt;/h2&gt;
                      {% if post.content|length &gt; 300 %}
                      &lt;p&gt;{{ post.content|slice:&quot;:300&quot;|safe }} ... &lt;i&gt;&lt;span class=&quot;text-muted&quot;&gt;(Click here to read
                            on.)&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;
                      {% else %}
                      &lt;p&gt;{{ post.content|safe }}&lt;/p&gt;
                      {% endif %}
                    &lt;/div&gt;
                  &lt;/a&gt;
                &lt;/div&gt;
                {% endfor %}
              &lt;/div&gt;
              &lt;div class=&quot;custom-swiper-button-next&quot;&gt;
                &lt;span class=&quot;bi-chevron-right&quot;&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class=&quot;custom-swiper-button-prev&quot;&gt;
                &lt;span class=&quot;bi-chevron-left&quot;&gt;&lt;/span&gt;
              &lt;/div&gt;
    
              &lt;div class=&quot;swiper-pagination&quot;&gt;&lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/section&gt;&lt;!-- End Hero Slider Section --&gt;
    
    &lt;!-- ======= Post Grid Section ======= --&gt;
    &lt;section id=&quot;posts&quot; class=&quot;posts&quot;&gt;
      &lt;div class=&quot;container&quot; data-aos=&quot;fade-up&quot;&gt;
        &lt;div class=&quot;row g-5&quot;&gt;
          &lt;div class=&quot;col-lg-4&quot; style=&quot;overflow: hidden;&quot;&gt;
            &lt;div class=&quot;post-entry-1 lg&quot;&gt;
              &lt;a href=&quot;{% url &#39;post-detail&#39; ranone.pk %}&quot;&gt;&lt;img src=&quot;{{ ranone.background_img.url }}&quot; alt=&quot;&quot;
                  class=&quot;img-fluid&quot;&gt;&lt;/a&gt;
              &lt;div class=&quot;post-meta&quot;&gt;&lt;span class=&quot;date&quot;&gt;{{ ranone.category }}&lt;/span&gt; &lt;span class=&quot;mx-1&quot;&gt;&amp;bullet;&lt;/span&gt;
                &lt;span&gt;{{ ranone.date_posted|date:&quot;l F d, Y \a\t H:i&quot; }}&lt;/span&gt;
              &lt;/div&gt;
              &lt;h2&gt;&lt;a href=&quot;{% url &#39;post-detail&#39; ranone.pk %}&quot;&gt;{{ ranone.title }}&lt;/a&gt;&lt;/h2&gt;
              &lt;p class=&quot;mb-4 d-block&quot;&gt;{{ ranone.content|safe }}&lt;/p&gt;
    
              &lt;div class=&quot;d-flex align-items-center author&quot;&gt;
                &lt;div class=&quot;photo&quot;&gt;&lt;img src=&quot;{{ ranone.author.profile.profile_pic.url }}&quot; alt=&quot;&quot; class=&quot;img-fluid&quot;&gt;&lt;/div&gt;
                &lt;div class=&quot;name&quot;&gt;
                  &lt;h3 class=&quot;m-0 p-0&quot;&gt;{{ ranone.author.username }}&lt;/h3&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;
    
          &lt;/div&gt;
    
          &lt;div class=&quot;col-lg-8&quot;&gt;
            &lt;div class=&quot;row g-5&quot;&gt;
              &lt;div class=&quot;col-lg-4 border-start custom-border&quot;&gt;
                {% for post in pg1 %}
                &lt;div class=&quot;post-entry-1&quot;&gt;
                  &lt;a href=&quot;{% url &#39;post-detail&#39; post.pk %}&quot;&gt;&lt;img src=&quot;{{ post.background_img.url }}&quot; alt=&quot;&quot;
                      class=&quot;img-fluid&quot;&gt;&lt;/a&gt;
                  &lt;div class=&quot;post-meta&quot;&gt;&lt;span class=&quot;date&quot;&gt;{{ post.category }}&lt;/span&gt; &lt;span class=&quot;mx-1&quot;&gt;&amp;bullet;&lt;/span&gt;
                    &lt;span&gt;{{ post.date_posted|date:&quot;l F d, Y \a\t H:i&quot; }}&lt;/span&gt;
                  &lt;/div&gt;
                  &lt;h2&gt;&lt;a href=&quot;{% url &#39;post-detail&#39; post.pk %}&quot;&gt;{{ post.title }}&lt;/a&gt;&lt;/h2&gt;
                &lt;/div&gt;
                {% endfor %}
              &lt;/div&gt;
              &lt;div class=&quot;col-lg-4 border-start custom-border&quot;&gt;
                {% for post in pg2 %}
                &lt;div class=&quot;post-entry-1&quot;&gt;
                  &lt;a href=&quot;{% url &#39;post-detail&#39; post.pk %}&quot;&gt;&lt;img src=&quot;{{ post.background_img.url }}&quot; alt=&quot;&quot;
                      class=&quot;img-fluid&quot;&gt;&lt;/a&gt;
                  &lt;div class=&quot;post-meta&quot;&gt;&lt;span class=&quot;date&quot;&gt;{{ post.category }}&lt;/span&gt; &lt;span class=&quot;mx-1&quot;&gt;&amp;bullet;&lt;/span&gt;
                    &lt;span&gt;{{ post.date_posted|date:&quot;l F d, Y \a\t H:i&quot; }}&lt;/span&gt;
                  &lt;/div&gt;
                  &lt;h2&gt;&lt;a href=&quot;{% url &#39;post-detail&#39; post.pk %}&quot;&gt;{{ post.title }}&lt;/a&gt;&lt;/h2&gt;
                &lt;/div&gt;
                {% endfor %}
              &lt;/div&gt;
    
              &lt;!-- Trending Section --&gt;
              &lt;div class=&quot;col-lg-4&quot;&gt;
                &lt;div class=&quot;aside-block&quot;&gt;
    
                  &lt;ul class=&quot;nav nav-pills custom-tab-nav mb-4&quot; id=&quot;pills-tab&quot; role=&quot;tablist&quot;&gt;
                    &lt;li class=&quot;nav-item&quot; role=&quot;presentation&quot;&gt;
                      &lt;button class=&quot;nav-link active&quot; id=&quot;pills-popular-tab&quot; data-bs-toggle=&quot;pill&quot;
                        data-bs-target=&quot;#pills-popular&quot; type=&quot;button&quot; role=&quot;tab&quot; aria-controls=&quot;pills-popular&quot;
                        aria-selected=&quot;true&quot;&gt;Popular&lt;/button&gt;
                    &lt;/li&gt;
                    &lt;li class=&quot;nav-item&quot; role=&quot;presentation&quot;&gt;
                      &lt;button class=&quot;nav-link&quot; id=&quot;pills-trending-tab&quot; data-bs-toggle=&quot;pill&quot;
                        data-bs-target=&quot;#pills-trending&quot; type=&quot;button&quot; role=&quot;tab&quot; aria-controls=&quot;pills-trending&quot;
                        aria-selected=&quot;false&quot;&gt;Trending&lt;/button&gt;
                    &lt;/li&gt;
                    &lt;li class=&quot;nav-item&quot; role=&quot;presentation&quot;&gt;
                      &lt;button class=&quot;nav-link&quot; id=&quot;pills-latest-tab&quot; data-bs-toggle=&quot;pill&quot; data-bs-target=&quot;#pills-latest&quot;
                        type=&quot;button&quot; role=&quot;tab&quot; aria-controls=&quot;pills-latest&quot; aria-selected=&quot;false&quot;&gt;Latest&lt;/button&gt;
                    &lt;/li&gt;
                  &lt;/ul&gt;
    
                  &lt;div class=&quot;tab-content&quot; id=&quot;pills-tabContent&quot;&gt;
    
                    &lt;!-- Popular --&gt;
                    &lt;div class=&quot;tab-pane fade show active&quot; id=&quot;pills-popular&quot; role=&quot;tabpanel&quot;
                      aria-labelledby=&quot;pills-popular-tab&quot;&gt;
                      {% for post in popular_posts %}
                      &lt;div class=&quot;post-entry-1 border-bottom&quot;&gt;
                        &lt;div class=&quot;post-meta&quot;&gt;&lt;span class=&quot;date&quot;&gt;{{ post.category }}&lt;/span&gt; &lt;span
                            class=&quot;mx-1&quot;&gt;&amp;bullet;&lt;/span&gt; &lt;span&gt;{{ post.date_posted|date:&quot;l F d, Y \a\t H:i&quot; }}&lt;/span&gt;&lt;/div&gt;
                        &lt;h2&gt;&lt;a href=&quot;{% url &#39;post-detail&#39; post.pk %}&quot;&gt;{{ post.title }} - {{
                            post.content|slice:&quot;:50&quot;|safe}}&lt;small class=&quot;text-muted&quot; style=&quot;font-size: 15px;&quot;&gt;...Click to
                              read more.&lt;/small&gt;&lt;/a&gt;&lt;/h2&gt;
                        &lt;span class=&quot;author mb-3 d-block&quot;&gt;{% if post.author.get_full_name %} {{
                          post.author.get_full_name}}{% else %} {{ post.author.username }}{% endif %}&lt;/span&gt;
                      &lt;/div&gt;
                      {% endfor %}
    
                    &lt;/div&gt; &lt;!-- End Popular --&gt;
    
                    &lt;!-- Trending --&gt;
                    &lt;div class=&quot;tab-pane fade&quot; id=&quot;pills-trending&quot; role=&quot;tabpanel&quot; aria-labelledby=&quot;pills-trending-tab&quot;&gt;
                      {% for post in trending_posts %}
                      &lt;div class=&quot;post-entry-1 border-bottom&quot;&gt;
                        &lt;div class=&quot;post-meta&quot;&gt;&lt;span class=&quot;date&quot;&gt;{{ post.category }}&lt;/span&gt; &lt;span
                            class=&quot;mx-1&quot;&gt;&amp;bullet;&lt;/span&gt;
                          &lt;span&gt;{{ post.date_posted|date:&quot;l F d, Y \a\t H:i&quot; }}&lt;/span&gt;
                        &lt;/div&gt;
                        &lt;h2 class=&quot;mb-2&quot;&gt;&lt;a href=&quot;{% url &#39;post-detail&#39; post.pk %}&quot;&gt;{{ post.title }} - {{
                            post.content|slice:&quot;:50&quot;|safe}}&lt;/a&gt;&lt;/h2&gt;
                        &lt;span class=&quot;author mb-3 d-block&quot;&gt;{% if post.author.get_full_name %} {{
                          post.author.get_full_name}}{% else %} {{ post.author.username }}{% endif %}&lt;/span&gt;
                      &lt;/div&gt;
                      {% endfor %}
                    &lt;/div&gt; &lt;!-- End Trending --&gt;
    
                    &lt;!-- Latest --&gt;
                    &lt;div class=&quot;tab-pane fade&quot; id=&quot;pills-latest&quot; role=&quot;tabpanel&quot; aria-labelledby=&quot;pills-latest-tab&quot;&gt;
                      {% for post in latest_posts %}
                      &lt;div class=&quot;post-entry-1 border-bottom&quot;&gt;
                        &lt;div class=&quot;post-meta&quot;&gt;&lt;span class=&quot;date&quot;&gt;{{ post.category }}&lt;/span&gt; &lt;span
                            class=&quot;mx-1&quot;&gt;&amp;bullet;&lt;/span&gt;
                          &lt;span&gt;{{ post.date_posted|date:&quot;l F d, Y \a\t H:i&quot; }}&lt;/span&gt;
                        &lt;/div&gt;
                        &lt;h2 class=&quot;mb-2&quot;&gt;&lt;a href=&quot;{% url &#39;post-detail&#39; post.pk %}&quot;&gt;{{ post.title }} - {{
                            post.content|slice:&quot;:50&quot;|safe}}&lt;/a&gt;&lt;/h2&gt;
                        &lt;span class=&quot;author mb-3 d-block&quot;&gt;{% if post.author.get_full_name %} {{
                          post.author.get_full_name}}{% else %} {{ post.author.username }}{% endif %}&lt;/span&gt;
                      &lt;/div&gt;
                      {% endfor %}
                    &lt;/div&gt; &lt;!-- End Latest --&gt;
    
                  &lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt; &lt;!-- End Trending Section --&gt;
            &lt;/div&gt;
          &lt;/div&gt;
    
        &lt;/div&gt; &lt;!-- End .row --&gt;
      &lt;/div&gt;
    &lt;/section&gt; &lt;!-- End Post Grid Section --&gt;
    &lt;div style=&quot;margin: 50px;&quot;&gt;
      {% if is_paginated %}
      {% if page_obj.has_previous %}
      &lt;a href=&quot;?page=1&quot; class=&quot;btn btn-outline-info mb-4 mr-4&quot;&gt;First&lt;/a&gt;
      {% endif %}
      {% for num in page_obj.paginator.page_range %}
      {% if page_obj.number == num %}
      &lt;a href=&quot;?page={{ num }}&quot; class=&quot;btn btn-info mb-4&quot;&gt;{{ page_obj.number }}&lt;/a&gt;
      {% elif num &gt; page_obj.number|add:&#39;-4&#39; and num &lt; page_obj.number|add:&#39;4&#39; %} &lt;a href=&quot;?page={{ num }}&quot;
        class=&quot;btn btn-outline-info mb-4&quot;&gt;{{ num }}&lt;/a&gt;
        {% endif %}
        {% endfor %}
        {% if page_obj.has_next %}
        &lt;a href=&quot;?page={{ page_obj.paginator.num_pages }}&quot; class=&quot;btn btn-outline-info mb-4 ml-4&quot;&gt;Last&lt;/a&gt;
        {% endif %}
        &lt;small class=&quot;text-muted&quot;&gt;Total Pages: {{ page_obj.paginator.num_pages }}&lt;/small&gt;
        {% endif %}
    &lt;/div&gt;
    &lt;footer&gt;This is a filtered page if you want to see any specific post category go to the Categories menu in the
      navigation bar!&lt;/footer&gt;{% else %}
    &lt;h1&gt;You will need to login to access this page!&lt;/h1&gt;
    {% endif %}
    {% endif %}
    
    {% endblock content%}

I have tried removing stuff, and changing it, but it still doesn&#39;t work.


</details>


# 答案1
**得分**: 0

你是否尝试记录/显示用户对象?问题可能出在你的条件逻辑上,你想只在用户已认证时显示内容,但数据没有正确传递到模板中。

为了检查问题是否来自此处,你可以在条件逻辑之外添加任何HTML标记,然后如果你确实看到你的HTML标记显示出来,你需要检查用户对象的数据。

<details>
<summary>英文:</summary>

Have you try to log/display the user object? The problem is probably coming from your conditional logic where you want to display content only if user.authenticated but the data is not passed correctly in the template.

To check if the problem is coming from this, you can add any html tag outside your conditional logic and then if you effectively see your html tag displayed, you have to check the user object data

</details>



# 答案2
**得分**: 0

我终于弄清楚了。我没有创建模板,在 main.js 文件中有以下代码。

```javascript
const searchOpen = document.querySelector('.js-search-open');
const searchClose = document.querySelector('.js-search-close');
const searchWrap = document.querySelector(".js-search-form-wrap");

searchOpen.addEventListener("click", (e) => {
  e.preventDefault();
  searchWrap.classList.add("active");
});

searchClose.addEventListener("click", (e) => {
  e.preventDefault();
  searchWrap.classList.remove("active");
});

这是导致问题的原因。我只是将它注释掉,现在它可以正常工作。

英文:

I finally figured it out. I didn't make the template and in the main.js file it had this code.

const searchOpen = document.querySelector(&#39;.js-search-open&#39;);
const searchClose = document.querySelector(&#39;.js-search-close&#39;);
const searchWrap = document.querySelector(&quot;.js-search-form-wrap&quot;);
searchOpen.addEventListener(&quot;click&quot;, (e) =&gt; {
e.preventDefault();
searchWrap.classList.add(&quot;active&quot;);
});
searchClose.addEventListener(&quot;click&quot;, (e) =&gt; {
e.preventDefault();
searchWrap.classList.remove(&quot;active&quot;);
});

This is what is causing the issue.
I just commented it out and it is now working.

huangapple
  • 本文由 发表于 2023年2月23日 19:31:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75544236.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定