Masonite masonite is a web framework made by Python. Official documentation and tutorials are also available, so it's fairly easy to get started.
I used virtualenv for the Python environment.
$ sudo apt install python3-dev python3-pip libssl-dev build-essential python3-venv
$ mkdir masonite_tutorial && cd masonite_tutorial/
$ virtualenv -p python3.6 venv
$ source venv/bin/activate
Next, install masonite. You can create a masonite project with the craft new
command.
$ pip3 install masonite
$ craft new
To start the server, use the following command.
$ craft serve
If you access http: // localhost: 8000, the following screen will appear.
Since the above page is not enough, we will add a user registration / login function.
$ craft auth
Set up the database. I think there is an .env file, so edit it as follows. Don't forget to create a database in your local postgres before that!
DB_CONNECTION=postgres
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=hello_masonite_dev
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_LOG=True
Once that's done, the following command
$ craft migrate
This completes the function addition. You can register as a user from http: // localhost: 8000 / register.
If you give the code to git so far and make it a template, it may be convenient to use it in the future.
Heroku
Add Procfile
web: gunicorn -w 2 wsgi:application
Deploying to heroku was done from a command.
$ heroku git:remote -a masonite-app
$ git push heroku master
$ heroku run craft migrate
Make the following settings after deploying.
--Add postgreSQL --The url issued after adding postgreSQL is as follows, so decompose it and set it in the environment variable. - postgres://DB_USERNAME:DB_PASSWORD@DB_HOST:DB_PORT/DB_DATABASE --Environment variable settings (Refer to your env file for the value of each environment variable) - KEY - APP_DEBAG - DB_CONNECTION - DB_HOST - DB_PORT - DB_DATABASE - DB_USERNAME - DB_PASSWORD - DB_LOG
Recommended Posts