Redirect to a page using Python

How can I redirect to a page using python in frappe?

1 Like

from frappe.utils.selenium_testdriver import TestDriver

then in your function
def example():
driver = TestDriver()
driver.set_route(‘Form’, ‘Test Runner’)

please try this method although it is suggestable to use js for redirecting.
Regards.

I am actually calling a method from Rest API and if successful I want to redirect to a new page

Hi @Khadija
try with : frappe.set_route(“Form”, “Customer”); in your js file or custom script.

you can try : window.history.back(); also.

I am calling this localhost:8000/api/method/somemethod directly from the browser, in somemethod if the functionality is succesful it should redirect me to a page, is that possible?

I tried raise Redirect but it did not work

If possible, will you explain the usecase of that method?

I am trying login user using LoginManger , it logs in and return this message {“home_page”:"/desk",“message”:“Logged In”,“full_name”:“admin”} so how do make it redirect?

it worked by adding
frappe.local.response[“type”] = “redirect”
frappe.local.response[“location”] = “/desk”
at the end

3 Likes

Great!