How to grant access to google appengine page in Python?
Question: I have a simple app that serves a page, I want this page to be accessible only
to a couple of predetermined users already signed into Google. In fact, I want
access only through importHTML function in Google Spreadsheets.

How to implement this with minimum fuss? Here's the app:

    
    
    import webapp2
    
    class MainPage(webapp2.RequestHandler):
      def get(self):
        self.response.out.write('/Statement.htm')
    
    app = webapp2.WSGIApplication([('/Statement.htm', MainPage)],
                                  debug=True)
    

Here's the app.yaml

    
    
    application: *********
    version: 1
    runtime: python27
    api_version: 1
    threadsafe: true
    
    handlers:
    - url: /.*
      static_files: Statement.htm
      upload: Statement.htm
    

I've seen this in the tutorial:

    
    
    from google.appengine.api import users
    
    class MainPage(webapp2.RequestHandler):
    
            user = users.get_current_user()
    

But who is this "get_current_user"? I don't want any logins, I just want it to
be some kind of Google ID that I can check with if/else and serve out error
page if it doesn't match one or two allowed names.


Answer: You should give them admin permission from your google app engine dashboard -
under Administration -> Permissions - and add to your app.yaml file:

**EDIT:**

This is a way to do it using jinja2 template system.

app.yaml file:

    
    
    application: statement
    version: 1
    runtime: python27
    api_version: 1
    threadsafe: true
    
    handlers:
    - url: /statement
      script: statement.app
      login: admin
    
    libraries:
    - name: jinja2
      version: latest
    

statement.py file:

    
    
    import webapp2
    import jinja2
    import os
    
    jinja_environment = jinja2.Environment(
        loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
    
    class Statement(webapp2.RequestHandler):
        def get(self):
            template = jinja_environment.get_template('Statement.htm')
            self.response.out.write(template.render())
    
    
    
    app = webapp2.WSGIApplication([('/statement', Statement)],
                                  debug=True)
    

Statement.htm file:

`You must have been granted admin permission.`

When you go to `http://127.0.0.1:8080/statement` you must login as admin to
get there. All three files are in the same directory. If your python main file
has other name you should use that name and the extension `.app` in the
app.yaml file:

`script: your-python-file-name.app`

