【发布时间】:2015-03-23 22:10:44
【问题描述】:
我正在尝试使用 django 重定向应用程序进行 301 重定向,但当我访问旧网址时,我仍然不断收到 404 页面。我按照文档https://docs.djangoproject.com/en/1.6/ref/contrib/redirects/ 并在数据库中添加了一个新旧网址,但它仍然无法正常工作。
还有其他方法可以进行 301 重定向
我有这个网址 http://localhost:8000/doclistings/?speciality=Dentist,我希望它被重定向到 http://localhost:8000/doclistings/?speciality=Dentists
urls.py
url(r'^doclistings/$', views.doclistings, name='doclistings'),
views.py
def doclistings(request):
d = getVariables(request)
if request.method == "GET":
form = DropdownSelectionForm(request.GET)
try:
s_name = request.GET['speciality']
except:
s_name = None
try:
l_name = request.GET['language']
except:
l_name = None
try:
g_name = request.GET['gender']
except:
g_name = None
d['s_name'] = s_name # adding these to the forms for the "selected" option
d['l_name'] = l_name
d['g_name'] = g_name
try:
doctors = filter_doctors(request=request, specialization=s_name, gender=g_name, language=l_name).order_by('-netlikes')
except Exception:
return error404(request)
else:
form = DropdownSelectionForm()
d['doctors'] = doctors
d.update({'form': form, 'languages': Language.objects.all()})
return render_to_response('m1/doclistings.html',d)
【问题讨论】:
-
嗨,您是否考虑过将两个 url 指向 urls.py 中的同一视图
-
我不知道该怎么做。我已经用视图和网址更新了问题
-
你确定你在 try except 表达式中的
doctors = ...是正确的吗?看来您的 404 错误来自这里....