def test_direct_instantiation(self): """ It should be possible to use the view without going through .as_view() (#21564). """ view = RedirectView() response = view.dispatch(self.rf.head('/foo/')) self.assertEqual(response.status_code, 410)
def ownRedirect(request, url, permanent=False, queryString=True): redirectView = RedirectView(url=url, permanent=permanent, query_string=queryString) redirectView.request = request return redirectView.get(request)
def test_deprecation_warning_init(self): with warnings.catch_warnings(record=True) as warns: warnings.simplefilter('always') view = RedirectView() response = view.dispatch(self.rf.head('/python/')) self.assertEqual(response.status_code, 410) self.assertEqual(len(warns), 1) self.assertIs(warns[0].category, RemovedInDjango19Warning) self.assertEqual( six.text_type(warns[0].message), "Default value of 'RedirectView.permanent' will change " "from True to False in Django 1.9. Set an explicit value " "to silence this warning.", )
from django.conf.urls import url from django.views.generic import TemplateView, RedirectView urlpatterns = [ url(r'^', TemplateView.as_view(template_name='index.html')), url(r'hello', RedirectView(template_name='home.html')), ]