我試圖限定使用Django一個搜索URL具有以下結構問題和Django URL表達式
www.example.com/afdata/search?device=television&category=news&query=channel&limit=30/
我的目標是提取值television
,news
,從上述URL和通channel
和30
它被定義爲一個視圖如下
def search(request, device='all', category='single', query='', limit=30):
return HttpResponse("device=%s, category=%s, query=%s, limit=%d", device, category, query, limit)
afdata
是應用程序和URL配置文件中我定義的URL如下:
from django.conf.urls.defaults import *
urlpatterns = patterns('afdata.views',
(r'^$', 'index'),
(r'^search?device=(?P<device>.*)&category=(?P<category>.*)&query=(?P<query>.*)&limit=(?P<limit>d+)/$', 'search')
)
當我在瀏覽器中使用上述搜索查詢時,我得到500 Internal Server Error
。 index
回覆良好。任何關於我可能做錯的建議?
它也更加正確:-) – 2011-06-14 05:58:35
@luke正確?!這只是一個小細節;) – 2011-06-14 05:59:15
@詹姆斯,網址的結構如下? 'www.example.com/search?device=television?category=news?query=channel?限制= 30' – David 2011-06-14 06:18:46