10 examples of 'django redirect' in Python

Every line of 'django redirect' 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(request):
15 return HttpResponseRedirect('/')
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_view(request):
15 return HttpResponseRedirect(target)
9def redirect(url):
10 return lambda res: HttpResponseRedirect(url)
32def redirect_to(request, url):
33 return HttpResponseRedirect(url)
21def f_redirect(req):
22 from django.http import HttpResponseRedirect
23 return HttpResponseRedirect(settings.REDIRECT_URL)
24def redirect(request,path):
25 """Redirect old talk.org blog posts"""
26 return HttpResponsePermanentRedirect("http://neubia.com/archives/%s"%path)
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
227def redirect(self):
228 """Redirect to matching SVG badge."""
229 kwargs = {
230 'project': self.obj.slug,
231 'widget': 'svg',
232 'color': 'badge',
233 'extension': 'svg',
234 }
235 if self.lang:
236 kwargs['lang'] = self.lang.code
237 return reverse('widget-image', kwargs=kwargs)
238 return reverse('widget-image', kwargs=kwargs)
116def redirect_if_no_refresh_token(backend, response, social, *args, **kwargs):
117 """http://python-social-auth.readthedocs.io/en/latest/use_cases.html#re-prompt-google-oauth2-users-to-refresh-the-refresh-token
118 """
119 if (
120 backend.name == "google-oauth2"
121 and social
122 and response.get("refresh_token") is None
123 and social.extra_data.get("refresh_token") is None
124 ):
125 return redirect("/login/google-oauth2?approval_prompt=force")
21def redirect_next(request, field_name, settings_name):
22 try:
23 # get safe url from user input
24 url = request.REQUEST[field_name]
25 url = urlunsplit(('','')+urlsplit(url)[2:])
26 except:
27 url = resolve_url(getattr(settings, settings_name, '/'))
28 return HttpResponseRedirect(url)

Related snippets