Path in First App, Part 3

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Path in First App, Part 3

rbar...@xcaretresearch.com
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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d5103e1a-07d0-4533-ad66-b9575e067c2en%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Path in First App, Part 3

Kasper Laudrup
Hi rbar,

On 21/10/2020 20.34, [hidden email] 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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cfe2a624-f52e-e134-c391-8ba6d37925e3%40stacktrace.dk.
Reply | Threaded
Open this post in threaded view
|

Re: Path in First App, Part 3

Kasper Laudrup
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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ab3e57d3-2ccf-5704-07c5-328917f410c3%40stacktrace.dk.