开发者

Maintaining URL parameters across page views

I am writing a Django application and would like to provide optional filters and sort options to the results displayed. I would like to represent these optional filters and sort options using RESTful URLs such as

  • /
  • /tags/tag1/
  • /tags/tag1/page2
  • /tags/ta开发者_Python百科g1/by/newest-desc/
  • /tags/tag1/by/newest-desc/page2

etc.

How should I maintain the existing URL filters or sort options across page views? I have tried using

{% url 'list-view' tags=tags sort=sort-option %} 

in my templates but these cause problems when viewing pages without both tags and sort-option parameters already set.

This problem is very similar to Using both sort & filter on a QuerySet but I am really looking for a RESTful URL solution, not a GET parameter or session state variable solution.

Any suggestions would be greatly appreciated.

Niall


Sort order should be a GET parameter as should be the page number. They'll be much easier to handle that way.

Think about it this way: the /tags/tag1 indicate what you are viewing. The other two indicate certain display options.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜