[Django]-Django: Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found

29πŸ‘

βœ…

In your index.html you gave poll_id as an argument, but that’s just the name the argument will have within the detail function; it is not defined in your template. The actual value you want to call the function with is probably poll.id.

13πŸ‘

My mistake was a typo on detail.html:

<form action={% url 'polls:vote' polls.id %}" method="post">

should have been

<form action={% url 'polls:vote' poll.id %}" method="post">

It took a while for me to realise the django traceback page was pointing me to the relevant line of code the whole time. :$

πŸ‘€dmvianna

1πŸ‘

This happened to me when I was reading tutorial. I didn’t change poll_id to pk:

url(r'^(?P<poll_id>\d+)/$', views.DetailView.as_view(), name='detail'),

vs

url(r'^(?P<pk>\d+)/$', views.DetailView.as_view(), name='detail'),
πŸ‘€Vanuan

1πŸ‘

I encountered this error when I was using a string as a raw value, rather than surrounding by quotes i.e.

{% url 'my_view' string_val %}

instead of

{% url 'my_view' 'string_val' %}

πŸ‘€Zach Nussbaum

0πŸ‘

I struggled with this for a while. Then I noticed I had put poll.id and not Poll.id with a (capital P)

πŸ‘€sam

0πŸ‘

also, in

polls/urls.py

i had spelling error

url(r’^(?P[0-9]+)/$’, views.detail, name=’detailsβ€˜),

vs the correct code

url(r’^(?P[0-9]+)/$’, views.detail, name=’detail’),

spent some time looking for the error, so look for proper spelling. lol

πŸ‘€VeganxEdge

0πŸ‘

The error got sorted out for me after correcting the filter condition in views.py.

snippet of my views.py

def post_share(request, post_id):
        post = get_object_or_404(Post, id=post_id, status='Published')

snippet from my models.py

class Post(models.Model):
STATUS_CHOICES=(
                ('draft','Draft'),
                ('published','Published'),
                )

1st value is stored in the database and the second value is for displaying to the users.

raw data from my mysql DB

+---------------------------------------+-----------+
| title                                 | status    |
+---------------------------------------+-----------+
| Revolution 2020                       | published |
| harry potter and the sorcerer's stone | published |
| harry potter and the cursed child     | draft     |
| five point someone                    | published |
| half girlfriend                       | draft     |
| one night at the call center          | published |
| Django by example                     | published |
+---------------------------------------+-----------+

When I had used β€œpublishedβ€œ, I was getting the said error. Once I changed the filter to β€œPublished” it all sorted out.

πŸ‘€Sharath K P

0πŸ‘

Be careful with your primary key datatype. In my case, i mistakently used int instead str.

if pk is string,

 path('addesm/pending/<str:pk>', views.addesm, name='add ESM')
πŸ‘€Pravin L

Leave a comment