Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.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 3错误-NoReverseMatch at/;与#x27相反;汽车详图';没有找到任何参数。尝试了1种模式:[';cars/(?P<;id>;[0-9]+;)$';]_Python_Django_Django Views - Fatal编程技术网

Python Django 3错误-NoReverseMatch at/;与#x27相反;汽车详图';没有找到任何参数。尝试了1种模式:[';cars/(?P<;id>;[0-9]+;)$';]

Python Django 3错误-NoReverseMatch at/;与#x27相反;汽车详图';没有找到任何参数。尝试了1种模式:[';cars/(?P<;id>;[0-9]+;)$';],python,django,django-views,Python,Django,Django Views,我目前正在从电子书上学习Django的教程。尽管做了书中写的事,我还是不断地犯这个错误。也许,我有疏忽,一定是错过了什么。一个善良的人能帮我检查一下代码,告诉我我一定做错了什么吗? 我在下面附上了我的代码片段。任何帮助都将不胜感激。谢谢 NoReverseMatch at/ Reverse for 'car_detail' with no arguments not found. 1 pattern(s) tried: ['cars/(?P<id>[0-9]+)$'] Request

我目前正在从电子书上学习Django的教程。尽管做了书中写的事,我还是不断地犯这个错误。也许,我有疏忽,一定是错过了什么。一个善良的人能帮我检查一下代码,告诉我我一定做错了什么吗? 我在下面附上了我的代码片段。任何帮助都将不胜感激。谢谢

NoReverseMatch at/

Reverse for 'car_detail' with no arguments not found. 1 pattern(s) tried: ['cars/(?P<id>[0-9]+)$']
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 3.0.7
Exception Type: NoReverseMatch
Exception Value:    
Reverse for 'car_detail' with no arguments not found. 1 pattern(s) tried: ['cars/(?P<id>[0-9]+)$']
Exception Location: C:\Python37\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix, line 677
Python Executable:  C:\Python37\python.exe
Python Version: 3.7.7
Python Path:    
['D:\\Django_Tests\\CarZone_Project',
 'C:\\Python37\\python37.zip',
 'C:\\Python37\\DLLs',
 'C:\\Python37\\lib',
 'C:\\Python37',
 'C:\\Python37\\lib\\site-packages']
Server time:    Wed, 16 Dec 2020 14:46:01 +0000
Error during template rendering
In template D:\Django_Tests\CarZone_Project\templates\base.html, error at line 0

Reverse for 'car_detail' with no arguments not found. 1 pattern(s) tried: ['cars/(?P<id>[0-9]+)$']
1   {% load static %}
2   
3   <!DOCTYPE html>
4   <html>
5   
6   <head>
7       <title></title>
8       <meta name="viewport" content="width=device-width, initial-scale=1.0">
9       <meta charset="utf-8">
10  
url.PY:


from . import views

urlpatterns = [
    path('', views.cars, name='cars'),
    path('<int:id>', views.car_detail, name='car_detail'),
] 
                              <div class="overlap-box">
                                <div class="overlap-btns-area">
                                    <div class="car-magnify-gallery">
                                        <a href="{{each_car.car_image.url}}" class="overlap-btn">
                                            <i class="fa fa-expand"></i>
                                            <img class="hidden" src="{{each_car.car_image.url}}">
                                        </a>

                                        {% if each_car.car_image_1 %}
                                        <a href="{{each_car.car_image_1.url}}" class="hidden">
                                            <img class="hidden" src="{{each_car.car_image_1.url}}">
                                        </a>
                                        {% endif%}
                                        {% if each_car.car_image_2 %}
                                        <a href="{{each_car.car_image_2.url}}" class="hidden">
                                            <img class="hidden" src="{{each_car.car_image_2.url}}">
                                        </a>
                                        {% endif%}
                                        {% if each_car.car_image_3 %}
                                        <a href="{{each_car.car_image_3.url}}" class="hidden">
                                            <img class="hidden" src="{{each_car.car_image_3.url}}">
                                        </a>
                                        {% endif%}
                                        {% if each_car.car_image_4 %}
                                        <a href="{{each_car.car_image_4.url}}" class="hidden">
                                            <img class="hidden" src="{{each_car.car_image_4.url}}">
                                        </a>
                                        {% endif%}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="detail">
                        <h1 class="title">
                            <a href="{% url 'car_detail' car.id %}">{{each_car.car_title}}</a>
                        </h1>
                        <div class="location">
                            <a href="{% url 'car_detail' car.id %}">
                                <i class="flaticon-pin"></i>{{each_car.state}}, {{each_car.city}}
                            </a>
                        </div>
                    </div>
试试这个

<div class="detail">
  <h1 class="title">
    <a href="{% url 'car_detail' each_car.id %}">{{each_car.car_title}}</a>
  </h1>
  <div class="location">
    <a href="{% url 'car_detail' each_car.id %}">
      <i class="flaticon-pin"></i>{{each_car.state}}, {{each_car.city}}
    </a>
  </div>
</div>

试试这个

<div class="detail">
  <h1 class="title">
    <a href="{% url 'car_detail' each_car.id %}">{{each_car.car_title}}</a>
  </h1>
  <div class="location">
    <a href="{% url 'car_detail' each_car.id %}">
      <i class="flaticon-pin"></i>{{each_car.state}}, {{each_car.city}}
    </a>
  </div>
</div>


Mac您的
path(“”,views.car\u detail,name='car\u detail'),
需要一个参数
id
“{%url'car\u detail'car.id%}”,需要是
“{%url'car\u detail'each\u car.id%}”
谢谢@ha neul。明显的疏忽。这解决了你的
路径(“”,views.car\u detail,name='car\u detail'),
需要一个参数
id
“{%url'car\u detail'car.id%}”,需要是
“{%url'car detail'each\u car.id%}”
谢谢@ha neul。明显的疏忽。这解决了汉克斯的问题。这就解决了,谢谢。这就解决了问题。
<div class="detail">
  <h1 class="title">
    <a href="{% url 'car_detail' each_car.id %}">{{each_car.car_title}}</a>
  </h1>
  <div class="location">
    <a href="{% url 'car_detail' each_car.id %}">
      <i class="flaticon-pin"></i>{{each_car.state}}, {{each_car.city}}
    </a>
  </div>
</div>