Как сделать перенаправление в Django и React?
Мне нужно сделать перенаправление сразу после нажатия кнопки.
<Button onClick={changeCalendar}>Integrate Google Calendar</Button>
Итак, я посылаю запрос на сервер, чтобы сделать перенаправление
const changeCalendar = async () => {
let response = await fetch("http://localhost:8000/gcalendar/", {
mode: "no-cors",
method: "GET",
headers: {
Authorization: "Bearer " + String(authTokens.access),
},
});
На стороне сервера я обрабатываю запрос и получаю URL
def change_calendar(request):
flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
CLIENT_SECRETS_FILE,
scopes=SCOPES)
flow.redirect_uri = 'http://localhost:3000/'
authorization_url, state = flow.authorization_url(
access_type='offline',
include_granted_scopes='true')
return redirect(authorization_url)
Если я печатаю authorization_url
, это выглядит следующим образом:
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=**ID**&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.events&state=**STATE**&access_type=offline&include_granted_scopes=true
Если я копирую и вставляю ссылку в поиск Google, то открывается окно авторизации Google. Мне нужно сделать то же самое через код. Но редирект не работает. Даже если я пытаюсь сделать редирект на другие ссылки.