Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.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 基于类的视图及其模型之间的源代码关系_Python_Django_Django Class Based Views - Fatal编程技术网

Python 基于类的视图及其模型之间的源代码关系

Python 基于类的视图及其模型之间的源代码关系,python,django,django-class-based-views,Python,Django,Django Class Based Views,根据, models.py from django.db import models class Publisher(models.Model): name = models.CharField(max_length=30) address = models.CharField(max_length=50) city = models.CharField(max_length=60) state_province = mod

根据,

models.py

from django.db import models
    class Publisher(models.Model):
        name = models.CharField(max_length=30)
        address = models.CharField(max_length=50)
        city = models.CharField(max_length=60)
        state_province = models.CharField(max_length=30)
        ...
from django.views.generic import ListView
from books.models import Publisher

class PublisherList(ListView):
    model = Publisher
from django.urls import path
from books.views import PublisherList

urlpatterns = [
    path('publishers/', PublisherList.as_view()),
]
views.py

from django.db import models
    class Publisher(models.Model):
        name = models.CharField(max_length=30)
        address = models.CharField(max_length=50)
        city = models.CharField(max_length=60)
        state_province = models.CharField(max_length=30)
        ...
from django.views.generic import ListView
from books.models import Publisher

class PublisherList(ListView):
    model = Publisher
from django.urls import path
from books.views import PublisherList

urlpatterns = [
    path('publishers/', PublisherList.as_view()),
]
url.py

from django.db import models
    class Publisher(models.Model):
        name = models.CharField(max_length=30)
        address = models.CharField(max_length=50)
        city = models.CharField(max_length=60)
        state_province = models.CharField(max_length=30)
        ...
from django.views.generic import ListView
from books.models import Publisher

class PublisherList(ListView):
    model = Publisher
from django.urls import path
from books.views import PublisherList

urlpatterns = [
    path('publishers/', PublisherList.as_view()),
]
在模板中,一个名为
object\u list
的变量,包含所有发布者对象

{% extends "base.html" %}

{% block content %}
    <h2>Publishers</h2>
    <ul>
        {% for publisher in object_list %}
            <li>{{ publisher.name }}</li>
        {% endfor %}
    </ul>
{% endblock %}
{%extends“base.html”%}
{%block content%}
出版者
    {对象_列表%]中发布者的%
  • {{publisher.name}
  • {%endfor%}
{%endblock%}

我一直在深入研究django的源代码,以找出django在模板上下文(
object\u list
)中显式放置
Publisher
模型的所有对象的确切位置。但是到目前为止运气不好,有人能分享一些见解吗?

ListView
BaseListView
的子类。
对象列表
属性已初始化: