1 of 12

App with Flask and Vue

Eva Martin del Pico

PyDay BCN 2022

2 of 12

Links

3 of 12

Components of a web application

Back End

Database

Server

API

Internet communication

Front End / Client

File System

4 of 12

Components of a web application

Back End

Database

Server

API

Internet communication

Front End / Client

5 of 12

Our app 🤓

App to store code snippets.

6 of 12

Our app 🤓

App to store code snippets.

7 of 12

The Database

{

"_id" : "63817ec05082489ee2f502b8",

"title" : "Execute a program from Python",

"description" : "To call an external command within Python as if I'd typed it in a shell or command prompt, use the subprocess module in the standard library.",

"body" : "import subprocess\nsubprocess.run([\"ls\", \"-l\"])\n",

"source" : [

"https://stackoverflow.com/a/89243"

],

"tags" : [

"Python",

"cmd"

],

"type" : "Code"

}

For simplicity, we will use a dockerized database ready to use.

Instructions in repository

JSON

  • NoSQL → schema-free

  • Document-based →

Collections are a bunch of documents (JSONs)

8 of 12

The API - REST

We need a GET endpoint to retrieve snippets and a POST endpoint to add new snippets

[GET] /snippet

[POST] /snippet

9 of 12

The API - REST

  • Setting up the app
  • Routes
  • Responses
  • CORS

10 of 12

The FrontEnd - Vue (Nuxt/Vuex)

Components

Lifecycle hooks

11 of 12

The FrontEnd - Vue (Nuxt/Vuex)

Vuex Store 💚

  • Accessible across components
  • Ensures consistent variables and reactivity

12 of 12

The FrontEnd - Vue (Nuxt/Vuex)

  • Install Nuxt: https://nuxtjs.org/docs/get-started/installation/
  • Setting up the app
  • Directories and files
  • Components
  • Model, data and lifecycle.
  • Store: Dynamic Client-Side