我在Django 1.5中有一个应用程序。我想从一个地址永久重定向到另一个地址。也就是说,我希望获得一种可以重定向的效果:
来自:
domain.com/team/event-2019/01-03-2019/827
至:
domain.com/team/event/01-03-2019/827
-(不包括2019年)
回溯:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/team/event/01-03-2019/827
Django Version: 1.5.4
Python Version: 2.7.12
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'haystack',
'users',
'adminextra',
'cms',
'pages',
'files',
'south',
'debug_toolbar',
'home',
'productions',
'contact',
'search')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'translation.middleware.LocaleMiddleware')
Traceback:
File "project/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "project/web/productions/views.py" in activity_details
284. return redirect(activity.get_absolute_url())
File "project/env/local/lib/python2.7/site-packages/django/shortcuts/__init__.py" in redirect
78. return redirect_class(resolve_url(to, *args, **kwargs))
File "project/env/local/lib/python2.7/site-packages/django/shortcuts/__init__.py" in resolve_url
151. return urlresolvers.reverse(to, args=args, kwargs=kwargs)
File "project/env/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse
496. return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "project/env/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix
381. raise NoReverseMatch("Error importing '%s': %s." % (lookup_view, e))
Exception Type: NoReverseMatch at /team/event/01-03-2019/827
Exception Value: Error importing 'Content-Type: text/html; charset=utf-8
Location: /team/event/01-03-2019/827
': 'HttpResponseRedirect' object has no attribute 'rindex'.
我希望事件位于以下地址:始终在该URL下:domain.com/team/event/01-03-2019/827
,并从以下地址重定向到该URL:domain.com/team/event-2019/01-03-2019/827
现在我得到一个错误:
'HttpResponseRedirect' object has no attribute 'find'
从这里开始:
if event_slug != activity.event.slug or str(date_url) != str(format_date(activity.date, "d-m-Y")):
return HttpResponsePermanentRedirect(activity.get_absolute_url())