简体   繁体   English

ReactJS作为前端和Flask作为后端之间的连接问题

[英]connection problem between ReactJS As Frontend And Flask As Backend

The Issue I Am Getting Is That, I Have A Form Which Takes Input User Data and sends the data through The Server to the database, Both the backend and Frontend starts and the data is also stored to the database when form is filled and on which(device) the server is running, but when we try to access the project from different device for form entry then the data is not added to the database我遇到的问题是,我有一个表单,它接受输入的用户数据并通过服务器将数据发送到数据库,后端和前端都启动,并且在填写表单时数据也存储到数据库中(设备)服务器正在运行,但是当我们尝试从不同的设备访问项目以进行表单输入时,数据不会添加到数据库中

其他设备上的错误

#Import required libraries
import pymongo
from flask import Flask, request, jsonify,render_template
from bson.objectid import ObjectId
from flask_cors import CORS,cross_origin
import export

export.init(default=export.PUBLIC)

#Connect to MongoDB Atlas
client = pymongo.MongoClient("mongodb+srv://D:D@cluster0.unaufu9.mongodb.net/R?retryWrites=true&w=majority")
db = client.R

#Initialize flask application
app = Flask(__name__)
CORS = (app)

@app.route("/")
def my_index():
    return render_template("<h1>HEll O! World",flask_token="hello")

It is running on a particular device but not on the other device like all the projects should do.它在特定设备上运行,但不像所有项目应该在其他设备上运行。

I would recommend if you want to add data using another device you can can the ip of the system that has backend up and running then change the http://127.0.0.1:5000 to that IP (example: http://192.168.11.22:5000 ).我建议如果您想使用其他设备添加数据,您可以获取后端已启动并正在运行的系统的 IP,然后将http://127.0.0.1:5000更改为该 IP(例如: http://192.168. 11.22:5000 )。

Keep in mind both devices should be connect from same internet connection请记住,两台设备都应从同一互联网连接进行连接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM