Path in First App, Part 3

120 views
Skip to first unread message

rbar...@xcaretresearch.com

unread,
Oct 21, 2020, 2:34:46 PM10/21/20
to Django users
I can get to .localhost:8000/polls. but not /polls/detail ror /votes or /results.  Here is my code:
```
from django.urls import path
from django.contrib import admin

from . import views

urlpatterns = [
#es: /polls/
path('', views.index, name='index'),
# ex: /polls/5
path('<int:question_id>/', views.detail, name='detail'),
# ex: /polls/5/results/
path('<int:question_id>/results', views.results, name='results'),
#ex: /polls/5/votes
path('<int:question_id>/votes/', views.votes, name='votes'),

]
```
The error message shows that there is a match.  What am I doing wrong?
```

Using the URLconf defined in maturedj.urls, Django tried these URL patterns, in this order:

  1. polls/ [name='index']
  2. polls/ <int:question_id>/ [name='detail']
  3. polls/ <int:question_id>/results [name='results']
  4. polls/ <int:question_id>/votes/ [name='votes']
  5. admin/

The current path, polls/3/detail, didn't match any of these.

```

obviously, there is a match

Kasper Laudrup

unread,
Oct 21, 2020, 3:04:27 PM10/21/20
to django...@googlegroups.com
Hi rbar,

On 21/10/2020 20.34, rbar...@xcaretresearch.com wrote:
> The error message shows that there is a match.  What am I doing wrong?

No, the error message shows you that there *isn't* a match:

>
> The current path, polls/3/detail, didn't match any of these.
>

Maybe change:

path('<int:question_id>/', views.detail, name='detail'),

to:

path('<int:question_id>/detail', views.detail, name='detail'),

The error message is quite clear and helpful, you probably just didn't
read it correctly. No worries, that can happen to all of us often enough :-)

Hope that helps.

Kind regards,

Kasper Laudrup

Kasper Laudrup

unread,
Oct 21, 2020, 3:57:55 PM10/21/20
to django...@googlegroups.com
Hi Ralph,

First of all, when using a mailing list, forum or similar like this,
please reply to the list instead of the person answering you directly
(in this case me).

The point of forums and mailing lists like is to share help and information.

Anyway:

> Thanks for the response, however, you misinterpreted what I wrote. My
> code is exactly what is shown in the tutorial.  What I meant by the
> error message displaying that there are matches, is that the detail in
> the message shows the exact path to each of the pages (views).  It shows
> the path exactly as it should be and exactly as it is in the code.  What
> is incorrect about how I read it?

I think I understand what you mean. The error message is informing you
how it tried to match the URL you gave it (ie. what your browser sent to
your Django application). And that does indeed seem to match exactly
what is in the tutorial.

> The paths in my code show exactly the
> paths that the error message says it tried.  Again, I think it is the
> precise code showing in Part 3 of the tutorial.  Perhaps you could take
> a look at that and tell me what specifically is wrong?  that would be great.
>

Nothing wrong with your code it seems, you probably just typed the wrong
URL in your browser. Try to remove the 'detail' part, e.g. something
like this:

http://localhost:8000/polls/3

Kind regards,

Kasper Laudrup

Kasper Laudrup

unread,
Oct 21, 2020, 4:03:18 PM10/21/20
to django...@googlegroups.com
By the way, look at the tutorial and you will see that it is not written
the way you suggest for "path"<int:question_id>/",views.detail,
name='detail')

The polls index page for a particular questioon_id refers to 'detail.'

Another interesting thing is that I just tried all three pages. "votes"
worked the other two did not.  when I tried "votes" the second time, it
didn't work.  The message error was not helpful and I read it quite
carefully.  There is something else going on.
--
Cheers,

/Ralph 3.0/

Kasper Laudrup

unread,
Oct 21, 2020, 4:04:26 PM10/21/20
to django...@googlegroups.com
Actually, I tried "votes" one more time and it did work.

rbar...@xcaretresearch.com

unread,
Oct 23, 2020, 5:18:11 PM10/23/20
to Django users
Now I am in the situation where "votes" works but "detail" and "results" does not work.  So weird.. Well, I just checked "votes" to make sure it works and it doesn't.  "index works and takes me to "detail" which, according to the tutorial, is what it supposed to do.  Does anybody know this code?

rbar...@xcaretresearch.com

unread,
Oct 23, 2020, 5:24:55 PM10/23/20
to Django users

Oh my.  I figured it out partially.  I was not entering the url correctly in address bar.  So, now, "results" and "votes" works but "detail" doesn't.  However, "detail" returns when I just enter the basic index url for a given question_id, it just doesn't work for "detail".  Is it supposed to be that way.

rbar...@xcaretresearch.com

unread,
Oct 23, 2020, 5:32:19 PM10/23/20
to Django users
My guess is that the index url is supposed to return "detail," but, then, why even have that "detail" function in the code?  I think I have been spending too long on this and need to move.  I would appreciate it if anybody would explain this to me.  Adding "detail" to the functions just to provide a return message for the. index page seems odd. But if I take it out, I get an error message in the code and it won't run.  Hmmm.  I wish I understood this.

rbar...@xcaretresearch.com

unread,
Oct 23, 2020, 5:38:15 PM10/23/20
to Django users
Someone suggest that I add "detail" to the urls.py code at path('<int:question.id>/", view detail, name="detail"
But that ruins everything.

rbar...@xcaretresearch.com

unread,
Oct 23, 2020, 5:44:08 PM10/23/20
to Django users
oh no, trying that ruined everything, now none of them work.  I tried again, and now "votes' works but "results" doesn't..  Again, is there anyone who knows this code?
Reply all
Reply to author
Forward
0 new messages