Skip to content

Instantly share code, notes, and snippets.

@Marlysson
Created November 9, 2020 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marlysson/ed857dcae62c771b67fa20091e7ea793 to your computer and use it in GitHub Desktop.
Save Marlysson/ed857dcae62c771b67fa20091e7ea793 to your computer and use it in GitHub Desktop.
How add a new Route Compile
class SearchController(Controller):
def search(self, request: Request):
return request.param("term")
"""Providers Configuration File."""
...
from app.providers.RouteProvider import RouteCompilerProvider
PROVIDERS = [
# Framework Providers
...
# Optional Framework Providers
...
# Third Party Providers
...
# Application Providers
RouteCompilerProvider, # Adding the Router Compile that we create before.
]
from masonite.provider import ServiceProvider
from masonite.routes import Route
class RouteCompilerProvider(ServiceProvider):
wsgi = False
def boot(self, route: Route):
route.compile('any', r'(.+)')
ROUTES = [
Get('/search/@term:any', "SearchController@search")
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment