Introduction
Quite some time ago I started attempting to learn python and web development. I claim in no way to be even close to an expert on either one of those things, in fact I am truly a beginner at both. While I never continued with python I have always enjoyed web development, creating quite a few small R Shiny apps along the way. As I have decided to learn Julia I am instantly drawn to Web Development, and I decided to try out the Genie Framework. While there exist some tutorials on the web, I find the all contain small pieces of information but lack putting everything together. Form my learning python days, I know that there exists a WONDERFUL tutorial for the python Flask framework (Found Here). I decided to challenge myself and recreate his website using Genie, and the Model, View, Controller model. I will attempt to document what I do to try and help others along the way. As stated above I AM NOT AN EXPERT, so at any time there is a good chance I am not doing something the best way possible! I encourage everyone to follow along and make suggestions for improvements. I am going to try my best to go in the order Miguel did, but for some chapters I will skip sections or combine things as needed to make them work for the framework.
Getting Started
Miguel’s blog does a great job of going into installing python and flask as well as setting up virtual environments in python. I am going to skip most of this as there is great documentation out there on how to install Julia and set up a project (Genie will actually take care of this for us). Instead I will link here what I would say are the three prerequisites for getting started.
- Download and install Julia
- The IDE of your choice (I use VSCode, and the Julia Extension)
- Add Genie to your Julia environment (see below)
To add Genie to your Julia environment, open the Julia REPL and type the following:
> add Genie # press ] from julia> prompt to enter Pkg mode pkg
Creating The App
Genie will take care of creating a new directory for us, but we will want to open the Julia REPL from whatever directory we want the app folder to live in. Once that has been decided open a Julia REPL and type the following:
> using Genie
julia
> Genie.Generator.newapp("Microblog") julia
Upon executing the command, Genie will:
- make a new dir called
Microblog
andcd()
into it, - install all the app’s dependencies
- create a new Julia project (adding the Project.toml and Manifest.toml files),
- activate the project,
- automatically load the new app’s environment into the REPL,
- start the web server on the default Genie port (port 8000) and host (127.0.0.1 – aka
localhost
).
At this point you can confirm that everything worked as expected by visiting http://127.0.0.1:8000 in your favorite web browser. You should see Genie’s welcome page. If at any point you want to exit the REPL and reload the app perform the following:
> using Genie
julia
> Genie.loadapp()
julia
> up() julia
This will reload the app and activate the web server. You can again visit http://127.0.0.1:8000 to test that everything is working.
Creating a Hello World Genie App
While Genie by default has a welcome page, lets change it to a simple Hello World page to make the app our own. Open routes.jl and change the “/” route to the following:
routes.jl
route("/") do
"Hello World!"
end
If we go to http://127.0.0.1:8000 we should now see the following:
Reuse
Citation
@online{belanger2024,
author = {Belanger, Kyle},
title = {GenieFramework {Microblog} {Part} 1},
date = {2024-08-27},
langid = {en}
}