Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to call an instance of webapp.RequestHandler class inside other module?
    primarykey
    data
    text
    <p>I am trying to create a simple web application using Google App Engine. I use jinja2 to render a frontend html file. User enters their AWS credentials and gets the output of regions and connected with them virtual machines. I have a controller file, to which I import a model file and it looks like this:</p> <pre><code>import webapp2 import jinja2 import os import model jinja_environment = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__))) class MainPage(webapp2.RequestHandler): def get(self): template = jinja_environment.get_template('index.html') self.response.out.write(template.render()) def request_a(self): a = self.reguest.get('a') return a def request_b(self): b = self.reguest.get('b') return b class Responce(webapp2.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.write(testing_ec2.me.get_machines()) app = webapp2.WSGIApplication([('/2', MainPage), ('/responce', Responce)], debug=True) </code></pre> <p>then I have a model file, to which I import controller file and it looks like this:</p> <pre><code>import boto.ec2 import controller import sys if not boto.config.has_section('Boto'): boto.config.add_section('Boto') boto.config.set('Boto', 'https_validate_certificates', 'False') a = controller.MainPage.get() b = controller.MainPage.get() class VM(object): def __init__(self, a, b): self.a = a self.b = b self.regions = boto.ec2.regions(aws_access_key_id = a, aws_secret_access_key = b) def get_machines(self): self.region_to_instance = {}#dictionary, which matches regions and instances for this region for region in self.regions: conn = region.connect(aws_access_key_id = self.a, aws_secret_access_key = self.b) reservations = conn.get_all_instances()#get reservations(need understand them better) if len(reservations) &gt; 0:#if there are reservations in this region self.instances = [i for r in reservations for i in r.instances]#creates a list of instances for that region self.region_to_instance[region.name] = self.instances return self.region_to_instance me = VM(a, b) me.get_machines() </code></pre> <p>When I run this, it throws an error: type object 'MainPage' has no attribute 'request_a' I assume, that it happens, because I do not call an instance of MainPage class and instead call a class itself. What is an instance of MainPage(and it`s parent webapp.RequestHandler) class? How do I call it inside another module?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload