10 examples of 'django redirect with parameters' in Python

Every line of 'django redirect with parameters' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
14def redirect_view(request):
15 return HttpResponseRedirect(target)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

14def redirect(request):
15 return HttpResponseRedirect('/')
32def redirect_to(request, url):
33 return HttpResponseRedirect(url)
9def redirect(url):
10 return lambda res: HttpResponseRedirect(url)
24def redirect(request,path):
25 """Redirect old talk.org blog posts"""
26 return HttpResponsePermanentRedirect("http://neubia.com/archives/%s"%path)
21def f_redirect(req):
22 from django.http import HttpResponseRedirect
23 return HttpResponseRedirect(settings.REDIRECT_URL)
177def redirect_with_query(redirect_uri, params):
178 """Return a Bottle redirect to the given target URI with query parameters
179 encoded from the params dict.
180 """
181 return redirect(redirect_uri + '?' + urllib.urlencode(params))
29def default_redirect(request, fallback_url, **kwargs):
30 redirect_field_name = kwargs.get("redirect_field_name", "next")
31 next_url = request.POST.get(redirect_field_name, request.GET.get(redirect_field_name))
32 if not next_url:
33 # try the session if available
34 if hasattr(request, "session"):
35 session_key_value = kwargs.get("session_key_value", "redirect_to")
36 if session_key_value in request.session:
37 next_url = request.session[session_key_value]
38 del request.session[session_key_value]
39 is_safe = functools.partial(
40 ensure_safe_url,
41 allowed_protocols=kwargs.get("allowed_protocols"),
42 allowed_host=request.get_host()
43 )
44 if next_url and is_safe(next_url):
45 return next_url
46 else:
47 try:
48 fallback_url = reverse(fallback_url)
49 except NoReverseMatch:
50 if callable(fallback_url):
51 raise
52 if "/" not in fallback_url and "." not in fallback_url:
53 raise
54 # assert the fallback URL is safe to return to caller. if it is
55 # determined unsafe then raise an exception as the fallback value comes
56 # from the a source the developer choose.
57 is_safe(fallback_url, raise_on_fail=True)
58 return fallback_url
39@override_settings(APPEND_SLASH=True)
40def test_redirect_not_found_with_append_slash(self):
41 """
42 Exercise the second Redirect.DoesNotExist branch in
43 RedirectFallbackMiddleware.
44 """
45 response = self.client.get('/test')
46 self.assertEqual(response.status_code, 404)
27@override_settings(APPEND_SLASH=True)
28def test_redirect_with_append_slash(self):
29 Redirect.objects.create(site=self.site, old_path='/initial/', new_path='/new_target/')
30 response = self.client.get('/initial')
31 self.assertRedirects(response, '/new_target/', status_code=301, target_status_code=404)

Related snippets