python - How to import a class from ndb.Model? -


i'm working google app engine , want use ndb model in .py file couldn't import it.

here main.py;

from google.appengine.ext import ndb  class user(ndb.model):     username = ndb.stringproperty()     created_date = ndb.datetimeproperty(auto_now=true)     follower_list = ndb.stringproperty(repeated=true) 

and code cron.py file:

from google.appengine.ext import ndb  save_user = user.query().filter(user.username == username) 

but i'm getting:

importerror: no module named user

how can import user class?

when create model you're instantiating class , assigning variable named user. in python variables bound module declared in, , there no implicit globals, if want use in module need import it:

from google.appengine.ext import ndb import main  save_user = main.user.query().filter(main.user.username == username) 

however best practice create models in models.py file, , import anytime need them.


btw, error hints you're trying import user earlier in cron file, so? either way think should idea :)


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -