how to redirect with multiple parameters in django code example
Example 1: redirect django
from django.shortcuts import redirect
def my_view(request):
return redirect('some-view-name', foo='bar')
Example 2: how to redirect to another page in python
from flask import Flask, redirect, request
app = Flask(__name__)
from urllib.parse import urlparse, urlunparse
FROM_DOMAIN = "yourusername.pythonanywhere.com"
TO_DOMAIN = "www.yourdomain.com"
@app.before_request
def redirect_to_new_domain():
urlparts = urlparse(request.url)
if urlparts.netloc == FROM_DOMAIN:
urlparts_list = list(urlparts)
urlparts_list[1] = TO_DOMAIN
return redirect(urlunparse(urlparts_list), code=301)