Can someone give a basic idea on how to approach the problem. It's not working on localhost and blobstore is also not working. Is there any other method or can someone show me the correct approach?
I am only showing the code related to the query....
Here is the pic of error
html code
<div class="form-group">
<input type="file" class="form-control" name="profile_pic" value="" placeholder="profile_pic">
<div class="error">
{{error_username}}
</div>
</div>
Takes input from form.
class Signup(BlogHandler): def get(self): self.render("signup-form.html")
def post(self):
have_error = False
self.username = self.request.get('username')
self.profile_pic = self.request.get('profile_pic')
self.password = self.request.get('password')
self.verify = self.request.get('verify')
self.email = self.request.get('email')
params = dict(username = self.username,
email = self.email)
if not valid_username(self.username):
params['error_username'] = "That's not a valid username."
have_error = True
if not valid_password(self.password):
params['error_password'] = "That wasn't a valid password."
have_error = True
elif self.password != self.verify:
params['error_verify'] = "Your passwords didn't match."
have_error = True
if not valid_email(self.email):
params['error_email'] = "That's not a valid email."
have_error = True
if have_error:
self.render('signup-form.html', **params)
else:
self.done()
def done(self, *a, **kw):
raise NotImplementedError
class to pass parameters to register function in User class
class Register(Signup,blobstore_handlers.BlobstoreUploadHandler):
def done(self):
u = User.by_name(self.username)
if u:
msg = 'That user already exists.'
self.render('signup-form.html', error_username = msg)
else:
upload = self.get_uploads()[0]
u = User.register(self.username, self.password, upload.key(), self.email)
u.put()
self.login(u)
self.redirect('/blog')
The user Model. Parameter profile_pic is passed and assigned profile_pic to column profile_pic in User entity
class User(db.Model):
name = db.StringProperty(required = True)
pw_hash = db.StringProperty(required = True)
email = db.StringProperty()
profile_pic = db.BlobProperty()
@classmethod
def by_id(cls, uid):
return User.get_by_id(uid, parent = users_key())
@classmethod
def by_name(cls, name):
u = User.all().filter('name =', name).get()
return u
@classmethod
def register(cls, name, pw, profile_pic, email = None):
pw_hash = make_pw_hash(name, pw)
return User(parent = users_key(),
name = name,
pw_hash = pw_hash,
profile_pic = profile_pic,
email = email)
@classmethod
def login(cls, name, pw):
u = cls.by_name(name)
if u and valid_pw(name, pw, u.pw_hash):
return u