python - 如何配置 app.yaml 以支持像/user/<user-id> 这样的 url?

标签 python google-app-engine

我做了以下事情

- url: /user/.*
  script: script.py

以及 script.py 中的以下处理:

class GetUser(webapp.RequestHandler):
    def get(self):
        logging.info('(GET) Webpage is opened in the browser')
        self.response.out.write('here I should display user-id value')

application = webapp.WSGIApplication(
                                     [('/', GetUser)],
                                     debug=True)

看起来那里有问题。

最佳答案

app.yaml 中你想做类似的事情:

- url: /user/\d+
  script: script.py

然后在 script.py 中:

class GetUser(webapp.RequestHandler):
    def get(self, user_id):
        logging.info('(GET) Webpage is opened in the browser')
        self.response.out.write(user_id)
        # and maybe you would later do something like this:
        #user_id = int(user_id)
        #user = User.get_by_id(user_id)

url_map = [('/user/(\d+)', GetUser),]
application = webapp.WSGIApplication(url_map, debug=True) # False after testing

def main():
    run_wsgi_app(application)

if __name__ == '__main__':
    main()

关于python - 如何配置 app.yaml 以支持像/user/<user-id> 这样的 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5763425/

相关文章:

python - 使用 python 读取 .nc (netcdf) 文件

python - mobilenetv2 tflite 不是 python3 的预期输出大小

java - 将日期和时区从 GAE 服务器发送到 GWT 客户端

Google App Engine 上的 Node.JS 带有 Cloud SQL 错误 : connect ENOENT/cloudsql/

python - NDB 数据存储,如何找到实体大小?

python - 子进程调用错误版本的 'time'

python - Postgres : Retrieve records Sequentially at 5 seconds interval

google-app-engine - 我的谷歌应用程序实例似乎不在正确的区域

python - 在 Django 上更改 ModelChoiceField 的查询集

java - 在非默认模块上运行 appengine 端点