首页 新闻 会员 周边

python Django URL分发出现的奇怪的问题

0
悬赏园豆:5 [已关闭问题] 关闭于 2018-08-12 12:42

Page not found (404)

Request Method: GET
Request URL: http://127.0.0.1:8000/aaa/hello/hello

Using the URLconf defined in redstar.urls, Django tried these URL patterns, in this order:

  1. admin/
  2. aaa/ hello/(\w+)

The current path, aaa/hello/hello, didn't match any of these.

 

 

上面是报的错,浏览器输入的url是http://127.0.0.1:8000/aaa/hello/hello

看到

  1. aaa/ hello/(\w+)这条路由匹配,中间明显多了一个空格

这是什么情况?

全局url下是这样的

urlpatterns = [
  path('admin/', admin.site.urls),
  path('aaa/',include('blog.urls')),
]
应用中的url是这样的:
urlpatterns = [
  path(r'hello/(\w+)', views.hello),
]

 

 

请高手指点

 

baoj2010的主页 baoj2010 | 初学一级 | 园豆:102
提问于:2018-08-12 12:06
< >
分享
所有回答(2)
0
被默认的配置误导了,应该这样配置,url才是支持正则表达式的
urlpatterns = [
  path('admin/', admin.site.urls),
  url('^aaa/',include('blog.urls')),
]
baoj2010 | 园豆:102 (初学一级) | 2018-08-12 12:42
0

2.0以后re_path支持re

自说自话唉 | 园豆:193 (初学一级) | 2018-08-17 14:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册