How to Work with Masonite — Python Rails/Laravel like Web Framework

Pre-requisites

  • Python 3.6
  • pip

Setup

  • in an empty folder run python -m venv venv to create a new virtual environment then source ./venv/bin/activate to activate it.
  • pip install masonite to install masonite
  • confirm it is installed by running craft (craft is the command we'll use to trigger all of masonites generators and tools)
  • run craft new to generate a new project in the folder you are in.
  • run craft serve to run the server which defaults to port 8000

Creating Some Routes

  • __init__ the class constructor which you can use to do things prior to methods being called, in this case it just creates a class property that holds the request so it's available to all your other methods
def show(self, view: View):
pass
def show(self):
return {"look": "I returned some json!"}

Connecting the Controller to a Route

"""Web Routes."""from masonite.routes import Get, PostROUTES = [
Get("/", "WelcomeController@show").name("welcome"),
]
"""Web Routes."""from masonite.routes import Get, PostROUTES = [
Get("/", "WelcomeController@show").name("welcome"),
Get("/first", "firstController@show").name("first"),
]

Going Deeper into Masonite

--

--

--

Alex Merced is a Developer Advocate for Dremio and host of the Web Dev 101 and Datanation Podcasts.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

5 Powerful Facts About Team Spirit in Software Companies

CodeRiders Software Development Company enjoying weekends together

Arrays vs List vs Dictionaries in Python

7 Key Points You Should Know to Become A Mobile App Developer

PE and ELF Code Caves

Python “tricks” Demystified

Nifty 1.0: Mobile Apps, Team Chat, Daily Digests & more

Moving to the cloud —  Chapter 1: The database, the images, and the wardrobe

Barcode Generator Tool : Open Source

Barcode generator tool online open source

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alex Merced Coder

Alex Merced Coder

Alex Merced is a Developer Advocate for Dremio and host of the Web Dev 101 and Datanation Podcasts.

More from Medium

Built a Web Based Machine Learning Application Using Flask & End to End Deployment With Heroku

Build a simple URL Shortener service like bitly!

URL shortener image

Top 5 Python Frameworks And Libraries | Hyperlink InfoSystem

Top 5 Python Frameworks And Libraries | Hyperlink InfoSystem

Flask: How to Create Authentication System Without Flask-Login

Flask logo