首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么这些模特没有出现在django网站上

为什么这些模特没有出现在django网站上
EN

Stack Overflow用户
提问于 2020-10-29 03:33:43
回答 1查看 75关注 0票数 0

我正在制作一个新闻网站,我做了一个模型的图像,标题,描述,url(可点击的图像),但最终的输出不只是显示和没有错误。

还请查看我附加的输出屏幕截图和管理页面截图的图片链接

主代码

代码语言:javascript
复制
{% load static %}
{% block content %}

<!DOCTYPE html>
<html>
<head>
    <!-- Required meta tags -->
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>World Vision</title>
    <!-- plugin css for this page -->
    <link
      rel="stylesheet"
      href="{% static 'techworld/assets/vendors/mdi/css/materialdesignicons.min.css' %}"
    />
    <link rel="stylesheet" href="{% static 'techworld/assets/vendors/aos/dist/aos.css/aos.css' %}" />
    <link
      rel="stylesheet"
      href="{% static 'techworld/assets/vendors/owl.carousel/dist/assets/owl.carousel.min.css' %}"
    />
    <link
      rel="stylesheet"
      href="{% static 'techworld/assets/vendors/owl.carousel/dist/assets/owl.theme.default.min.css' %}"
    />
    <!-- End plugin css for this page -->
    <link rel="shortcut icon" href="{% static 'techworld/assets/images/favicon.png' %}" />
    <!-- inject:css -->
    <link rel="stylesheet" href="{% static 'techworld/assets/css/style.css' %}">
    <!-- endinject -->


    <!-- Bootstrap -->
    <link href="{% static 'techworld/box/css/bootstrap.min.css' %}" rel="stylesheet">
    <link href="{% static 'techworld/box/ionicons/css/ionicons.min.css' %}" rel="stylesheet">

    <!-- main css -->
    <link href="{% static 'techworld/box/css/style.css' %}" rel="stylesheet">


    <!-- modernizr -->
    <script src="{% static 'techworld/box/js/modernizr.js' %}"></script>


    <link
      rel="stylesheet"
      href="{% static 'techworld/worldtime/assets/vendors/mdi/css/materialdesignicons.min.css' %}"
    />
    <link rel="stylesheet" href="{% static 'techworld/worldtime/assets/vendors/aos/dist/aos.css/aos.css' %}" />

    <!-- End plugin css for this page -->
    <link rel="shortcut icon" href="{% static 'techworld/worldtime/assets/images/favicon.png' %}" />

    <!-- inject:css -->
    <link rel="stylesheet" href="{% static 'techworld/worldtime/assets/css/style.css' %}">
    <!-- endinject -->


    <title>Tech-World</title>
</head>
<body>
  <!-- Preloader -->
    <div id="preloader">
        <div class="pre-container">
            <div class="spinner">
                <div class="double-bounce1"></div>
                <div class="double-bounce2"></div>
            </div>
        </div>
    </div>
    <!-- end Preloader -->
<!--  Intro Slide  
  <div class="container-fluid">
    
    <section class="box-intro">
      <div class="table-sell">
        <h1 class="box-headline letters rotate-2">
          <span class="box-words-wrapper">
            <b class="is-visible">Choose What you Read</b>
            <b>&nbsp;To see all the latest talks Scroll down</b>
          </span>
        </h1>
        <h5>More than everything You need</h5>
      </div>

      <div class="mouse">
        <div class="scroll"></div>
      </div>
    </section>
  </div>-->
  <!--  End Intro slide  -->
  <div class="container-fluid">
        <!-- box header -->
        
        <!-- end box header -->

        

        <!-- box-intro -->
        <section class="box-intro">
            <div class="table-cell">
                <h1 class="box-headline letters rotate-2">
                    <span class="box-words-wrapper">
                        <b class="is-visible">design. mbkm</b>
                        <b>&nbsp;coding.</b>
                        <b>graphic.</b>
                    </span>
            </h1>
                <h5>We always server more than everythin you need </h5>
            </div>

            <div class="mouse">
                <div class="scroll"></div>
            </div>
        </section>
        <!-- end box-intro -->
    </div>

    <!-- portfolio div -->
    <div class="portfolio-div">
        <div class="portfolio">
            <div class="no-padding portfolio_container">
                <!-- single work -->
                <div class="col-md-3 col-sm-6  fashion logo">
                    <a href="single-project.html" class="portfolio_item">
                        <img src="{% static 'techworld/img/apple.png' %}" alt="image" class="img-responsive" />
                        <div class="portfolio_item_hover">
                            <div class="portfolio-border clearfix">
                                <div class="item_info">
                                    <span>Latest Talks from Apple</span>
                                    <em>Apple TechWorld</em>
                                </div>
                            </div>
                        </div>
                    </a>
                </div>
                <!-- end single work -->


                <div class="col-md-3 col-sm-6 ads graphics">
                        <a href="#" class="portfolio_item">
                            <img src="{% static 'techworld/img/tablet.png' %}" alt="image" class="img-responsive" />
                            <div class="portfolio_item_hover">
                                <div class="portfolio-border clearfix">
                                    <div class="item_info">
                                        <span>Latest Productivity Tablets</span>
                                        <em>Latest Tablets</em>
                                    </div>
                                </div>
                            </div>
                        </a>
                </div>


                <div class="col-md-6 col-sm-12 photography">
                    <a href="#" class="portfolio_item">
                        <img src="{% static 'techworld/img/mobile.jpg' %}" alt="image" class="img-responsive" />
                        <div class="portfolio_item_hover">
                            <div class="portfolio-border clearfix">
                                <div class="item_info">
                                    <span>Its all About SmartPhones</span>
                                    <em>Reviews,Latest news and much more</em>
                                </div>
                            </div>
                        </div>
                    </a>
                </div>


                <!--  Single workflow area end   -->
                <!--  Dual workflow area part 2  -->

                <div class="col-md-3 col-sm-6 fashion ads">
                    <a href="#" class="portfolio_item">
                        <img src="{% static 'techworld/img/samsung.png' %}" alt="image" class="img-responsive" />
                        <div class="portfolio_item_hover">
                            <div class="portfolio-border clearfix">
                                <div class="item_info">
                                    <span>Empty space</span>
                                    <em>Empty space</em>
                                </div>
                            </div>
                        </div>
                    </a>
                </div>


                <div class="col-md-3 col-sm-6 graphics ads">
                    <a href="#" class="portfolio_item">
                        <img src="{% static 'techworld/img/samsung.png' %}" alt="image" class="img-responsive" />
                        <div class="portfolio_item_hover">
                            <div class="portfolio-border clearfix">
                                <div class="item_info">
                                    <span>Empty space</span>
                                    <em>Empty space</em>
                                </div>
                            </div>
                        </div>
                    </a>
                </div>


                <div class="col-md-6 col-sm-12 photography">
                    <a href="#" class="portfolio_item">
                        <img src="{% static 'techworld/img/samsung.png' %}" alt="image" class="img-responsive" />
                        <div class="portfolio_item_hover">
                            <div class="portfolio-border clearfix">
                                <div class="item_info">
                                    <span>Empty space</span>
                                    <em>Empty space</em>
                                </div>
                            </div>
                        </div>
                    </a>
                </div>


                <div class="col-md-3 col-sm-6 graphics ads">
                    <a href="#" class="portfolio_item">
                        <img src="{% static 'techworld/img/samsung.png' %}" alt="image" class="img-responsive" />
                        <div class="portfolio_item_hover">
                            <div class="portfolio-border clearfix">
                                <div class="item_info">
                                    <span>Empty space</span>
                                    <em>Empty space</em>
                                </div>
                            </div>
                        </div>
                    </a>
                </div>


                <div class="col-md-3 col-sm-6 graphics ads">
                    <a href="#" class="portfolio_item">
                        <img src="{% static 'techworld/img/samsung.png' %}" alt="image" class="img-responsive" />
                        <div class="portfolio_item_hover">
                            <div class="portfolio-border clearfix">
                                <div class="item_info">
                                    <span>Empty space</span>
                                    <em>Empty space</em>
                                </div>
                            </div>
                        </div>
                    </a>
                </div>


                <div class="col-md-3 col-sm-6 graphics ads">
                    <a href="#" class="portfolio_item">
                        <img src="{% static 'techworld/img/samsung.png' %}" alt="image" class="img-responsive" />
                        <div class="portfolio_item_hover">
                            <div class="portfolio-border clearfix">
                                <div class="item_info">
                                    <span>Empty space</span>
                                    <em>Empty space</em>
                                </div>
                            </div>
                        </div>
                    </a>
                </div>


                <div class="col-md-3 col-sm-6 graphics ads">
                    <a href="#" class="portfolio_item">
                        <img src="{% static 'techworld/img/samsung.png' %}" alt="image" class="img-responsive" />
                        <div class="portfolio_item_hover">
                            <div class="portfolio-border clearfix">
                                <div class="item_info">
                                    <span>Empty space</span>
                                    <em>Empty space</em>
                                </div>
                            </div>
                        </div>
                    </a>
                </div>






                
            </div>
            <!-- end portfolio_container -->
        </div>
        <!-- portfolio -->
    </div>
    <!-- end portfolio div -->

    <br>
    <br>
    <br>



<div class="container-scroller">
      <div class="main-panel">
        <!-- partial:partials/_navbar.html -->
        

        <!-- partial -->
        
        <div class="content-wrapper">
          <div class="container">
            <div class="row" data-aos="fade-up">
              {% for AllProject in allprojects %}
              <div class="col-xl-8 stretch-card grid-margin">
                <div class="position-relative">
                  {% if AllProject.url %}
                  <a href="{{ AllProject.url }}"><img
                    src="{{ AllProject.image.url }}"
                    alt="banner"
                    class="img-fluid" />
                  </a>
                  {% else %}
                  <img src="{{ AllProject.image.url }}" alt="banner" class="img-fluid" />
                  {% endif %}
                  
                  <div class="banner-content">
                    <div class="badge badge-danger fs-12 font-weight-bold mb-3">
                      global news
                    </div>
                    <h1 class="mb-0">{{ AllProject.title }}</h1>
                    <h1 class="mb-2">
                      {{ AllProject.description }}
                    </h1>
                    <div class="fs-12">
                      <span class="mr-2">Photo </span>10 Minutes ago
                    </div>
                  </div>
                </div>
              </div>
              {% endfor %}
              
              
            </div>
            <div class="row" data-aos="fade-up">
              <div class="col-lg-3 stretch-card grid-margin">
                <div class="card">
                  <div class="card-body">
                    <h2>Category</h2>
                    <ul class="vertical-menu">
                      <li><a href="#">Politics</a></li>
                      <li><a href="#">International</a></li>
                      <li><a href="#">Finance</a></li>
                      <li><a href="#">Health care</a></li>
                      <li><a href="#">Technology</a></li>
                      <li><a href="#">Jobs</a></li>
                      <li><a href="#">Media</a></li>
                      <li><a href="#">Administration</a></li>
                      <li><a href="#">Sports</a></li>
                      <li><a href="#">Game</a></li>
                      <li><a href="#">Art</a></li>
                      <li><a href="#">Kids</a></li>
                    </ul>
                  </div>
                </div>
              </div>
              <div class="col-lg-9 stretch-card grid-margin">
                <div class="card">
                  <div class="card-body">
                    {% for Flash in flashes %}
                    <div class="row">
                      
                      <div class="col-sm-4 grid-margin">
                        <div class="position-relative">
                          <div class="rotate-img">
                            {% if Flash.url %}
                            <a href="{{ Flash.url }}">
                              <img src="{{ project.image.url }}" alt="thumb" class="img-fluid" />
                            </a>
                            {% else %}
                            <img src="{{ project.image.url }}" alt="thumb" class="img-fluid" />
                            {% endif %}
                          </div>
                          <div class="badge-positioned">
                            <span class="badge badge-danger font-weight-bold"
                              >Flash news</span
                            >
                          </div>
                        </div>
                      </div>
                      <div class="col-sm-8  grid-margin">
                        <h2 class="mb-2 font-weight-600">
                          {{ Flash.title }}
                        </h2>
                        <div class="fs-13 mb-2">
                          <span class="mr-2">Photo </span>10 Minutes ago
                        </div>
                        <p class="mb-0">
                          {{ Flash.description }}
                        </p>
                      </div>
                    </div>
                    {% endfor %}
              {% endblock %}

                    
                  </div>
                </div>
              </div>
            </div>

Views.py

代码语言:javascript
复制
from django.shortcuts import render
from .models import AllProject
from .models import Flash


def techhome(request):
    allprojects = AllProject.objects.all()
    return render(request, 'techworld/techhome.html', {'allprojects':allprojects})

def Flashnews(request):
    flashes = Flash.objects.all()
    return render(request, 'techworld/techhome1.html', {'flashes':flashes})

Models.py

代码语言:javascript
复制
from django.db import models

class AllProject(models.Model):
    title = models.CharField(max_length=100)
    description = models.CharField(max_length=250)
    image = models.ImageField(upload_to='techworld/images/')
    url = models.URLField(blank=True)
    date = models.DateField(blank=True)

    def __str__(self):
        return self.title


class Flash(models.Model):
    title = models.CharField(max_length=100)
    description = models.CharField(max_length=250)
    image = models.ImageField(upload_to='techworld/images/')
    url = models.URLField(blank=True)
    date = models.DateField(blank=True)

    def __str__(self):
        return self.title

也请查看图片链接,我已经附加了输出屏幕和管理页面屏幕截图

EN

回答 1

Stack Overflow用户

发布于 2020-11-02 04:29:22

您在模板中同时使用了allprojectsflashes,但是可以将它们在单独的视图中传递给不同的模板。

不清楚(至少对我来说)这些视图中哪些与此模板相对应。我猜您正在尝试使用techhome()视图,因为您似乎无法获得闪存数据。您需要将allprojectsflashes作为context传递给模板,这样就可以呈现它们。例如,如果希望techhome()同时显示两者,则可以执行以下操作:

代码语言:javascript
复制
def techhome(request):
    allprojects = AllProject.objects.all()
    flashes = Flash.objects.all()
    context = {'allprojects':allprojects, 'flashes':flashes}
    return render(request, 'techworld/techhome.html', context)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64584616

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档