【问题标题】:Error when retrieving URL path in GAE + python + Flask在 GAE + python + Flask 中检索 URL 路径时出错
【发布时间】:2020-07-22 21:38:42
【问题描述】:

我正在尝试在 GAE + python + flask 中检索我的应用程序的 URL,并在本地运行时收到以下错误:

NameError: name 'self' is not defined

这是我用来检索 URL 路径并显示它的代码的 sn-p。

import Flask, session, etc etc

... 

@app.route('/')
def main():
    if 'username' in session:
        message = self.request.path 
        return render_template('main.html', username=session['username'], message=message) 

    return redirect(url_for('login'))

当我在我的 Ubuntu 机器上本地运行应用程序时,我得到上面复制的 NameError。我在 StackOverflow 中进行了搜索,一些帖子提到应该在存在的方法中调用“self”。我在def main()中调用'self',所以我希望它可以工作但没有。看起来我遗漏了一些关于“自我”范围的信息。

任何想法有什么问题吗?一旦成功,我会将其上传到云端的 GAE。

谢谢!

【问题讨论】:

    标签: python google-app-engine flask


    【解决方案1】:

    函数中没有self。使用:

    message = request.path

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多