저는 GAE와 언어 Python에 익숙하지 않고 매우 간단한 작업을하고 싶습니다. 주석 상자 (http://soltexfirstapp.appspot.com)가 있어야하며, 누군가 새로운 것을 작성했는지 확인하고 싶습니다. 사용자가 새로운 것을 제출하기 전에 댓글을 달고 "댓글 상자에 새로운 댓글이 있습니다. 계속 하시겠습니까?"라고 말하는 상자를 알려주십시오. 예 혹은 아니오?". 그래서 파이썬 구문, 특히 쿼리와 혼동스러워지고 있습니다. Google App Engine 데이터베이스 최종 입력
내 코드 작업
...소리. 평
import webapp2
import datetime
import time
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp \
import template
class Shout(db.Model):
message = db.StringProperty(required=True)
when = db.DateTimeProperty(auto_now_add=True)
who = db.StringProperty()
class MainPage(webapp2.RequestHandler):
def get(self):
shouts = db.GqlQuery('SELECT * FROM Shout '
'ORDER BY when ASC')
values = {
'shouts': shouts
}
# my attempt to make and print the query
# aaa = db.GqlQuery('SELECT * FROM Shout '
'ORDER BY when DESC LIMIT 1')
# self.response.out.write('Query is: %s', aaa)
self.response.out.write(template.render('main.html',values))
def post(self):
shout = Shout (
message = self.request.get('message'),
who = self.request.get('who'))
shout.put()
self.redirect('/')
application = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
main.html은
<!DOCTYPE html>
<html>
<head>
<title>Comment System</title>
<link rel="stylesheet" href="./css/main.css" media="screen" />
</head>
<body>
<h1>Cloud Comment System</h1>
{% for shout in shouts %}
<div>
<div id="fl">
{{shout.when}}
from
{% ifequal shout.who "" %}
Anonymous
{% else %}
{{shout.who}}
{% endifequal %}
</div>
{{shout.message}}
</div>
{% endfor %}
<form action="" method="post" accept-charset="utf-8">
<p>From:<input type="text" name="who" value="" id="who"></p>
<p>Message:<input type="text" name="message" value="" id="message"></p>
<p><input type="submit" name="" value="comment"></p>
</form>
</body>
</html>
난 정말 어떤 도움을 주셔서 감사합니다. 감사합니다
네, 맞습니다. 제 코드가 작동하고 있다고 말했어야합니다. Iam은 ASC에 의한 명령을 사용하고, 마지막 명령은 가장 새로운 명령이므로, 그것은 나를위한 것이다. 여분의 문자에 대해서는 두 가지 방법이 옳습니다. google 개발자가 만든이 동영상 (https://www.youtube.com/watch?v=bfgO-LXGpTM)을 6시 49 분에 확인하십시오. "가져 오기"팁을 주셔서 감사합니다. 저는 지금 당장 그것에 대해 생각하지 않았습니다. 그러나 좋은 아이디어입니다. 구현하려고합니다. 내가 원하는 것은 사용자가 의견을 제출하기 전후에 마지막 "시기"를 비교합니다. 제출 후와 게시물 이전에 동일하지 않은 경우 사용자에게 경고해야합니다. – soltex
아마도 비동기 자바 스크립트 요청을 사용해야 할 것입니다. 그렇지 않으면 올바르게 말하고있는 것을 이해할 수 있다면 기사를 두 번 제출해야합니다. –