2017-04-17 123 views
0

我嘗試的網址:http://127.0.0.1:8000/manifest/archive/?page=1。 的正則表達式:(django)url正則表達式不匹配

  1. (原來的我試過):(最簡單的可能,只是爲了嘗試)r'^archive/(?P<reverse>[n]{0,1})/?\?page=[0-9]+/?'
  2. (更簡單的我也試過在Python控制檯)r'^archive/\?page=[0-9]+'
  3. r'^archive/\?page=1' (但我逃以正確的方式問號,不是嗎?)

我嘗試了所有這些正則表達式中的巨蟒控制檯和他們的工作很好,所以我覺得這個問題是不是一個錯誤的正則表達式。

所以:爲什麼這不工作?


可選信息:

項目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比賽,因爲它應該,所以不能對萬事發錯了。


的網址追蹤:

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.

+0

我們真的需要處理查詢參數在URL中?我認爲我們不需要。 下面的url模式應該可以正常工作: url(r'^ archive /',view_to_handle), –

回答

1

這應該是你的文件manifest.urls

urlpatterns = [ 
    url(r'^archive/?$', view_to_handle), 
]