-1
我在Google應用引擎上很新穎。所以羅馬請幫我解決這個問題。明確地說,我的代碼是錯誤的,但我不能在哪裏?這裏的代碼:將文件上傳到blobstore數據存儲
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("[email protected]", emailto, "Confirmation Email", body)
mail.send_mail(sender="Daniyar Seisenov <[email protected]>",
to="Daniyar Seisenov <[email protected]>",
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。請幫助我,如果你知道什麼是解決方案。謝謝
感謝您的回覆。你不認爲我的問題可能也在這裏:self.redirect('/服務/%s'%blob_info.key())在我的模板頁面操作是:(/ register)..我試圖用%s替換/註冊,但它不工作..你會介意我該怎麼處理&s嗎?再次感謝 – Danik 2012-04-10 18:15:28
那麼你想要將文件存儲在Blobstore中或作爲數據存儲中的一個blob?首先,你需要弄清楚。 Youre Register()函數將文件保存在數據存儲中,但ServeHandler()嘗試從Blobstore檢索它。 – dragonx 2012-04-10 19:31:04
我想將我的文件存儲在Blobstore中。將不勝感激,如果你能幫助我 – Danik 2012-04-10 23:54:51