我对 Google 应用引擎很陌生。所以请大家帮我解决这个问题。明确地说,我的代码是错误的,但我不知道它在哪里?这里代码:
import os
import urllib
from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
from google.appengine.ext.webapp.util import run_wsgi_app
import datetime
import wsgiref.handlers
from google.appengine.api import mail
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp \
import template
class MyUsers(db.Model):
firstname = db.StringProperty(
required=False)
lastname = db.StringProperty(
required=False)
email = db.StringProperty(
required=False)
zipcode = db.StringProperty(
required=False)
file = db.BlobProperty(
required=False)
idea = db.TextProperty(
)
ask = db.StringProperty(
required=False)
contact_back = db.StringProperty(
required=False)
phone = db.StringProperty(
required=False)
regdate = db.DateTimeProperty(
auto_now_add=True)
class MainHandler(webapp.RequestHandler):
def get(self):
self.response.out.write(
template.render('expert.html',[]))
class Register(webapp.RequestHandler):
def get(self):
upload_url = blobstore.create_upload_url('/upload')
self.response.out.write(
template.render('expert.html',[]))
def post(self):
user = MyUsers(
firstname = self.request.get('firstname'),
lastname = self.request.get('lastname'),
email = self.request.get('email'),
zipcode = self.request.get('zipcode'),
ask = self.request.get('ask'),
idea = self.request.get('idea'),
file = self.request.get('file'),
contact_back = self.request.get('contact_back'),
phone = self.request.get('phone'),
)
phone = self.request.get('phone')
firstname = self.request.get('firstname')
email = self.request.get('email')
lastname = self.request.get('lastname')
user.put()
emailto = self.request.get('email')
body = """Dear """+firstname+""":
Thank you for registering.
Please let us know if you have any questions.
As One Source.
"""
mail.send_mail("daniyar.seisenov@gmail.com", emailto, "Confirmation Email", body)
mail.send_mail(sender="Daniyar Seisenov <daniyar.seisenov@gmail.com>",
to="Daniyar Seisenov <daniyar.seisenov@gmail.com>",
subject="New User",
body="""
This applicant has just registered. Please review:
Firstname: """+firstname+"""
Lastname: """+lastname+"""
Email: """+email+"""
Phone: """+phone+"""
""")
self.redirect('/')
class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
upload_files = self.get_uploads('file') # 'file' is file upload field in the form
blob_info = upload_files[0]
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self, resource):
resource = str(urllib.unquote(resource))
blob_info = blobstore.BlobInfo.get(resource)
self.send_blob(blob_info)
self.redirect('/serve/%s' % blob_info.key())
class Users(webapp.RequestHandler):
def get(self):
myusers=db.GqlQuery(
'SELECT * FROM MyUsers '
'ORDER BY regdate DESC'
)
values = {
'myusers':myusers,
'totalmyusers' : myusers.count()
}
self.response.out.write(
template.render('userscountandremove.html',
values))
def main():
application = webapp.WSGIApplication([('/', MainHandler),
('/upload', UploadHandler),
('/serve/([^/]+)?', ServeHandler),
('/register',Register),
('/userscountandremove',Users)],
debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()
当我从expert.html 按下提交时,“文件”不会进入数据存储中的blobstore。如果您知道什么是解决方案,请帮助我。谢谢