2009-09-29 2 views
0

속성이 없습니다 :서브 클래스 내 템플릿로드 잘, 응답이 아래의 코드를 사용

e = AttributeError("'ToDo' object has no attribute 'response'",) 

ToDo하지 않습니다 개체에 response 속성이 없습니까? 처음으로 호출됩니다.

import cgi 
import os 

from google.appengine.api import users 
from google.appengine.ext import webapp 
from google.appengine.ext.webapp.util import run_wsgi_app 
from google.appengine.ext.webapp import template 
from google.appengine.ext import db 

class Task(db.Model): 
    description = db.StringProperty(required=True) 
    complete = db.BooleanProperty() 

class ToDo(webapp.RequestHandler): 

    def get(self): 
     todo_query = Task.all() 
     todos = todo_query.fetch(10) 
     template_values = { 'todos': todos } 

     self.renderPage('index.html', template_values) 

    def renderPage(self, filename, values): 
     path = os.path.join(os.path.dirname(__file__), filename) 
     self.response.out.write(template.render(path, values))   


class UpdateList(webapp.RequestHandler): 
    def post(self): 
     todo = ToDo() 
     todo.description = self.request.get('description') 
     todo.put() 
     self.redirect('/') 

application = webapp.WSGIApplication(
            [('/', ToDo), 
             ('/add', UpdateList)], 
            debug=True) 

def main(): 
    run_wsgi_app(application) 

if __name__ == "__main__": 
    main() 

지금까지 템플릿 코드가 있습니다. 지금은 설명을 나열하고 있습니다.

<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> 
<html> 
<head> 
    <title>ToDo tutorial</title> 
</head> 
<body> 
    <div> 
    {% for todo in todos %} 
     <em>{{ todo.description|escape }}</em> 
    {% endfor %} 
    </div> 

    <h3>Add item</h3> 
    <form action="/add" method="post"> 
     <label for="description">Description:</label> 
     <input type="text" id="description" name="description" /> 
     <input type="submit" value="Add Item" /> 
    </form> 
</body> 
</html> 

답변

3

post에서 무엇을합니까? 그것은해야한다 :

def post(self): 
    task = Task()    # not ToDo() 
    task.description = self.request.get('description') 
    task.put() 
    self.redirect('/') 

put

webapp.RequestHandler 것이다 try to handle PUT request, according to docs의 서브 클래스에서 호출.

+1

* 이마를 때리면 * 때때로 나무에 숲이 보이지 않을 수도 있습니다. 그래, 그래야 했어. 고맙습니다 SilentGhost. – Phil

관련 문제