Flask Blueprint pass object to another file

sealabr

I'm using python selenium to make a webservice when it's called will execute some instructions to a page, but the problem is pass 'driver' class to another page using flask blueprint.

main.py

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options as chrome_options
from classes.send_message import send_message
from flask import Flask
from flask_restful import Resource, Api
from flask import request

app = Flask(__name__)
api = Api(app)

app.register_blueprint(send_message)

if __name__ == '__main__':

    logging.info('START APP')

    options = webdriver.ChromeOptions() 
    options.add_argument("user-data-dir=C:\\myuserpath........")
    driver = webdriver.Chrome(executable_path="chromedriver.exe", chrome_options=options)

    driver.get("https://example.com")

    app.run(host='192.168.50.1', port='11111',debug=False)

send_message.py

from flask import Blueprint
#from flask import current_app as app    
send_message = Blueprint('send_message', __name__)

@send_message.route("/SendPostMessage")
def sendMessage():
    side_panel = driver.find_element_by_id('menutop') # error here!!!

error:

  File "C:\python36\lib\site-packages\flask\app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\rararara\classes\send_message.py", line 8, in sendMessage
    side_panel = driver.find_element_by_id('menutop')
NameError: name 'driver' is not defined
Tamas Hegedus

You can use the app object as a context:

...
driver.get("https://example.com")
app.driver = driver
app.run(host='192.168.50.1', port='11111',debug=False)

and then

from flask import current_app as app
...
@send_message.route("/SendPostMessage")
def sendMessage():
    side_panel = app.driver.find_element_by_id('menutop')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

flask - blueprint - sqlalchemy - cannot import name 'db' into moles file

From Java

Flask Blueprint AttributeError: 'module' object has no attribute 'name' error

From Dev

Calling method from Flask Blueprint

From Java

flask blueprint template folder

From Dev

Flask blueprint: meaning of first input and output object

From Dev

How to pass arbitrary arguments to a flask blueprint?

From Dev

Pass an HTML file object from one <input type = file> to another

From Dev

Flask FileStorage object to File Object

From Dev

Flask Session not persistant in blueprint

From Dev

Overwrite route in flask blueprint

From Dev

Flask Blueprint 404

From Dev

How to pass object from one file to another in javascript?

From Dev

Pass json object to another html

From Dev

PHP how to pass `http request` object from one PHP file to another PHP file

From Dev

Flask: pass argument to another route

From Dev

Pass custom object to another fragment

From Dev

Flask Blueprint structure

From Dev

Flask AttributeError: 'Blueprint' object has no attribute 'response_class'

From Dev

Flask - Forms - Blueprint

From Dev

JS: Pass an Object containing a Function/Method Property then Passing and Invoking the Passed in Object Function/Method Property in Another File?

From Dev

How can I pass pipeline variable to parameters file for blueprint assignment

From Dev

How to pass variable to another function flask

From Dev

Flask url_for() pass multiple parameters but only show one in the blueprint route?

From Dev

How to pass request object in laravel from one file to another file?

From Dev

Is there another way to pass an object to a function?

From Dev

Flask blueprint and registering path

From Dev

Blueprint error in Flask: NameError: name of blueprint is not defined

From Dev

Inject dependencies in Flask blueprint

From Dev

Python Flask Pass Global Variable To Blueprint

Related Related

  1. 1

    flask - blueprint - sqlalchemy - cannot import name 'db' into moles file

  2. 2

    Flask Blueprint AttributeError: 'module' object has no attribute 'name' error

  3. 3

    Calling method from Flask Blueprint

  4. 4

    flask blueprint template folder

  5. 5

    Flask blueprint: meaning of first input and output object

  6. 6

    How to pass arbitrary arguments to a flask blueprint?

  7. 7

    Pass an HTML file object from one <input type = file> to another

  8. 8

    Flask FileStorage object to File Object

  9. 9

    Flask Session not persistant in blueprint

  10. 10

    Overwrite route in flask blueprint

  11. 11

    Flask Blueprint 404

  12. 12

    How to pass object from one file to another in javascript?

  13. 13

    Pass json object to another html

  14. 14

    PHP how to pass `http request` object from one PHP file to another PHP file

  15. 15

    Flask: pass argument to another route

  16. 16

    Pass custom object to another fragment

  17. 17

    Flask Blueprint structure

  18. 18

    Flask AttributeError: 'Blueprint' object has no attribute 'response_class'

  19. 19

    Flask - Forms - Blueprint

  20. 20

    JS: Pass an Object containing a Function/Method Property then Passing and Invoking the Passed in Object Function/Method Property in Another File?

  21. 21

    How can I pass pipeline variable to parameters file for blueprint assignment

  22. 22

    How to pass variable to another function flask

  23. 23

    Flask url_for() pass multiple parameters but only show one in the blueprint route?

  24. 24

    How to pass request object in laravel from one file to another file?

  25. 25

    Is there another way to pass an object to a function?

  26. 26

    Flask blueprint and registering path

  27. 27

    Blueprint error in Flask: NameError: name of blueprint is not defined

  28. 28

    Inject dependencies in Flask blueprint

  29. 29

    Python Flask Pass Global Variable To Blueprint

HotTag

Archive