当前的网址app /与这些网址不匹配 [英] The current URL, app/, didn't match any of these

查看:237
本文介绍了当前的网址app /与这些网址不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Django的新手,只是在一天之前开始使用Django 1.10安装在本地。



我遵循了所有的指示此链接 https://docs.djangoproject.com/en/dev/intro/tutorial01/ 。但是我不断得到这个错误:

 找不到页面(404)请求方法:GET请求URL:http:// 127.0.0.1:8000/polls/ 

使用在mysite.urls中定义的URLconf,Django按照以下顺序尝试了这些URL模式:

^ admin /

当前URL,polls /,与之不匹配。

我已经创建了民意调查应用程序开始使用。



要开始,我用view.py去了,这里是代码:


polls / views.py




 从django.shortcuts import render 

#在这里创建您的意见。

from django.http import HttpResponse


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

这是我的代码为urls.py:


polls / urls.py




  from django.conf.urls import patterns ,url 

从。导入视图

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

这里是root中的urls.py:


mysite / urls.py




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

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

我花了很多时间找出解决方案,发现这个问题已经被问了很多次,所以尝试了这些解决方案,但没有一个为我工作。



我找不到我在这里遗漏的东西,请吸引我注意这个差距。

解决方案

我想你在尝试更改根URL配置时编辑了错误的文件。



确保您正在编辑 mysite / mysite / urls.py (包含 settings.py )不是 mysite / urls.py (包含 manage.py 的目录)。



作为一般建议,安装最新版本,目前为1.9。不要使用正在开发的1.10。确保您遵循 1.9的教程,因为本教程的更改为不同版本。例如,您的 mysite / urls.py 与1.9的教程不符,因为 urlpatterns 应该是:

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


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.

解决方案

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),
]

这篇关于当前的网址app /与这些网址不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆