Im进入django的世界,并按照Tango with Django的教程。但是,当我尝试创建基本的view
时,我一直收到404页面未找到的错误。Django:没有找到页面
我使用了django-admin.py
命令并创建了一个名为Project
的文件夹。其中又有一个文件夹名称相同(在这里称为subProject以避免混淆)和manage.py
文件。子项目有文件
1.init.py
2.settings.py
3.urls.py
4.wsgi.py
然后我创建了一个项目app文件夹名为rango
。 Rango有init.py, views,py, tests.py models.py and views.py
文件。
我只编辑了views
和urls
文件。有如下几点:
/rango/views.py
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello World")
/rango.urls.py
from django.conf.urls import patterns, url
from rango import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'))
我再子项目
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'project.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^rango/', include('rango.urls')),
)
编辑urls.py
我加在设置文件的添加。然而,当我做python manage.py runserver
并进入项目URL,它说
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in project.urls, Django tried these URL patterns, in this order:
^admin/
^rango/
The current URL, , 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.
伊夫跟着教程,因为它是。究竟是什么问题?
在哪个文件我贴到这一点? rango或subProject中的url文件? – letsc 2014-11-03 04:22:59
urls.py在子项目 – sajadkk 2014-11-03 04:24:23
哦,它的工作原理!我不得不删除'url(r'^ rango /',include('rango.urls'))'行。 – letsc 2014-11-03 04:28:19