Website#
- class toui.apps.Website(name=None, assets_folder=None, secret_key=None, vars_timeout=86400, gen_sid_algo=None)[source]#
Bases:
_AppA class that creates a web application from HTML files.
Examples
Creating a web app:
>>> from toui import Website >>> app = Website(__name__, secret_key="some key")
Creating a page and adding it to the app:
>>> from toui import Page >>> home_page = Page(html_str="<h1>This is the home page</h1>") >>> app.add_pages(home_page)
Running the app:
>>> if __name__ == "__main__": ... app.run(debug=True)
See also
- Parameters:
name (str (optional)) – The name of the app.
assets_folder (str (optional)) – The path to the folder that contains the HTML files and other assets.
secret_key (str (optional)) – Sets the secret_key attribute for flask.Flask. You can also set the environment variable SECRET_KEY from the command line and ToUI will get it using os.environ.
vars_timeout (int (optional)) – The timeout interval before the temporary user-specific variables are deleted from user_vars attribute. The default is 86400 seconds (1 day).
gen_sid_algo (Callable (optional)) – A callable that generates a unique user id so that ToUI can store data for each user/browser. If
None, the IP address, user agent, and secret key will be used.
- flask_app#
ToUI creates applications using Flask. You can access the Flask object using the attribute flask_app.
- Type:
Flask
- forbidden_urls#
These are URLs that ToUI does not allow the user to use because ToUI uses them.
- Type:
list
- user_vars#
A dictionary that stores temporary data unique to each user.
- Type:
dict
- page_vars#
A dictionary that stores data that is deleted when the user leaves the page.
- Type:
dict
- pages#
A list of added Page objects.
- Type:
list
- firestore#
If firebase was added using add_firebase, you can access firestore database using this attribute. Otherwise, it will be
None. See Firebase documentation and Firestore API Reference.- Type:
firebase_admin.firestore.Firestore
Behind The Scenes
ToUI uses Flask and its extenstions to create apps. When creating an instance of this class, the following extensions are used:
Sock class extension from Flask-Sock package.
Methods#
Adds Firebase to the app. |
|
Adds pages to the app. |
|
Makes the app private. |
|
Adds Firebase user database to the app. |
|
Creates a simple database that has data specific to each user. |
|
Checkout using PayPal API. |
|
Opens a Stripe checkout page. |
|
Downloads a file from the server to a client. |
|
Checks if the email is exists in the database. |
|
A method that returns the current full URL. |
|
Gets data specific to the currently signed in user from the database. |
|
Gets the ID of the currently signed in user. |
|
Downloads a file from Firebase storage. |
|
A method that returns the query parameters of the current URL. |
|
A static method that gets data sent from client using HTTP request. |
|
A static method that returns the current Page. |
|
Gets the user ids from the users data. |
|
Checks if the user is signed in. |
|
Opens another URL. |
|
Use it with Page.on_url_request to redirect the user to another page. |
|
Registers a ToUIBlueprint object. |
|
Runs the application on a local development server. |
|
Sets data specific to the currently signed in user in the database. |
|
Validates data received from JavaScript before using it. |
|
Validates a WebSocket connection before sending and accepting data. |
|
Signs in a user using Google (Experimental). |
|
Loads the data of a user from database. |
|
Loads the data of a user from database using the user's ID. |
|
A method that signs out the current user. |
|
Creates a new user in the database. |
|
Uploads a file to Firebase storage. |
|
Checks if the username is exists in the database. |