You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using a decorator to bind URLs to view functions the canonical way to route URLs in flask. This patch implements the same for nereid and this issue will be used as a reference to why this change is done and the implementation detail.
New design
It is now possible to use a route decorator to bind your URLs to view functions. Example below::
Methods need to be decorated again if they are implemented in subclasses (mostly in downstream modules). This is easier to explain with an example.
If the code in the above example was from nereid_catalog module and the nereid_webshop module implements this method to make a change in the behavior, then the decorator needs to be applied again.
Example code:
# File: nereid_webshop/product.pyclassProduct:
__name__='product.product'@classmethod@route('/product/<uri>')defrender_product(cls, uri):
# Do something here# may be call the super function to get the response# return the final resultreturnrender_template('...')
Before
Nereid, until version 3.0.7.0 used xml records which created the rules in the database to bind URLs to view functions which were methods in tryton models. This was required because the URLs (and view functions) change depending on the database (more precisely the modules installed in the database). Since XML records in a module are only created in the database when a module is installed for the specific database, it was an easy way to bind URLs to the corresponding views. However, the approach had its flaws:
URL creation was more complicated than it should have been (define XML, upgrade DB and so on).
Non flaskish - URL routing with decorators is indeed considered a major feature of Flask and nereid should not miss out on it.
The text was updated successfully, but these errors were encountered:
Using a decorator to bind URLs to view functions the canonical way to route URLs in flask. This patch implements the same for nereid and this issue will be used as a reference to why this change is done and the implementation detail.
New design
It is now possible to use a
route
decorator to bind your URLs to view functions. Example below::Caveats
Methods need to be decorated again if they are implemented in subclasses (mostly in downstream modules). This is easier to explain with an example.
If the code in the above example was from
nereid_catalog
module and thenereid_webshop
module implements this method to make a change in the behavior, then the decorator needs to be applied again.Example code:
Before
Nereid, until version 3.0.7.0 used xml records which created the rules in the database to bind URLs to view functions which were methods in tryton models. This was required because the URLs (and view functions) change depending on the database (more precisely the modules installed in the database). Since XML records in a module are only created in the database when a module is installed for the specific database, it was an easy way to bind URLs to the corresponding views. However, the approach had its flaws:
The text was updated successfully, but these errors were encountered: