[google-appengine] Re: Forming url with id number
I figured that i_id = item.key().id() logging.info("i_id is: %s" % item.key().id()) gets the id number. Can anyone help about forming the corresponding url? Thanks. On Jan 14, 7:38 pm, Zeynel wrote: > Hello, > > I am working on a simple news site for people to post Sarah Palin > related links. At this point I have a submit > pagehttp://sarah-for-president.appspot.com/submitand a newest > pagehttp://sarah-for-president.appspot.com/newest > > But I also want to add a comments page (like in Hacker News) so that > people can comment on each article. I want to use disqus for comments > and the page will look something like > thishttp://sarah-for-president.appspot.com/comments > > But I don't understand how I can connect an article with its comments. > Hacker News has urls of this typehttp://news.ycombinator.com/item?id=2105038 > > I see in Datastore Viewer that each entry has an id: > > ID/Name: id=1 > date: 2011-01-14 20:51:28.256421 > title: Sarah Palin Wikipedia page > url:http://en.wikipedia.org/wiki/Sarah_Palin > > Can you help me understand how to form the urls of the > formhttp://sarah-for-president.appspot.com/item?id=1 > > Or if this is not correct, what is the correct way? > > This is my app.yaml: > > application: sarah-for-president > version: 1 > runtime: python > api_version: 1 > > handlers: > - url: /favicon.ico > static_files: static/images/favicon.ico > upload: static/images/favicon.ico > > - url: /.* > script: sarah.py > > inbound_services: > - mail > > and the code is here:http://pastebin.com/5bnEURhj > > (sorry for all the HTML, i am not using templating at this point) > > Thanks! -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
[google-appengine] Re: Forming url with id number
I tried this: self.response.out.write("") for item in items: self.response.out.write("""%s comments """ % (cgi.escape(item.url), cgi.escape(item.title), cgi.escape(item.key().id( self.response.out.write("") but gives this error: Traceback (most recent call last): File "C:\Program Files (x86)\Google\google_appengine\google\appengine \ext\webapp\__init__.py", line 515, in __call__ handler.get(*groups) File "C:\sarah.py", line 37, in get (cgi.escape(item.url), cgi.escape(item.title), cgi.escape(item.key().id( File "C:\Python26\lib\cgi.py", line 1023, in escape s = s.replace("&", "&") # Must be done first! AttributeError: 'long' object has no attribute 'replace' Can anyone help? On Jan 14, 9:10 pm, Zeynel wrote: > I figured that > > i_id = item.key().id() > > logging.info("i_id is: %s" % item.key().id()) > > gets the id number. Can anyone help about forming the corresponding > url? > > Thanks. > > On Jan 14, 7:38 pm, Zeynel wrote: > > > > > > > > > Hello, > > > I am working on a simple news site for people to post Sarah Palin > > related links. At this point I have a submit > > pagehttp://sarah-for-president.appspot.com/submitanda newest > > pagehttp://sarah-for-president.appspot.com/newest > > > But I also want to add a comments page (like in Hacker News) so that > > people can comment on each article. I want to use disqus for comments > > and the page will look something like > > thishttp://sarah-for-president.appspot.com/comments > > > But I don't understand how I can connect an article with its comments. > > Hacker News has urls of this typehttp://news.ycombinator.com/item?id=2105038 > > > I see in Datastore Viewer that each entry has an id: > > > ID/Name: id=1 > > date: 2011-01-14 20:51:28.256421 > > title: Sarah Palin Wikipedia page > > url:http://en.wikipedia.org/wiki/Sarah_Palin > > > Can you help me understand how to form the urls of the > > formhttp://sarah-for-president.appspot.com/item?id=1 > > > Or if this is not correct, what is the correct way? > > > This is my app.yaml: > > > application: sarah-for-president > > version: 1 > > runtime: python > > api_version: 1 > > > handlers: > > - url: /favicon.ico > > static_files: static/images/favicon.ico > > upload: static/images/favicon.ico > > > - url: /.* > > script: sarah.py > > > inbound_services: > > - mail > > > and the code is here:http://pastebin.com/5bnEURhj > > > (sorry for all the HTML, i am not using templating at this point) > > > Thanks! -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
[google-appengine] Re: Forming url with id number
converting the id to string appears to have solved the problem: self.response.out.write("") for item in items: self.response.out.write("""%s comments """ % (cgi.escape(item.url), cgi.escape(item.title), cgi.escape(str(item.key().id() self.response.out.write("") On Jan 14, 9:38 pm, Zeynel wrote: > I tried this: > > self.response.out.write("") > for item in items: > self.response.out.write("""%s > comments """ % > (cgi.escape(item.url), > cgi.escape(item.title), cgi.escape(item.key().id( > self.response.out.write("") > > but gives this error: > > Traceback (most recent call last): > File "C:\Program Files (x86)\Google\google_appengine\google\appengine > \ext\webapp\__init__.py", line 515, in __call__ > handler.get(*groups) > File "C:\sarah.py", line 37, in get > (cgi.escape(item.url), cgi.escape(item.title), > cgi.escape(item.key().id( > File "C:\Python26\lib\cgi.py", line 1023, in escape > s = s.replace("&", "&") # Must be done first! > AttributeError: 'long' object has no attribute 'replace' > > Can anyone help? > > On Jan 14, 9:10 pm, Zeynel wrote: > > > > > > > > > I figured that > > > i_id = item.key().id() > > > logging.info("i_id is: %s" % item.key().id()) > > > gets the id number. Can anyone help about forming the corresponding > > url? > > > Thanks. > > > On Jan 14, 7:38 pm, Zeynel wrote: > > > > Hello, > > > > I am working on a simple news site for people to post Sarah Palin > > > related links. At this point I have a submit > > > pagehttp://sarah-for-president.appspot.com/submitandanewest > > > pagehttp://sarah-for-president.appspot.com/newest > > > > But I also want to add a comments page (like in Hacker News) so that > > > people can comment on each article. I want to use disqus for comments > > > and the page will look something like > > > thishttp://sarah-for-president.appspot.com/comments > > > > But I don't understand how I can connect an article with its comments. > > > Hacker News has urls of this > > > typehttp://news.ycombinator.com/item?id=2105038 > > > > I see in Datastore Viewer that each entry has an id: > > > > ID/Name: id=1 > > > date: 2011-01-14 20:51:28.256421 > > > title: Sarah Palin Wikipedia page > > > url:http://en.wikipedia.org/wiki/Sarah_Palin > > > > Can you help me understand how to form the urls of the > > > formhttp://sarah-for-president.appspot.com/item?id=1 > > > > Or if this is not correct, what is the correct way? > > > > This is my app.yaml: > > > > application: sarah-for-president > > > version: 1 > > > runtime: python > > > api_version: 1 > > > > handlers: > > > - url: /favicon.ico > > > static_files: static/images/favicon.ico > > > upload: static/images/favicon.ico > > > > - url: /.* > > > script: sarah.py > > > > inbound_services: > > > - mail > > > > and the code is here:http://pastebin.com/5bnEURhj > > > > (sorry for all the HTML, i am not using templating at this point) > > > > Thanks! -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
[google-appengine] Re: Forming url with id number
On Jan 15, 9:14 am, djidjadji wrote: > You could use the URL dispatcher to check for validity of the passed > id by making the id part of the URL > > http://me-for-president.appspot.com/item/1 > > in the code > > class ItemPage(webapp.RequestHandler): > def get(self, id): > id = int(id) > # rest of the handler > > application = webapp.WSGIApplication([('/item/(\d+)', ItemPage)], > debug=True) > Thanks for this information! Exactly what I was trying to understand. I changed the handler like this: class Article(webapp.RequestHandler): def get(self, id): id = int(id) self.response.out.write("""article title """ % (id)) and it works fine. But now how do I get the article title from the other handler where it is inside the for loop. Because in this handler I cannot use "item.title". What is the way to do this? Thanks again. -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
[google-appengine] Re: Forming url with id number
On Jan 15, 11:18 am, djidjadji wrote: > And deal with the individual item in the next handler > > class ItemPage(webapp.RequestHandler): > def get(self, id): > id = int(id) > item = Item.get_by_id(id) > # rest of the handler > Thanks for your help. This works: class Article(webapp.RequestHandler): def get(self, id): id = int(id) item = Item.get_by_id(id) ... self.response.out.write("""%s """ % (cgi.escape(item.url), cgi.escape(item.title))) -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
[google-appengine] Re: Forming url with id number
Thanks. Disqus works great but I am having a styling issue that may be my fault. I use and the count shows as "x comments". In other words, disqus does not recognize my link text; even if it ıs blank it shows "x comments" like in this page http://sarah-for-president.appspot.com/ On Jan 16, 10:04 pm, "Nick Johnson (Google)" wrote: > Hi Zeynel, > > You might want to read my blog post about using Disqus on App > Engine:http://blog.notdot.net/2009/10/Blogging-on-App-Engine-part-6-Comments... > > You don't need to do anything special - just create one page for each item > that people can comment on, and embed the Disqus code in that page. > > -Nick Johnson > > > > > > > > > > On Sat, Jan 15, 2011 at 11:38 AM, Zeynel wrote: > > Hello, > > > I am working on a simple news site for people to post Sarah Palin > > related links. At this point I have a submit page > >http://sarah-for-president.appspot.com/submitand a newest page > >http://sarah-for-president.appspot.com/newest > > > But I also want to add a comments page (like in Hacker News) so that > > people can comment on each article. I want to use disqus for comments > > and the page will look something like this > >http://sarah-for-president.appspot.com/comments > > > But I don't understand how I can connect an article with its comments. > > Hacker News has urls of this type > >http://news.ycombinator.com/item?id=2105038 > > > I see in Datastore Viewer that each entry has an id: > > > ID/Name: id=1 > > date: 2011-01-14 20:51:28.256421 > > title: Sarah Palin Wikipedia page > > url:http://en.wikipedia.org/wiki/Sarah_Palin > > > Can you help me understand how to form the urls of the form > >http://sarah-for-president.appspot.com/item?id=1 > > > Or if this is not correct, what is the correct way? > > > This is my app.yaml: > > > application: sarah-for-president > > version: 1 > > runtime: python > > api_version: 1 > > > handlers: > > - url: /favicon.ico > > static_files: static/images/favicon.ico > > upload: static/images/favicon.ico > > > - url: /.* > > script: sarah.py > > > inbound_services: > > - mail > > > and the code is here:http://pastebin.com/5bnEURhj > > > (sorry for all the HTML, i am not using templating at this point) > > > Thanks! > > > -- > > You received this message because you are subscribed to the Google Groups > > "Google App Engine" group. > > To post to this group, send email to google-appengine@googlegroups.com. > > To unsubscribe from this group, send email to > > google-appengine+unsubscr...@googlegroups.com > e...@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/google-appengine?hl=en. > > -- > Nick Johnson, Developer Programs Engineer, App Engine > Google Ireland Ltd. :: Registered in Dublin, Ireland, Registration Number: > 368047 -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
Re: [google-appengine] Re: Forming url with id number
You could use the URL dispatcher to check for validity of the passed id by making the id part of the URL http://me-for-president.appspot.com/item/1 in the code class ItemPage(webapp.RequestHandler): def get(self, id): id = int(id) # rest of the handler application = webapp.WSGIApplication([('/item/(\d+)', ItemPage)], debug=True) def main(): run_wsgi_app(application) Use some sort of template engine. Much easier if the site or pages gets bigger. -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
Re: [google-appengine] Re: Forming url with id number
First you make an index page containing all the items you want to show based on a filtering, maybe date. class ItemIndexPage(webapp.RequestHandler): def get(self): items = Item.all().filter(...some filter...).fetch(1000) self.response.out.write("") for item in items: self.response.out.write("""%s comments """ % (cgi.escape(item.url), cgi.escape(item.title), cgi.escape(item.key().id( self.response.out.write("") And deal with the individual item in the next handler class ItemPage(webapp.RequestHandler): def get(self, id): id = int(id) item = Item.get_by_id(id) # rest of the handler application = webapp.WSGIApplication([('/items', ItemIndexPage)],('/item/(\d+)', ItemPage)], debug=True) -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.