tutorial01 is not working

瀏覽次數:37 次
跳到第一則未讀訊息

aljom...@live.com

未讀,
2018年4月24日 清晨7:34:332018/4/24
收件者:django...@googlegroups.com
hi. i'm new to django dev. so i'm following the tutorial at https://docs.djangoproject.com/en/2.0/intro/tutorial01/

i copied and pasted the code samples so as not to introduce typing mistakes. everything works fine until i reached the "polls" section. i get below errors:

Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/polls/

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

admin/

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

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

when i open http://127.0.0.1:8000/polls/

what could be the reason?

lakshitha kumara

未讀,
2018年4月24日 上午8:03:192018/4/24
收件者:Django users
Look like url is missing. try to add this line to urls.py
from django.urls import path

from . import views

urlpatterns = [
    path('', views.index, name='index'),
]

Anthony Flury

未讀,
2018年4月24日 上午10:35:412018/4/24
收件者:django...@googlegroups.com、aljom...@live.com
The debug suggest that it only tried to match the admin pattern but
nothing else,

that sugggests to me that you missed this bit in the mysite/urls.py

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('polls/', include('polls.urls')),
    path('admin/', admin.site.urls),
]

You notice that this now has two patterns - 'polls' and 'admin', but
your debug message didn't mention trying the 'polls/' pattern, which
suggests that the 'polls/' bit is missing from this file.

To help you debug this sort of thing in future - a quick tutorial might help

* When Django gets a request for a URL, then it checks the project
'urls.py' first - it is expected that the project 'urls.py' will
contain a list of specific urls for the project, and then will
include the 'urls.py' for the various apps within the project.
* If Django is unable to find a match for the url provided - and DEBUG
is TRUE then Django will tell you what paths it tried to match on -
so it will list everything in the project 'urls.py' and then the
patterns from any app 'urls.py' if it finds a match - and so on.
* So for instance with the correct project 'urls.py' and the polls
'url.py' as given in the tutorial, if you tried to get a url of :
'http://localhost:8000/polls/python' - you would get a DEBUG message
something like :

Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/polls/

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

admin/
polls/

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

Django has matched the 'polls' bit of the URL with the 'polls'
pattern in 'mysite/urls.py', it will now try to match the python
bit of the URL within the 'polls/url.py' - but of course wont be
able to, because that 'urls.py' only has a blank pattern.

--
Tony
--
--
Anthony Flury
email : *Anthon...@btinternet.com*
Twitter : *@TonyFlury <https://twitter.com/TonyFlury/>*

回覆所有人
回覆作者
轉寄
0 則新訊息