The current URL, app/, didn't match any of the

2019-01-27 22:44发布

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.

8条回答
混吃等死
2楼-- · 2019-01-27 23:19

change the mysite/url

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

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

Then run your server and visit 127.0.0.1/8000. This should take you to the index of ur website.

or you leave your code as it is and run 127.0.0.1/8000/polls on your browser

查看更多
神经病院院长
3楼-- · 2019-01-27 23:23

It's working. Go to your url bar and type your app name:

http://127.0.0.1:8000/home

My app name is home. It will work.

If you want to set your app as your default page then import views from your app.

Like

from home import views

then write

url(r'^$', views.index),

inside.

It will set the views as your default page

http://127.0.0.1:8000/

When you type this it will redirect to your views.

查看更多
登录 后发表回答