Website#
- class toui.apps.Website(name=None, assets_folder=None, secret_key=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
- 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. The data are stored in a Cache object from flask-caching package.
- Type:
dict
- pages#
A list of added Page objects.
- Type:
list
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.
Cache class extension from Flask-Cache package.
The following Flask configurations are also set:
CACHE_TYPE = “SimpleCache”
Methods#
Adds pages to the app. |
|
Makes the app private. |
|
Creates a simple database that has data specific to each user. |
|
Downloads a file from the server to a client. |
|
A static method that returns the current user. |
|
A static method that gets data sent from client using HTTP request. |
|
A static method that returns the current Page. |
|
Opens another URL. |
|
Registers a ToUIBlueprint object. |
|
Runs the application on a local development server. |
|
Validate data received from JavaScript before using it. |
|
Validate simple_websocket.ws.Server object before sending and accepting data. |
|
Loads the data of a user from database. |
|
A static method that signs out the current user. |
|
Creates a new user in the database. |
|
Checks if the username is exists in the database. |