AttributeError:'MainHandler'对象没有属性'_render_template'

我对Google App Engine(python)有疑问。我找不到问题,但是它无法按预期工作。错误消息是

self.response.out.write(self._render_template('main.html',template_context))
AttributeError: 'MainHandler' object has no attribute '_render_template'

我的代码在下面,这是什么问题?

import webapp2
import os
import jinja2

from google.appengine.api import users
from models import Note

jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(os.path.dirname(__file__)))

class MainHandler(webapp2.RequestHandler):
def get(self):
    user = users.get_current_user()
    if user is not None:
        logout_url = users.create_logout_url(self.request.uri)
        template_context = {
            'user':user.nickname(),
            'logout_url':logout_url,
        }
        def _render_template(self,template_name, context=None):
            if context is None:
                context = {}
            template = jinja_env.get_template(template_name)
            return template.rendet(context)
        self.response.out.write(self._render_template('main.html',template_context))

    else:
        login_url = users.create_login_url(self.request.uri)
        self.redirect(login_url)
def post(self):
    user = users.get_current_user()
    if user is None:
        self.error(401)
    note = Note(parent=ndb.Key("User",user.nickname()),title=self.request.get('title'),content=self.request.get('content'))
    note.put()
    logout_url = users.create_logout_url(self.request.uri)
    template_context = {
        'user': user.nickname(),
        'logout_url':logout_url,
    }
    template = jinja_env.get_template('main.html')
    self.response.out.write(template.render(template_context))

app = webapp2.WSGIApplication([('/', MainHandler)], debug=True)

以下是我的yaml文件。

application: MYAPPLICATION
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: .*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.2"
- name: jinja2

版本:最新

丹尼尔·罗斯曼

您已经在_render_template方法的if语句中定义了该get方法。

不要那样做 在同一级别定义它getpost

另外,修复最后一行: return template.render(...)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

接收错误;AttributeError: 在 return 语句中使用 render_template 时,“NoneType”对象没有属性“app”

来自分类Dev

AttributeError:对象没有属性

来自分类Dev

AttributeError: '' 对象没有属性 ''

来自分类Dev

AttributeError:“列表”对象没有属性“对象”

来自分类Dev

render_template无法对对象进行jsonify

来自分类Dev

烧瓶:带有路径的render_template

来自分类Dev

AttributeError:“模块”对象没有属性“ tk”

来自分类Dev

AttributeError:'NoneType'对象没有属性'ravel'

来自分类常见问题

AttributeError:“模块”对象没有属性“测试”

来自分类Dev

AttributeError:“模块”对象没有属性“缓存”

来自分类Dev

AttributeError:'dict'对象没有属性'predictors'

来自分类Dev

AttributeError:“模块”对象没有属性“ TestCase”

来自分类Dev

AttributeError:“模块”对象没有属性“版本”

来自分类Dev

AttributeError:对象没有属性“ tk”

来自分类Dev

AttributeError:“模块”对象没有属性

来自分类Dev

AttributeError:“ float”对象没有属性“ center”

来自分类Dev

“ AttributeError:'list'对象没有属性'ravel'”

来自分类Dev

AttributeError:“模块”对象没有属性“绘图”

来自分类Dev

AttributeError:“ Response”对象没有属性“ json”

来自分类Dev

AttributeError:'NoneType'对象没有属性'endswith'

来自分类常见问题

AttributeError:“模块”对象没有属性“请求”

来自分类常见问题

AttributeError:“ ChooseBook”对象没有属性“ txtrd”

来自分类Dev

AttributeError:'Figure'对象没有属性'plot'

来自分类Dev

AttributeError:“模块”对象没有属性“ SignedJwtAssertionCredentials”

来自分类Dev

AttributeError:“ DataFrame”对象没有属性

来自分类Dev

AttributeError:“会话”对象没有属性“保存”

来自分类Dev

AttributeError:“模块”对象没有属性

来自分类Dev

AttributeError:“模块”对象没有属性“ SFrame”

来自分类Dev

AttributeError:“模块”对象没有属性“ scandir”

Related 相关文章

  1. 1

    接收错误;AttributeError: 在 return 语句中使用 render_template 时,“NoneType”对象没有属性“app”

  2. 2

    AttributeError:对象没有属性

  3. 3

    AttributeError: '' 对象没有属性 ''

  4. 4

    AttributeError:“列表”对象没有属性“对象”

  5. 5

    render_template无法对对象进行jsonify

  6. 6

    烧瓶:带有路径的render_template

  7. 7

    AttributeError:“模块”对象没有属性“ tk”

  8. 8

    AttributeError:'NoneType'对象没有属性'ravel'

  9. 9

    AttributeError:“模块”对象没有属性“测试”

  10. 10

    AttributeError:“模块”对象没有属性“缓存”

  11. 11

    AttributeError:'dict'对象没有属性'predictors'

  12. 12

    AttributeError:“模块”对象没有属性“ TestCase”

  13. 13

    AttributeError:“模块”对象没有属性“版本”

  14. 14

    AttributeError:对象没有属性“ tk”

  15. 15

    AttributeError:“模块”对象没有属性

  16. 16

    AttributeError:“ float”对象没有属性“ center”

  17. 17

    “ AttributeError:'list'对象没有属性'ravel'”

  18. 18

    AttributeError:“模块”对象没有属性“绘图”

  19. 19

    AttributeError:“ Response”对象没有属性“ json”

  20. 20

    AttributeError:'NoneType'对象没有属性'endswith'

  21. 21

    AttributeError:“模块”对象没有属性“请求”

  22. 22

    AttributeError:“ ChooseBook”对象没有属性“ txtrd”

  23. 23

    AttributeError:'Figure'对象没有属性'plot'

  24. 24

    AttributeError:“模块”对象没有属性“ SignedJwtAssertionCredentials”

  25. 25

    AttributeError:“ DataFrame”对象没有属性

  26. 26

    AttributeError:“会话”对象没有属性“保存”

  27. 27

    AttributeError:“模块”对象没有属性

  28. 28

    AttributeError:“模块”对象没有属性“ SFrame”

  29. 29

    AttributeError:“模块”对象没有属性“ scandir”

热门标签

归档