Python 将Flask Restful Google应用程序引擎与Angular一起使用
我想把这个和这个结婚Python 将Flask Restful Google应用程序引擎与Angular一起使用,python,angular,google-app-engine,google-cloud-platform,Python,Angular,Google App Engine,Google Cloud Platform,我想把这个和这个结婚 目录 - /app - css/app.css - js/app.js - index.html - app.yaml - main.py - appengine_config.py - vendor.py - requirements.txt - /static - css/app.css - js/app.js - partials/... - /templates/index.html - app.yaml - mai
目录
- /app
- css/app.css
- js/app.js
- index.html
- app.yaml
- main.py
- appengine_config.py
- vendor.py
- requirements.txt
- /static
- css/app.css
- js/app.js
- partials/...
- /templates/index.html
- app.yaml
- main.py
- appengine_config.py
- vendor.py
- requirements.txt
app.yaml
application: your-application-id-here
version: 1
runtime: python37
api_version: 1
threadsafe: yes
handlers:
- url: /rest/.*
script: main.APP
- url: /(.+)
static_files: app/\1
upload: app/.*
- url: /
static_files: app/index.html
upload: app/index.html
application: application-id-here
version: 1
runtime: python37
api_version: 1
threadsafe: yes
handlers:
- url: /static
static_dir: static
- url: /.*
script: main.app
main.py
from flask import Flask
from flask.ext import restful
APP = Flask(__name__)
api = restful.Api(APP)
class HelloWorld(restful.Resource):
def get(self):
return {'hello': 'world'}
api.add_resource(HelloWorld, '/rest/query/')
@app.errorhandler(404)
def page_not_found(e):
"""Return a custom 404 error."""
return 'Sorry, Nothing at this URL.', 404
@app.errorhandler(500)
def page_not_found(e):
"""Return a custom 500 error."""
return 'Sorry, unexpected error: {}'.format(e), 500
from flask import Flask, render_template
from flask.ext import restful
class HelloWorld(restful.Resource):
def get(self):
return {'hello': 'world'}
app = Flask(__name__)
api = restful.Api(app)
api.add_resource(HelloWorld, '/rest/query')
@app.route('/')
def root():
return render_template('index.html')
@app.errorhandler(404)
def page_not_found(e):
"""Return a custom 404 error."""
return 'Sorry, Nothing at this URL.', 404
@app.errorhandler(500)
def page_not_found(e):
"""Return a custom 500 error."""
return 'Sorry, unexpected error: {}'.format(e), 500
app/
文件夹中的所有内容与python angular项目中的内容完全相同
如果我从app.yaml
中注释掉以下内容,我可以访问/rest/query
,并获得预期的输出
- url: /(.+)
static_files: app/\1
upload: app/.*
- url: /
static_files: app/index.html
upload: app/index.html
然而,当它没有被注释掉时,我得到了/rest/query
的404
。在/
我可以看到静态index.html
页面,页面上加载了角度挂钩。由于app.js
无法查询/rest/query
,因此未填充任何数据
如何设置使用Angular的GAE Flask restful项目?我必须这样做,我部署了一个Flask api,其中包含一个数据库作为web服务和独立应用程序 接下来,您必须添加COR,以允许您的服务与另一个应用程序对话,在本例中,是使用angular框架的前端客户端 然后我部署我的angular应用程序,它将接受对后端web服务的api调用 我的项目为部署到azure的web服务器使用sql server和.net核心web api。以及部署到谷歌云的Angular应用程序。我还将另一个angular应用程序部署到azure
我正在为我的google cloud angular前端应用程序开发一个新的api和dB,以使测试和开发更加容易 我不太喜欢这种解决方法,但我将路由从
app.yaml
移动到了main.py
from flask import Flask
from flask.ext import restful
APP = Flask(__name__)
api = restful.Api(APP)
class HelloWorld(restful.Resource):
def get(self):
return {'hello': 'world'}
api.add_resource(HelloWorld, '/rest/query/')
@app.errorhandler(404)
def page_not_found(e):
"""Return a custom 404 error."""
return 'Sorry, Nothing at this URL.', 404
@app.errorhandler(500)
def page_not_found(e):
"""Return a custom 500 error."""
return 'Sorry, unexpected error: {}'.format(e), 500
from flask import Flask, render_template
from flask.ext import restful
class HelloWorld(restful.Resource):
def get(self):
return {'hello': 'world'}
app = Flask(__name__)
api = restful.Api(app)
api.add_resource(HelloWorld, '/rest/query')
@app.route('/')
def root():
return render_template('index.html')
@app.errorhandler(404)
def page_not_found(e):
"""Return a custom 404 error."""
return 'Sorry, Nothing at this URL.', 404
@app.errorhandler(500)
def page_not_found(e):
"""Return a custom 500 error."""
return 'Sorry, unexpected error: {}'.format(e), 500
main.py
from flask import Flask
from flask.ext import restful
APP = Flask(__name__)
api = restful.Api(APP)
class HelloWorld(restful.Resource):
def get(self):
return {'hello': 'world'}
api.add_resource(HelloWorld, '/rest/query/')
@app.errorhandler(404)
def page_not_found(e):
"""Return a custom 404 error."""
return 'Sorry, Nothing at this URL.', 404
@app.errorhandler(500)
def page_not_found(e):
"""Return a custom 500 error."""
return 'Sorry, unexpected error: {}'.format(e), 500
from flask import Flask, render_template
from flask.ext import restful
class HelloWorld(restful.Resource):
def get(self):
return {'hello': 'world'}
app = Flask(__name__)
api = restful.Api(app)
api.add_resource(HelloWorld, '/rest/query')
@app.route('/')
def root():
return render_template('index.html')
@app.errorhandler(404)
def page_not_found(e):
"""Return a custom 404 error."""
return 'Sorry, Nothing at this URL.', 404
@app.errorhandler(500)
def page_not_found(e):
"""Return a custom 500 error."""
return 'Sorry, unexpected error: {}'.format(e), 500
app.yaml
application: your-application-id-here
version: 1
runtime: python37
api_version: 1
threadsafe: yes
handlers:
- url: /rest/.*
script: main.APP
- url: /(.+)
static_files: app/\1
upload: app/.*
- url: /
static_files: app/index.html
upload: app/index.html
application: application-id-here
version: 1
runtime: python37
api_version: 1
threadsafe: yes
handlers:
- url: /static
static_dir: static
- url: /.*
script: main.app
目录
- /app
- css/app.css
- js/app.js
- index.html
- app.yaml
- main.py
- appengine_config.py
- vendor.py
- requirements.txt
- /static
- css/app.css
- js/app.js
- partials/...
- /templates/index.html
- app.yaml
- main.py
- appengine_config.py
- vendor.py
- requirements.txt
你能显示你的应用程序的目录结构,包括
app.yaml
和main.py
文件的位置吗?@DanCornilescu编辑,如果你查看上面的链接,你会找到appengine\u config.py
和vendor.py
。这些基本上是在根目录中为依赖项创建一个生成的/lib
文件夹。我正在努力克服这个障碍,我可以运行angular应用程序或rest api,但不能同时运行两者。这一定是一个app.yaml
路由问题,对吗?特别是在上面的示例中,您可以使用webapp2