Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.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)DetailView模板未显示信息_Python_Django_Django Models_Django Templates_Django Views - Fatal编程技术网

Python (Django)DetailView模板未显示信息

Python (Django)DetailView模板未显示信息,python,django,django-models,django-templates,django-views,Python,Django,Django Models,Django Templates,Django Views,在我的维护应用程序中,我有六种型号。我将只包括与这个问题相关的两个模型。有一个正确显示的设备列表(Listview)。但是,我在为每个设备创建详细视图时遇到问题。当我转到时,它应该显示与设备1相关的所有设备实例(详细信息),但它会显示回设备列表页面,即 型号.py from django.db import models class Equipment(models.Model): """ Model representing an Equipment (but not a s

在我的维护应用程序中,我有六种型号。我将只包括与这个问题相关的两个模型。有一个正确显示的设备列表(Listview)。但是,我在为每个设备创建详细视图时遇到问题。当我转到时,它应该显示与设备1相关的所有设备实例(详细信息),但它会显示回设备列表页面,即

型号.py

from django.db import models

class Equipment(models.Model):
    """
    Model representing an Equipment (but not a specific type of equipment).
    """
    title = models.CharField(max_length=200)
    physicist = models.ForeignKey('Physicist', null=True, help_text= 'add information about the physicist')
    technician = models.ForeignKey('Technician', null=True, help_text= 'add information about the technician')
    # Physicist as a string rather than object because it hasn't been declared yet in the file.
    features = models.TextField(max_length=1000, help_text='Enter a brief description of the features of the equipment')
    machine_number = models.CharField('Number', max_length=30, null=True, help_text='Enter the Equipment number')
    specialty = models.ForeignKey(Specialty, null=True, help_text='Select a specialty for an equipment')
    # Specialty class has already been defined so we can specify the object above.
    assigned_technician = models.CharField(max_length=50, null= True, blank=True)
    #This is for the Technician who the repair of the Equipment is assigned to. 

    def __str__(self):

        return self.title

    def get_absolute_url(self):

        return reverse('equipment-detail', args=[str(self.id)])

    def display_specialty(self):

        return ', '.join([ specialty.name for specialty in self.specialty.all()[:3] ])
    display_specialty.short_description = 'Specialty'

    class Meta:
        ordering = ['-id']

class EquipmentInstance(models.Model):

    id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text="Unique ID for this particular equipment across the entire database")
    equipment = models.ForeignKey('Equipment', on_delete=models.SET_NULL, null=True) 
    imprint = models.CharField(max_length=200)
    due_date = models.DateField(null=True, blank=True)
    delegate = models.ForeignKey('Physicist', on_delete=models.SET_NULL, null=True, blank=True)

    def is_overdue(self):
        if self.due_date and date.today() > self.due_date:
            return True
        return False

    MAINTENANCE_STATUS = (
        ('p', 'Past Maintenance'),
        ('o', 'On Maintenance'),
        ('a', 'Available'),
        ('r', 'Reserved'),
    )

    status = models.CharField(max_length=1, choices = MAINTENANCE_STATUS, blank=True, default='m', help_text='Equipment availability')

    class Meta:
        ordering = ["due_date"]
        permissions = (("can_mark_maintained", "Set equipment as maintained"),) 

    def __str__(self):
        """
        String for representing the Model object
        """
        return '{0} ({1})'.format(self.id,self.equipment.title)
from django.conf.urls import url
from qatrack.maintenance import views 
from qatrack.maintenance import models

urlpatterns = [

    url(r'^$', views.MDashboard, name='m_dash'),
    url(r'^equipments/$', views.EquipmentListView.as_view(), name='equipments'),
    url(r'^equipment(?P<pk>\d+)/$', views.EquipmentDetailView.as_view(), name='equipment-detail'),

]
from django.shortcuts import render
from django.views.generic import DetailView, ListView
from qatrack.maintenance import models

class EquipmentListView(ListView):
    template_name = 'maintenance/equipment_list.html'

    def get_queryset(self):
        return models.Equipment.objects.all()

    paginate_by = 10

class EquipmentDetailView(DetailView):
    model = models.Equipment
    template_name = 'maintenance/equipment_detail.html'
    context_object_name = 'equipment'
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.views.generic.base import TemplateView, RedirectView
from django.contrib.staticfiles.templatetags.staticfiles import static as static_url
from django.contrib import admin
from qatrack.maintenance.views import get_data
admin.autodiscover()

urlpatterns = [

    url(r'^$', TemplateView.as_view(template_name="homepage.html"), name="home"),

    url(r'^accounts/', include('qatrack.accounts.urls')),
    url(r'^qa/', include('qatrack.qa.urls')),
    url(r'^servicelog/', include('qatrack.service_log.urls')),
    url(r'^parts/', include('qatrack.parts.urls')),
    url(r'^units/', include('qatrack.units.urls')),
    url(r'^issues/', include('qatrack.issue_tracker.urls')),
    url(r'^maintenance/', include('qatrack.maintenance.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
维护/url.py

from django.db import models

class Equipment(models.Model):
    """
    Model representing an Equipment (but not a specific type of equipment).
    """
    title = models.CharField(max_length=200)
    physicist = models.ForeignKey('Physicist', null=True, help_text= 'add information about the physicist')
    technician = models.ForeignKey('Technician', null=True, help_text= 'add information about the technician')
    # Physicist as a string rather than object because it hasn't been declared yet in the file.
    features = models.TextField(max_length=1000, help_text='Enter a brief description of the features of the equipment')
    machine_number = models.CharField('Number', max_length=30, null=True, help_text='Enter the Equipment number')
    specialty = models.ForeignKey(Specialty, null=True, help_text='Select a specialty for an equipment')
    # Specialty class has already been defined so we can specify the object above.
    assigned_technician = models.CharField(max_length=50, null= True, blank=True)
    #This is for the Technician who the repair of the Equipment is assigned to. 

    def __str__(self):

        return self.title

    def get_absolute_url(self):

        return reverse('equipment-detail', args=[str(self.id)])

    def display_specialty(self):

        return ', '.join([ specialty.name for specialty in self.specialty.all()[:3] ])
    display_specialty.short_description = 'Specialty'

    class Meta:
        ordering = ['-id']

class EquipmentInstance(models.Model):

    id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text="Unique ID for this particular equipment across the entire database")
    equipment = models.ForeignKey('Equipment', on_delete=models.SET_NULL, null=True) 
    imprint = models.CharField(max_length=200)
    due_date = models.DateField(null=True, blank=True)
    delegate = models.ForeignKey('Physicist', on_delete=models.SET_NULL, null=True, blank=True)

    def is_overdue(self):
        if self.due_date and date.today() > self.due_date:
            return True
        return False

    MAINTENANCE_STATUS = (
        ('p', 'Past Maintenance'),
        ('o', 'On Maintenance'),
        ('a', 'Available'),
        ('r', 'Reserved'),
    )

    status = models.CharField(max_length=1, choices = MAINTENANCE_STATUS, blank=True, default='m', help_text='Equipment availability')

    class Meta:
        ordering = ["due_date"]
        permissions = (("can_mark_maintained", "Set equipment as maintained"),) 

    def __str__(self):
        """
        String for representing the Model object
        """
        return '{0} ({1})'.format(self.id,self.equipment.title)
from django.conf.urls import url
from qatrack.maintenance import views 
from qatrack.maintenance import models

urlpatterns = [

    url(r'^$', views.MDashboard, name='m_dash'),
    url(r'^equipments/$', views.EquipmentListView.as_view(), name='equipments'),
    url(r'^equipment(?P<pk>\d+)/$', views.EquipmentDetailView.as_view(), name='equipment-detail'),

]
from django.shortcuts import render
from django.views.generic import DetailView, ListView
from qatrack.maintenance import models

class EquipmentListView(ListView):
    template_name = 'maintenance/equipment_list.html'

    def get_queryset(self):
        return models.Equipment.objects.all()

    paginate_by = 10

class EquipmentDetailView(DetailView):
    model = models.Equipment
    template_name = 'maintenance/equipment_detail.html'
    context_object_name = 'equipment'
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.views.generic.base import TemplateView, RedirectView
from django.contrib.staticfiles.templatetags.staticfiles import static as static_url
from django.contrib import admin
from qatrack.maintenance.views import get_data
admin.autodiscover()

urlpatterns = [

    url(r'^$', TemplateView.as_view(template_name="homepage.html"), name="home"),

    url(r'^accounts/', include('qatrack.accounts.urls')),
    url(r'^qa/', include('qatrack.qa.urls')),
    url(r'^servicelog/', include('qatrack.service_log.urls')),
    url(r'^parts/', include('qatrack.parts.urls')),
    url(r'^units/', include('qatrack.units.urls')),
    url(r'^issues/', include('qatrack.issue_tracker.urls')),
    url(r'^maintenance/', include('qatrack.maintenance.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
设备清单.html

{% extends "maintenance/m_base.html" %}

{% block body %}

 <div class="row">
     <div class="col-md-12">
        <div class="box">

          <h1>Equipment List</h1>

          {% if equipment_list %}
          <ul>
              {% for equipment in equipment_list %}
            <li>
              <a href="{{ equipment.get_absolute_url }}">{{ equipment.title }}</a> ({{equipment.physicist}}, {{equipment.technician}})
            </li>
              {% endfor %}
          </ul>
          {% else %}
              <p>There are no equipments in the database.</p>

          {% endif %}
        </div>
      </div>
 </div>

{% endblock body %}
{% extends "maintenance/m_base.html" %}

{% block title %}Equipment Details{% endblock %}

{% block body %}
  <h1>Title: {{ equipment.title }}</h1>

  <h2>Machine Detail</h2>

  <p><strong>Physicist:</strong> <a href="">{{ equipment.physicist }}</a></p> <!-- physicist detail link not yet defined -->
  <p><strong>Technician:</strong> <a href="">{{ equipment.technician }}</a></p> <!-- technician detail link not yet defined -->
  <p><strong>Features:</strong> {{ equipment.features }}</p>
  <p><strong>Machine_number:</strong> {{ equipment.machine_number }}</p>  
  <p><strong>Specialty:</strong> {% for specialty in equipment.specialty.all %} {{ specialty }}{% if not forloop.last %}, {% endif %}{% endfor %}</p>  

    {% for type in equipment.equipmentinstance_set.all %}
    <hr>
    <p class="{% if type.status == 'a' %}text-success{% elif type.status == 'm' %}text-danger{% else %}text-warning{% endif %}">{{ type.get_status_display }}</p>
    {% if type.status != 'a' %}<p><strong>Due to be maintained:</strong> {{type.due_date}}</p>{% endif %}
    <p><strong>Imprint:</strong> {{type.imprint}}</p>
    <p class="text-muted"><strong>Id:</strong> {{type.id}}</p>
    {% endfor %}

  </div>

{% endblock body %}
我在这里遇到了很多类似的问题并应用了它们,但我仍然无法让DetailView正常工作。我真的很感激任何帮助。谢谢在进行更改之后,我遇到了这个回溯错误

内部服务器错误:/maintenance/equipment1/回溯(最新) 调用最后一个文件 “/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/url/base.py”, 第77行,反向 额外,resolver=resolver.namespace_dict[ns]keyrerror:“设备”

在处理上述异常期间,发生了另一个异常:

回溯(最近一次调用上次):文件 “/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/core/handlers/exception.py”, 第41行,在内部 response=get_response(请求)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/core/handlers/base.py”, 第217行,在“获取”响应中 response=self.process\u exception\u by_中间件(e,请求)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/core/handlers/base.py”, 第215行,在_get_响应中 response=response.render()文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/response.py”, 第107行,在渲染中 self.content=self.rendered_content File“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/response.py”, 第84行,在渲染内容中 content=template.render(context,self._request)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/backends/django.py”, 第66行,在渲染中 返回self.template.render(上下文)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/base.py”, 第207行,在渲染中 返回self._render(context)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/test/utils.py”, 第107行,仪表化测试渲染中 返回self.nodelist.render(上下文)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/base.py”, 第990行,在渲染中 bit=node.render_注释(上下文)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/base.py”, 第957行,在“渲染”注释中 返回self.render(context)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/loader_tags.py”, 第177行,在渲染中 返回编译的\u parent.\u render(context)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/test/utils.py”, 第107行,仪表化测试渲染中 返回self.nodelist.render(上下文)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/base.py”, 第990行,在渲染中 bit=node.render_注释(上下文)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/base.py”, 第957行,在“渲染”注释中 返回self.render(context)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/loader_tags.py”, 第177行,在渲染中 返回编译的\u parent.\u render(context)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/test/utils.py”, 第107行,仪表化测试渲染中 返回self.nodelist.render(上下文)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/base.py”, 第990行,在渲染中 bit=node.render_注释(上下文)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/base.py”, 第957行,在“渲染”注释中 返回self.render(context)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/loader_tags.py”, 第72行,在渲染中 结果=block.nodelist.render(上下文)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/base.py”, 第990行,在渲染中 bit=node.render_注释(上下文)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/base.py”, 第957行,在“渲染”注释中 返回self.render(context)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/defaulttags.py”, 第322行,在渲染中 返回nodelist.render(上下文)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/base.py”, 第990行,在渲染中 bit=node.render_注释(上下文)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/base.py”, 第957行,在“渲染”注释中 返回self.render(context)文件“/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/template/defaulttags.py”, 第458行,在渲染中 url=reverse(查看\名称,args=args,kwargs=kwargs,当前\应用程序=当前\应用程序)文件 “/home/blesjoe1/venvs/qatrack3/lib/python3.5/site packages/django/url/base.py”, 第87行,反向 raise NoReverseMatch(“%s”不是注册的命名空间“%key”)django.url.exceptions.NoReverseMatch:“设备”不是 注册名称空间[14/May/2018 16:05:33]“获取 /维护/设备1/HTTP/1.1“500 215728


您的
url
不正确

而不是

 url(r'^equipment(?:/(?P<pk>\d+))?/$', views.EquipmentDetailView.as_view(), name="equipment_detail"),
url(r'^equipment(?:/(?P\d+)))/$,views.EquipmentDetailView.as_view(),name=“equipment_detail”),
应该是:

url(r'^equipment/(?P<pk>\d+)/$', views.EquipmentDetailView.as_view(), name="equipment_detail"),
url(r'^equipment/(?P\d+)/$,views.EquipmentDetailView.as\u view(),name=“equipment\u detail”),