Возможный не обработанный отказ обещания (id: 0): [AxiosError: Network Error] - React Native и Django
Я пытаюсь получить данные из бэкенда Django для моего проекта React Native, но получаю эту ошибку
Possible Unhandled Promise Rejection (id: 0): [AxiosError: Network Error]
я новичок в react native и django, но я делал это раньше в react js, но я не знаю, почему я не могу заставить это работать здесь
Вот мой код React Native
import React, { useState, useEffect } from "react";
import axios from "axios";
import { StyleSheet, ScrollView, View, Text } from "react-native";
// Components
import ProductCard from "../components/ProductCard";
export default function HomeScreen({ navigation }) {
const [products, setProducts] = useState([]);
useEffect(() => {
async function fetchProducts() {
const { data } = await axios.get("http://127.0.0.1:8000/api/products/");
setProducts(data);
}
fetchProducts();
}, []);
return (
<View style={styles.container}>
<ScrollView style={styles.scrollView}>
{products.map((product) => (
<View style={styles.productsContainer}>
<ProductCard product={product} navigation={navigation} />
</View>
))}
</ScrollView>
</View>
);
}
Я также добавил их в файл settings.py
INSTALLED_APPS = [
"corsheaders",
]
MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
]
CORS_ALLOW_ALL_ORIGINS = True