(django) url 正则表达式不匹配
(django) url regex doesn't match
url我试试:http://127.0.0.1:8000/manifest/archive/?page=1
。
正则表达式模式:
- (我试过的原版):
r'^archive/(?P<reverse>[n]{0,1})/?\?page=[0-9]+/?'
- (更简单的我也在python控制台试过。)
r'^archive/\?page=[0-9]+'
- (最简单的,只是尝试。)
r'^archive/\?page=1'
(但是我以正确的方式转义了问号,不是吗?)
我在 python 控制台中尝试了所有这些正则表达式,它们运行良好,所以我认为问题不在于错误的正则表达式。
所以:为什么这行不通?
可选信息:
项目url-conf:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', RedirectView.as_view(url=reverse_lazy('manifest:index'))),
url(r'^manifest/', include('manifest.urls', namespace='manifest')),
]
注意:url 127.0.0.1:8000/manifest/index
应该是匹配的,所以不能把所有东西都弄错了。
url回溯:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/manifest/archive/?page=1
Using the URLconf defined in asqiir005.urls, Django tried these URL patterns, in this order:
^admin/
^$
^manifest/ ^$ [name='index']
^manifest/ ^(?P<number>[0-9]+)$ [name='article']
^manifest/ ^archive/\?page=1
^manifest/ ^archive/(?P<reverse>[n]{0,1})/?\?page=[0-9]+/? [name='paged_archive']
^manifest/ ^archive/all/(?P<reverse>[n]{0,1})/?$ [name='whole_archive']
^media\/(?P<path>.*)$
The current URL, manifest/archive/, didn't match any of these.
您可以在视图中使用 request.GET.get('page', '')。
其他选项:
这应该是您的文件 manifest.urls :
urlpatterns = [
url(r'^archive/?$', view_to_handle),
]
url我试试:http://127.0.0.1:8000/manifest/archive/?page=1
。
正则表达式模式:
- (我试过的原版):
r'^archive/(?P<reverse>[n]{0,1})/?\?page=[0-9]+/?'
- (更简单的我也在python控制台试过。)
r'^archive/\?page=[0-9]+'
- (最简单的,只是尝试。)
r'^archive/\?page=1'
(但是我以正确的方式转义了问号,不是吗?)
我在 python 控制台中尝试了所有这些正则表达式,它们运行良好,所以我认为问题不在于错误的正则表达式。
所以:为什么这行不通?
可选信息:
项目url-conf:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', RedirectView.as_view(url=reverse_lazy('manifest:index'))),
url(r'^manifest/', include('manifest.urls', namespace='manifest')),
]
注意:url 127.0.0.1:8000/manifest/index
应该是匹配的,所以不能把所有东西都弄错了。
url回溯:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/manifest/archive/?page=1
Using the URLconf defined in asqiir005.urls, Django tried these URL patterns, in this order:
^admin/
^$
^manifest/ ^$ [name='index']
^manifest/ ^(?P<number>[0-9]+)$ [name='article']
^manifest/ ^archive/\?page=1
^manifest/ ^archive/(?P<reverse>[n]{0,1})/?\?page=[0-9]+/? [name='paged_archive']
^manifest/ ^archive/all/(?P<reverse>[n]{0,1})/?$ [name='whole_archive']
^media\/(?P<path>.*)$
The current URL, manifest/archive/, didn't match any of these.
您可以在视图中使用 request.GET.get('page', '')。
其他选项:
这应该是您的文件 manifest.urls :
urlpatterns = [
url(r'^archive/?$', view_to_handle),
]