0👍
✅
You should learn to read the traceback. Here is the error:
car = get_object_or_404(Car, pk=pk)
and the error happens in:
File "C:\Users\name\djangofolder\myproject\website\views.py" in car_detail
You passed the pk
in url as a string new
, but your car_detail
method is expecting an integer which represents the pk of Car
. If you read the error message again it should make more sense.
1👍
The url for /car/new/
is resolving to your car_detail
view, instead of the car_new
view.
You haven’t shown your url patterns, so I can’t give a precise answer, but you can probably fix the problem by doing either of the following:
- Move the
car_new
url above thecar_detail
view. - Change the regex for the primary key so that it matches only digits (at the moment, you are probably using something like
\w+
, which matches strings likenew
.
Putting that together, you something like:
url(r'^car/new/$', views.car_new, name='car_new'),
url(r'^car/(?P<pk>\d+)/$', views.car_detail, name='car_detail'),
- How to make a dynamic model's field value?
- Stopping the Inheritance of nav-bar for a particular template
Source:stackexchange.com