google app engine - Django + ndb/GAE: can't figure out how to properly display results from queries -
I am on a Google App Engine application, and I am using the tools for visuals, templates and file structure, And dealing with NDB / Datastore for models / questions.
My problem is that I did not know how to properly display a model through a query. It seems that I am posting on datastore and can recover it properly, but I can not print anything I have achieved. I take a stringproperty () object, which I think the DJGENGO is unable to understand the request handler, so it actually prints "stringproperty ()" Either, or I do not understand NDB questions and I think :)
Still, any idea how can I show it right? Am I trying to combine NDB and Dzegoo in this way?
How it looks:
Import to google.appengine.ext from models.py:
ndb #make your model here Class contact (ndb.model): name = ndb.StringProperty address_street = ndb.StringProperty address_extra = ndb.StringProperty address range = ndb.StringProperty address_state = ndb.StringProperty address_zipcode = ndb.StringProperty email = ndb.StringProperty phone = ndb.StringProperty < / Code> > In prequisitions:
import from django.core.context_processors from http django.template django.views.decorators.csrf import csrf_protect from CSRF Import import from django.shortcuts import from RequestContext model render_to_response import import contact def home (request): contacts = contact.query () fetch () return to render_to_response ('index.html', {'message': 'hello world', ' Contacts': Copies }} Def form (request): C = RequestContext (request) if request.method == 'POST': contact = contact () contact.name = request.POST ['name'] address_street = request.POST ['road '] Address_extra = request.POST [' extra '] addresses = [request]. ['City'] address_state = request. POST ['state'] address_jipcode = request POST ['Zipcode'] Email = Request POST ['email'] phone = request. POST ['phone'] contact.put () Return render_to_response ('form.html', {'message': 'Your contact,' + contact.name + ', has been added.'}, C) else: return render_to_response ('Form.html', {'message': 'form!'}, C) index.html: {% extension of "base .html"%} {% block pagestyle %} {% Endblock%} {% block content%} {{message}} & lt; Br> & Lt; Br> & Lt; Table border = 1 & gt; & Lt; TR & gt; & Lt; TD & gt; Name & lt; / TD & gt; & Lt; TD & gt; Address & lt; / TD & gt; & Lt; TD & gt; City & lt; / TD & gt; & Lt; TD & gt; State & lt; / TD & gt; & Lt; TD & gt; Zipcode & lt; / TD & gt; & Lt; TD & gt; Email & lt; / TD & gt; & Lt; TD & gt; Phone & lt; / TD & gt; & Lt; / TR & gt; {% Contacts in contact%} & lt; Tr & gt; & Lt; Td> {{Contact.name}} & lt; / Td> & Lt; / TR & gt; {% Endfor%} & lt; / Table & gt; & Lt; Div class = "button" value = "/ form" & gt; Add a contact & lt; / Div & gt; {% Endblock%}
You define the model's definition is wrong. Name = ndb.StringProperty () address_street = ndb.StringProperty () address_extra: You are not creating properties, just holding the reference for the property class, contact it
class (ndb.model ) Should be = ndb.StringProperty () address_city = ndb.StringProperty () address_state = ndb.StringProperty () address_zipcode = ndb.StringProperty () email = ndb.StringProperty () phone = ndb.StringProperty ()
and why are you seeing stringproperty in the output.
Comments
Post a Comment