title: Retrieve key from automatically assigned ID which has been passed through URL in GAE, using ndb and python
body: <p>I've been struggling with this for hours and tried everything!</p>
  
  <p>So basically</p>
  
  <p>I have a class called City:</p>
  
  <pre><code>class City(ndb.Model):
      _parent = None
      city = ndb.StringProperty(required=True)
      created = ndb.DateTimeProperty(auto_now_add=True)
  </code></pre>
  
  <p>When i make a new city, it is given an automatic ID, such as 6438740092256256</p>
  
  <p>Later on i want to add a Restaurant entity to this city as a child. So I have passed the city ID in the url, like this:</p>
  
  <p><a href="http://www.edkjfsk.com/addrestaurant/6438740092256256" rel="nofollow">http://www.edkjfsk.com/addrestaurant/6438740092256256</a></p>
  
  <p>which leads to this bit of code</p>
  
  <pre><code>class PostRestaurant(webapp2.RequestHandler):
      def post(self, resource):
          key = ????
  </code></pre>
  
  <p>where resource is 6438740092256256</p>
  
  <p>What i want to do is to be able to retrieve the key using the 6438740092256256 from the url. However every single approach i have tried results in an unknown error. </p>
  
  <p>Ive tried everything, including key = :</p>
  
  <pre><code>City.get_by_id(int(resource))
  
  ndb.Key(City, resource).get()
  
  ndb.Key('City', int(resource))
  </code></pre>
  
  <p>etc.</p>