This message was deleted.
# ask-ai
s
This message was deleted.
t
Thanks for reaching out, Nakshatra. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! I didn’t come across a ready-made template for a Next.js
page.tsx
to test a Python backend connection, but no worries—I can help you put together a simple example:
Copy code
"use client";

import { useState } from "react";

export default function Home() {
  const [response, setResponse] = useState("");

  const checkBackendConnection = async () => {
    try {
      const res = await fetch(process.env.NEXT_PUBLIC_BACKEND_URL + "/api-endpoint"); // Just swap this with your Python backend URL
      const data = await res.json();
      setResponse(JSON.stringify(data));
    } catch (error) {
      setResponse("Oops, there was an error connecting to the backend: " + error.message);
    }
  };

  return (
    
      Test Python Backend Connection
      
      Response: {response}

    
  );
}
Just replace
process.env.NEXT_PUBLIC_BACKEND_URL
with your environment variable that points to your Python backend URL. This little example uses the Fetch API to send a GET request and then shows you either the response or an error message. If you get stuck or want to tweak it, I’m here to help!