python - 如何修复django模板中的html代码

标签 python html django django-templates

这是现在的模板错误。

   NoReverseMatch at /
        Reverse for 'product_detail' not found. 'product_detail' is not a valid view function or pattern name.
        Request Method: GET
        Request URL:    http://127.0.0.1:8000/
        Django Version: 2.2.6
        Exception Type: NoReverseMatch
        Exception Value:    
        Reverse for 'product_detail' not found. 'product_detail' is not a valid view function or pattern name.
        Exception Location: C:\Users\Others\AppData\Local\Programs\Python\Python38\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix, line 673
        Python Executable:  C:\Users\Others\AppData\Local\Programs\Python\Python38\python.exe
        Python Version: 3.8.0
        Python Path:    
        ['C:\\reet\\mysite\\myshopping',
         'C:\\Users\\Others\\AppData\\Local\\Programs\\Python\\Python38\\python38.zip',
         'C:\\Users\\Others\\AppData\\Local\\Programs\\Python\\Python38\\DLLs',
         'C:\\Users\\Others\\AppData\\Local\\Programs\\Python\\Python38\\lib',
         'C:\\Users\\Others\\AppData\\Local\\Programs\\Python\\Python38',
         'C:\\Users\\Others\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages']
        Server time:    Tue, 29 Oct 2019 07:01:37 +0000

Error during template rendering
In template C:\reet\mysite\myshopping\shop\templates\shop\base.html, error at line 0

我认为是指定的路径不正确,我不知道如何处理这个错误。 未找到“product_detail”的反向操作。 “product_detail”不是有效的 View 函数或模式名称。

1   
2   {% load static %}
3   <!DOCTYPE html>
4   <html>
5   <head>
6       <meta charset="utf-8" />
7       <title>{% block title %}My shop{% endblock %}</title>
8       <link href="{% static "css/base.css" %}"  rel="stylesheet">
9   </head>
10  <body>

我不知道如何解决这个错误,请帮忙,提前致谢。

最佳答案

检查第 27 行

<img src=" {% if product.image %}{{ product.image.url }}{% else %}{% state}" /> 

应该是

<img src=" {% if product.image %}{{ product.image.url }}{% else %}{state}{% endif %}" />

关于python - 如何修复django模板中的html代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58602278/

相关文章:

python - VGG16 模型的 OpenCV Python 图像预处理

python - 如果值为空,则从另一个数据框 pandas 更改数据框的值

python - 如何使用BeautifulSoup匹配<div></div>中嵌入<a></a>的文本?

javascript - 创建字典的简单算法

python - 'choices' 必须是一个包含(实际值,人类可读名称)元组的可迭代对象

javascript - AJAX 调用后使用 django 变量填充下拉列表

python - 我可以使用 lxml 只下载部分 Internet 网页吗?

javascript - Oncuechange事件在html的P标签内触发淡入/淡出动画

javascript - 如何在每个窗帘在中间相遇后添加延迟滚动?

python - 可重新部署的 conda 环境