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
1.0k views
in Technique[技术] by (71.8m points)

python - Django can't find URL pattern

I can't figure out why Django is unable to find the requested URL in my application.

Here is the error code I get:

 Using the URLconf defined in littlelogsms.urls, Django tried these URL patterns, in this order:
^admin/
^$
The current URL, success/, didn't match any of these.

Here is my sms.urls.py file:

from django.conf.urls import url

from sms import views

urlpatterns = [
    url(r'^success/$', views.success, name='success'),
    url(r'^$', views.index, name='index')
]

Here is the application urls.py file:

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


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

I can't find the mistake I'm making. Any ideas?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

This problem is the dollar sign in this url pattern.

url(r'^$', include('sms.urls')),

The caret ^ matches the beginning of the string, and the dollar $ matches the end if the string, so ^$ only matches the index URL /.

You should remove the dollar and change it to:

url(r'^', include('sms.urls')),

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

...