Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django不显示数据库项_Python_Html_Django_Database - Fatal编程技术网

Python Django不显示数据库项

Python Django不显示数据库项,python,html,django,database,Python,Html,Django,Database,我在这个应用程序中创建了一个名为Test的项目和一个名为testing的应用程序。我在测试应用程序中有一个名为ModelTesting的模型。此模型只有一个名为prop的字段,它是最大长度为20的CharField。我可以插入数据库中的项目没有任何问题,但不能显示在主页上。看看我的代码 这是我的模特 from django.db import models # My Model class ModelTesting(models.Model): prop = models.CharFi

我在这个应用程序中创建了一个名为Test的项目和一个名为testing的应用程序。我在测试应用程序中有一个名为ModelTesting的模型。此模型只有一个名为prop的字段,它是最大长度为20的CharField。我可以插入数据库中的项目没有任何问题,但不能显示在主页上。看看我的代码

这是我的模特

from django.db import models

# My Model
class ModelTesting(models.Model):
    prop = models.CharField(max_length = 20)
    def __str__(self):
        return self.prop
这是我的观点

from django.shortcuts import render
from .models import ModelTesting

# Loads Homepage
def index(request):
    all_testing_models = ModelTesting.objects.all()
    params = {'all_models': all_testing_models}
    return render(request, "index.html", params)
这是我想要显示项目的引导模板。此外,我自己编辑了模板

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.1/css/bootstrap.min.css" integrity="sha384-VCmXjywReHh4PwowAiWNagnWcLhlEJLA5buUprzK8rxFgeH0kww/aWY76TfkUoSX" crossorigin="anonymous">

    <title>Hello, world!</title>
  </head>
  <body>
    <h1>The Properties are:-</h1>
        
    {% for test_model in all_testing_mdoels %}
        <h3>{{test_model.prop}}</h3>
    {% endfor %}

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.1/js/bootstrap.min.js" integrity="sha384-XEerZL0cuoUbHE4nZReLT7nx9gQrQreJekYhJD9WNWhH8nEW+0c5qq7aIo2Wl30J" crossorigin="anonymous"></script>
  </body>
</html>

你好,世界!
这些物业包括:-
{所有测试中的测试模型百分比%}
{{test_model.prop}}
{%endfor%}
这个错误也发生在其他一些项目中,所以我专门为此创建了这个项目。请看一看,帮帮我。
谢谢。

您正在制作所有型号的

    params = {'all_models': all_testing_models}
    {% for test_model in all_testing_mdoels %}
        <h3>{{test_model.prop}}</h3>
    {% endfor %}
并尝试在中查找所有测试模型

    params = {'all_models': all_testing_models}
    {% for test_model in all_testing_mdoels %}
        <h3>{{test_model.prop}}</h3>
    {% endfor %}
{%用于所有测试中的测试模型\u mdoels%}
{{test_model.prop}}
{%endfor%}
修复其中一个以匹配另一个

您可能希望启用此选项以帮助更好地捕捉拼写错误