Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.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_Django - Fatal编程技术网

Python Django:在第二个模板中添加可单击链接时出现问题

Python Django:在第二个模板中添加可单击链接时出现问题,python,django,Python,Django,我是Django的初学者。我正在构建一个名为PhoneReview的Django应用程序。它将存储与最新手机相关的评论。它还将显示手机品牌以及相关的手机型号 我已经创建了模型和视图。我还设法在第一个模板(brandlist.html)中添加了可点击链接。在第一个模板中,当您单击品牌名称(如三星)时,您将进入手机型号页面,如Galaxy S10。 以下是第一个模板的屏幕截图: 当你点击链接时,你将看到第二个模板(phonemodel.html)。但现在,我面临一个问题。手机型号(“Galaxy

我是Django的初学者。我正在构建一个名为PhoneReview的Django应用程序。它将存储与最新手机相关的评论。它还将显示手机品牌以及相关的手机型号

我已经创建了模型和视图。我还设法在第一个模板(brandlist.html)中添加了可点击链接。在第一个模板中,当您单击品牌名称(如三星)时,您将进入手机型号页面,如Galaxy S10。 以下是第一个模板的屏幕截图:

当你点击链接时,你将看到第二个模板(phonemodel.html)。但现在,我面临一个问题。手机型号(“Galaxy S10”)上没有指向details.html的可点击链接。这是截图。

以下是“PhoneReview”文件夹中models.py的代码:

以下是“PhoneReview”文件夹中URL.py的代码:

以下是“PhoneReview”文件夹中apps.py的代码:

以下是“templates”文件夹中的details.html代码:

{%extends'PhoneReview/base.html%}
{%load static%}
{%block title%}详细信息{%endblock%}
{%block content%}
这是详细信息页面
审查:
{{review.review{u article}}

新闻链接: {{review.slug}

{%endblock%}
以下是“模板”文件夹中phonemodel.html的代码:

{%extends'PhoneReview/base.html%}
{%load static%}
{%block title%}
电话型号页
{%endblock%}
{%block content%}
这是手机型号页
这是电话型号
  • {{phonemodel.model_name}
{%endblock%}
我尝试将
  • {{phonemodel.model\u name}}
  • 替换为
  • 。但我得到一个错误,它看起来像这样:

    NoReverseMatch at /phonemodel/1/
    Reverse for 'details' with arguments '('',)' not found. 1 pattern(s) tried: ['details/(?P<pk>[0-9]+)/$']
    
    NoReverseMatch at/phonemodel/1/
    未找到参数为“(“”,)”的“详细信息”的反转。尝试了1个模式:[“详细信息/(?P[0-9]+)/$”]
    

    如何解决此问题?

    没有名为
    brand
    的上下文变量,您也不需要它。您应该使用
    phonemodel
    id

    <li>
      <a href = "{% url 'details' phonemodel.id %}">
        {{ phonemodel.model_name }}
      </a>
    </li>
    
  • from django.views import generic
    from .models import Brand, PhoneModel, Review
    
    
    class BrandListView(generic.ListView):
        template_name = 'PhoneReview/brandlist.html'
        context_object_name = 'all_brands'
    
        def get_queryset(self):
            return Brand.objects.all()
    
    
    class ModelView(generic.DetailView):
        model = PhoneModel
        template_name = 'PhoneReview/phonemodel.html'
    
    class ReviewView(generic.DetailView):
        model = Review
        template_name = 'PhoneReview/details.html'
    
    from django.apps import AppConfig
    
    
    class PhonereviewConfig(AppConfig):
        name = 'PhoneReview'
    
    {% extends 'PhoneReview/base.html' %}
    {% load static %}
    
    <html>
    
    <link rel="stylesheet" type="text/css" href="{% static "css/style.css" %}">
    
    
    <html lang="en">
    
    {% block title%}Details{% endblock %}
    
    {% block content %}
    
    <h1>This is the Details Page</h1>
    
    <h2>Review:</h2>
    <p>{{ review.review_article }}</p>
    
    <h2>News Link:</h2>
    <p>{{ review.slug }}</p>
    {% endblock %}
    </html>
    
    {% extends 'PhoneReview/base.html' %}
    
    {% load static %}
    
    {% block title%}
    Phone Model Page
    {% endblock %}
    
    {% block content %}
    <!--Page content-->
    <h1>This is Phone Model Page</h1>
    <h2>Here is the phone model</h2>
        <ul>
            <li>{{ phonemodel.model_name }}</li>
        </ul>
    <img src="{% static "images/brandlist.jpg" %}" alt="Super Mario Odyssey" /> <!-- New line -->
    {% endblock %}
    
    NoReverseMatch at /phonemodel/1/
    Reverse for 'details' with arguments '('',)' not found. 1 pattern(s) tried: ['details/(?P<pk>[0-9]+)/$']
    
    <li>
      <a href = "{% url 'details' phonemodel.id %}">
        {{ phonemodel.model_name }}
      </a>
    </li>