Django找不到网址格式 [英] Django can't find URL pattern
本文介绍了Django找不到网址格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我得到的错误代码:
使用在littlelogsms.urls中定义的URLconf,Django按照以下顺序尝试了这些URL模式:
^ admin /
^ $
当前URL,success /,与之不匹配。
这是我的 sms.urls.py 文件:
从django.conf.urls导入url
从sms导入视图
urlpatterns = [
url(r'^ success / $',views.success,name ='success'),
url(r'^ $',views.index,name ='index')
]
这是应用程序 urls.py 文件:来自django.conf.urls的include
import django.contrib中的
import admin
urlpatterns = [
url(r'^ admin /',include(admin.site.urls)),
url(r'^ $',include('sms.urls') ),
]
我找不到我所犯的错误。任何想法?
解决方案
此问题是此url模式中的美元符号。
url(r'^ $',include('sms.urls')),
插入符号 ^
匹配字符串的开头,而美元 $
匹配结尾如果字符串,所以 ^ $
只匹配索引URL /
。
您应该删除美元并将其更改为:
url (r'^',include('sms.urls')),
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?
解决方案
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')),
这篇关于Django找不到网址格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文