开发者

Django multiple view parameters and duplicated named urls

I was just pondering if make two named urls the same produc开发者_如何学编程es any problems. I tried it and it works. So for example, I have a view that is able to do paging:

def info(request, page_num = 1)    

and I would like to call it both ways, as:

/info
/info/page/1

so I made urls like:

url(r'^info/$', 'views.info', name='info'),
url(r'^info/(?P<page_num>)\d+)/$', 'views.info', name='info'),

and it seems to work. Anything wrong with that, or should I name my second url differently, like info_paginated for example.


Nothing wrong with that and as far as I know pretty standard practice. I know I do it, mostly when I'm using URL's that integrate with Javascript code and I don't have the parameter to use on page load.


It is perfectly fine, but you might want to set page_num = None, then

if page_num is None:
    return redirect(reverse('info',{'page_num':1})

because a search engine sees yoursite.com/info and yoursite.com/info/1 and thinks they are duplicated content, if you redirect from one to another you will be fine.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜