【发布时间】:2023-03-05 18:53:02
【问题描述】:
我正在尝试使用具有以下结构的 Django 定义搜索 url
www.example.com/afdata/search?device=television&category=news&query=channel&limit=30/
我的目标是从上面的 url 中提取值 television、news、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 响应良好。关于我可能做错的任何建议?
【问题讨论】: