python Django 多个视图url出错
刚开始学Django,按照网上的写了一个很简单的例子,但总是出错在mysite/urls.py中fromdjango.conf.urlsimportpatterns,in...
刚开始学Django,按照网上的写了一个很简单的例子,但总是出错
在mysite/urls.py中
from django.conf.urls import patterns,include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^$','mysite.views.first_page'),
url(r'^west/',include('west.urls')),
)
然后在west/urls.py中
from django.conf.urls import patterns, include, url
urlpatterns=patterns(
url(r'^$','west.views.first_page'),
)
之后在views.py中定义了first_page 函数
之后访问http://127.0.0.1:8000/west 就出错了
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^admin/
^$
west/
The current URL, west, didn't match any of these.
求助大神帮忙 展开
在mysite/urls.py中
from django.conf.urls import patterns,include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^$','mysite.views.first_page'),
url(r'^west/',include('west.urls')),
)
然后在west/urls.py中
from django.conf.urls import patterns, include, url
urlpatterns=patterns(
url(r'^$','west.views.first_page'),
)
之后在views.py中定义了first_page 函数
之后访问http://127.0.0.1:8000/west 就出错了
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^admin/
^$
west/
The current URL, west, didn't match any of these.
求助大神帮忙 展开
2个回答
展开全部
urlpatterns += patterns(
url(r'^$','west.views.first_page'),
url(r'^$','west.views.first_page'),
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
访问http://127.0.0.1:8000/west/ 注意最后的/
更多追问追答
追问
访问http://127.0.0.1:8000/west/ 都不会比较最后一个pattern了
Django tried these URL patterns, in this order: ^admin/ ^$ The current URL, west/, didn't match any of these.只比较了前两个
追答
你改了别的地方吧。。。。
或者你第一次写,可以只写一个mysite/urls.py,先不要学习include
from django.conf.urls import patterns,include, url
from django.contrib import admin
import west
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^$','mysite.views.first_page'),
url(r'^west',west.index),
)
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询