Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
378 views
in Technique[技术] by (71.8m points)

python - The current URL, app/, didn't match any of these

I'm a newbie in Django and just started looking at it before a day by installing Django 1.10 on my local.

I've followed all the instructions of this link https://docs.djangoproject.com/en/dev/intro/tutorial01/. However I'm continuously getting this error:

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 URL, polls/, didn't match any of these.

I've created polls app to getting started.

To make a start, I went with view.py, here is the code:

polls/views.py

from django.shortcuts import render

# Create your views here.

from django.http import HttpResponse


def index(request):
    return HttpResponse("Hello World!")

Here is my code for urls.py:

polls/urls.py

from django.conf.urls import patterns, url

from . import views

urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
)

And here is the urls.py in root:

mysite/urls.py

from django.conf.urls import patterns,include, url
from django.contrib import admin

urlpatterns = patterns('',
    url(r'^polls/', include('polls.urls')),
    url(r'^admin/', include(admin.site.urls)),
)

I've spent good piece of time to find out the solution, found that this question has been asked for many times,so tried with those solutions as well but none of them worked for me.

I can't find out what I'm missing here so please draw my attention to the gap.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think you have edited the wrong file when trying to change the root url config.

Make sure you are editing the root url config in mysite/mysite/urls.py (the directory containing settings.py) not mysite/urls.py (the directory containing manage.py).

As general advice, install the latest release, currently 1.9. Don't use 1.10, which is under development. Make sure that you are following the tutorial for 1.9, because the tutorial changes for different versions. For example, your mysite/urls.py doesn't match the tutorial for 1.9, as the urlpatterns should be:

urlpatterns = [
    url(r'^polls/', include('polls.urls')),
    url(r'^admin/', admin.site.urls),
]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...