0

The url I try: http://127.0.0.1:8000/manifest/archive/?page=1. The regex pattern:

  1. (The original one I tried): r'^archive/(?P<reverse>[n]{0,1})/?\?page=[0-9]+/?'
  2. (An easier I also tried in the python console.) r'^archive/\?page=[0-9]+'
  3. (The easiest possible, just to try.) r'^archive/\?page=1' (But I escaped the question mark in the right way, don't I?)

I tried all of these regexes in the python console and they worked nice, so I think the problem isn't about a wrong regex.

So: why don't this work?


Optional information:

the projects 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')),
]

note: the url 127.0.0.1:8000/manifest/index matches as it should, so can't be about everything is made wrong.


The url traceback:

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.

Asqiir
  • 607
  • 1
  • 8
  • 23
  • Do we really need to handle query params in urls? I think we don't need to. The following url pattern should work fine : url(r'^archive/', view_to_handle), – Anshul Sharma Apr 17 '17 at 12:24

2 Answers2

1

You can use request.GET.get('page', '') in your views.

Other options: https://stackoverflow.com/a/150518/3336408

Community
  • 1
  • 1
XaviP
  • 188
  • 1
  • 2
  • 8
1

This should be your file manifest.urls :

urlpatterns = [
    url(r'^archive/?$', view_to_handle),
]
Anshul Sharma
  • 327
  • 4
  • 14