简体   繁体   English

Flask / Flask-CORS:缺少CORS标头“ Access-Control-Allow-Origin”

[英]Flask/Flask-CORS: CORS header ‘Access-Control-Allow-Origin’ missing

I'm trying to link a Flask backend , running locally on port 5000 with a Vue.js frontend , running locally on port 8080. 我正在尝试将在端口5000上本地运行的Flask后端与在端口8080上本地运行的Vue.js前端链接起来。

I'm able to successfully signup and login, but fail to submit an article in the app, with the following error in the browser console. 我能够成功注册和登录,但无法在应用程序中提交文章,并且在浏览器控制台中出现以下错误。

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:5000/api/articles . 跨域请求被阻止:同源策略禁止读取位于http:// localhost:5000 / api / articles的远程资源。 (Reason: CORS header 'Access-Control-Allow-Origin' missing). (原因:CORS标头“ Access-Control-Allow-Origin”缺失)。

The Flask backend uses Flask CORS (initializes them for every blueprint) and I've provided the localhost/127.0.0.1 origins to the whitelist. Flask后端使用Flask CORS(为每个蓝图初始化它们),并且我已将localhost / 127.0.0.1来源提供给白名单。

#settings.py
    CORS_ORIGIN_WHITELIST = [
        'http://0.0.0.0:4100',
        'http://localhost:4100',
        'http://0.0.0.0:8000',
        'http://localhost:8000',
        'http://0.0.0.0:4200',
        'http://localhost:4200',
        'http://0.0.0.0:4000',
        'http://localhost:4000',
        'http://localhost:8080',
        'http://0.0.0.0:8080',
        'http://127.0.0.1:8080',
        'http://192.168.100.6:8080',
        'localhost'
    ]

#app.py
def register_blueprints(app):
    """Register Flask blueprints."""
    origins = app.config.get('CORS_ORIGIN_WHITELIST', '*')
    cors.init_app(user.views.blueprint, origins=origins)
    cors.init_app(profile.views.blueprint, origins=origins)
    cors.init_app(articles.views.blueprint, origins=origins)

    app.register_blueprint(user.views.blueprint)
    app.register_blueprint(profile.views.blueprint)
    app.register_blueprint(articles.views.blueprint)

#extensions.py

cors = CORS()

Any help would be greatly appreciated. 任何帮助将不胜感激。

Have you tried adding the port to the localhost entry? 您是否尝试过将端口添加到localhost条目?

#settings.py
    CORS_ORIGIN_WHITELIST = [
        'http://0.0.0.0:4100',
        'http://localhost:4100',
        'http://0.0.0.0:8000',
        'http://localhost:8000',
        'http://0.0.0.0:4200',
        'http://localhost:4200',
        'http://0.0.0.0:4000',
        'http://localhost:4000',
        'http://localhost:8080',
        'http://0.0.0.0:8080',
        'http://127.0.0.1:8080',
        'http://192.168.100.6:8080',
        'localhost:8080'
    ]

暂无
暂无

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

相关问题 flask-cors Control-Allow-Origin' - flask-cors Control-Allow-Origin' Flask CORS - 重定向上没有Access-control-allow-origin标头() - Flask CORS - no Access-control-allow-origin header present on a redirect() 被 CORS 策略阻止:No"Access-Control-Allow-Origin" Using Flask - Blocked by CORS policy: No"Access-Control-Allow-Origin" Using Flask Python Flask CORS - 没有“访问控制允许来源”Z099FB995346F31C95EZF6 上存在请求的资源 - Python Flask CORS - No 'Access-Control-Allow-Origin' header is present on the requested resource CORS header 'Access-Control-Allow-Origin' 缺失,尽管 header 从那里开始 - CORS header 'Access-Control-Allow-Origin' missing despite header begin there Django CORS Access-Control-Allow-Origin缺失 - Django CORS Access-Control-Allow-Origin missing 发布到python eve时缺少CORS标头“ Access-Control-Allow-Origin” - CORS header ‘Access-Control-Allow-Origin’ missing when posting to python eve Django,Next.JS:CORS header 'Access-Control-Allow-Origin' 丢失,CORS 请求没有成功,即使定义了 django-cors-headers - Django, Next.JS: CORS header ‘Access-Control-Allow-Origin’ missing, CORS request did not succeed even though django-cors-headers is defined AWS 对 XMLHttpRequest 的访问已被 CORS 策略阻止:No 'Access-Control-Allow-Origin' header - AWS Access to XMLHttpRequest at from origin has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header 为 Flask-CORS 指定域 - Specify domains for Flask-CORS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM