Single Page App with Flask and Vue.js

Overview

Developing a Single Page App with FastAPI and Vue.js

Want to learn how to build this?

Check out the post.

Want to use this project?

Build the images and spin up the containers:

$ docker-compose up -d --build

Apply the migrations:

$ docker-compose exec backend aerich upgrade

Ensure http://localhost:5000, http://localhost:5000/docs, and http://localhost:8080 work as expected.

Comments
  • Vue3 support

    Vue3 support

    Anybody interested in having this awesome project support Vue3? I can create a PR for that.

    And many thanks @mjhea0 for writing the great tutorial for this project 👏🏻

    opened by devmount 11
  • Wrong description with Flask

    Wrong description with Flask

    On the GitHub page, under "About" it says: "Single Page App with Flask and Vue.js". But it should be "Single Page App with FastAPI and Vue.js".

    opened by KristjanESPERANTO 1
  • exception: relation

    exception: relation "users" does not exist

    I just cloned and docker-compose up the project. The "Hello world!" works, but when I want to register or login, I get this output on FastAPI machine:

      File "/app/./src/routes/users.py", line 27, in create_user
        return await crud.create_user(user)
      File "/app/./src/crud/users.py", line 17, in create_user
        user_obj = await Users.create(**user.dict(exclude_unset=False))
      File "/usr/local/lib/python3.9/site-packages/tortoise/models.py", line 1105, in create
        await instance.save(using_db=db, force_create=True)
      File "/usr/local/lib/python3.9/site-packages/tortoise/models.py", line 926, in save
        await executor.execute_insert(self)
      File "/usr/local/lib/python3.9/site-packages/tortoise/backends/base/executor.py", line 203, in execute_insert
        insert_result = await self.db.execute_insert(self.insert_query, values)
      File "/usr/local/lib/python3.9/site-packages/tortoise/backends/asyncpg/client.py", line 38, in translate_exceptions_
        raise OperationalError(exc)
    tortoise.exceptions.OperationalError: relation "users" does not exist
    
    opened by sohail-bakhtiari 1
  • Tortoise fails to connect to database

    Tortoise fails to connect to database

    @mjhea0 Tried to fix this by refering to multiple resources. Can you please look into it?

    1. Cloned the repo,
    2. Build the images and spin up the containers, using: $ docker-compose up -d --build
    3. Applying migrations it failed to connect with database with below traceback: $ docker-compose exec backend aerich upgrade
    Traceback (most recent call last):
      File "/usr/local/bin/aerich", line 8, in <module>
        sys.exit(main())
      File "/usr/local/lib/python3.9/site-packages/aerich/cli.py", line 321, in main
        cli()
      File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
        return self.main(*args, **kwargs)
      File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1053, in main
        rv = self.invoke(ctx)
      File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1656, in invoke
        super().invoke(ctx)
      File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "/usr/local/lib/python3.9/site-packages/click/core.py", line 754, in invoke
        return __callback(*args, **kwargs)
      File "/usr/local/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
        return f(get_current_context(), *args, **kwargs)
      File "/usr/local/lib/python3.9/site-packages/aerich/cli.py", line 45, in wrapper
        loop.run_until_complete(f(*args, **kwargs))
      File "/usr/local/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
        return future.result()
      File "/usr/local/lib/python3.9/site-packages/aerich/cli.py", line 95, in cli
        await Migrate.init(tortoise_config, app, location)
      File "/usr/local/lib/python3.9/site-packages/aerich/migrate.py", line 66, in init
        await Tortoise.init(config=config)
      File "/usr/local/lib/python3.9/site-packages/tortoise/__init__.py", line 600, in init
        await cls._init_connections(connections_config, _create_db)
      File "/usr/local/lib/python3.9/site-packages/tortoise/__init__.py", line 392, in _init_connections
        await connection.create_connection(with_db=True)
      File "/usr/local/lib/python3.9/site-packages/tortoise/backends/asyncpg/client.py", line 106, in create_connection
        raise DBConnectionError(f"Can't establish connection to database {self.database}")
    tortoise.exceptions.DBConnectionError: Can't establish connection to database hello_fastapi_dev
    

    Detailed traceback:

    Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/tortoise/backends/asyncpg/client.py", line 103, in create_connection self._pool = await asyncpg.create_pool(None, password=self.password, **self._template) File "/usr/local/lib/python3.9/site-packages/asyncpg/pool.py", line 407, in _async__init__ await self._initialize() File "/usr/local/lib/python3.9/site-packages/asyncpg/pool.py", line 435, in _initialize await first_ch.connect() File "/usr/local/lib/python3.9/site-packages/asyncpg/pool.py", line 127, in connect self._con = await self._pool._get_new_connection() File "/usr/local/lib/python3.9/site-packages/asyncpg/pool.py", line 477, in _get_new_connection con = await connection.connect( File "/usr/local/lib/python3.9/site-packages/asyncpg/connection.py", line 1981, in connect return await connect_utils._connect( File "/usr/local/lib/python3.9/site-packages/asyncpg/connect_utils.py", line 732, in _connect con = await _connect_addr( File "/usr/local/lib/python3.9/site-packages/asyncpg/connect_utils.py", line 632, in _connect_addr return await __connect_addr(params, timeout, True, *args) File "/usr/local/lib/python3.9/site-packages/asyncpg/connect_utils.py", line 682, in __connect_addr await compat.wait_for(connected, timeout=timeout) File "/usr/local/lib/python3.9/site-packages/asyncpg/compat.py", line 103, in wait_for return await asyncio.wait_for(fut, timeout) File "/usr/local/lib/python3.9/asyncio/tasks.py", line 479, in wait_for return fut.result() asyncpg.exceptions.InvalidCatalogNameError: database "hello_fastapi_dev" does not exist

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "/usr/local/bin/aerich", line 8, in sys.exit(main()) File "/usr/local/lib/python3.9/site-packages/aerich/cli.py", line 321, in main cli() File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1128, in call return self.main(*args, **kwargs) File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1053, in main rv = self.invoke(ctx) File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1656, in invoke super().invoke(ctx) File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1395, in invoke return ctx.invoke(self.callback, **ctx.params) File "/usr/local/lib/python3.9/site-packages/click/core.py", line 754, in invoke return __callback(*args, **kwargs) File "/usr/local/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func return f(get_current_context(), *args, **kwargs) File "/usr/local/lib/python3.9/site-packages/aerich/cli.py", line 45, in wrapper loop.run_until_complete(f(*args, **kwargs)) File "/usr/local/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/usr/local/lib/python3.9/site-packages/aerich/cli.py", line 95, in cli await Migrate.init(tortoise_config, app, location) File "/usr/local/lib/python3.9/site-packages/aerich/migrate.py", line 66, in init await Tortoise.init(config=config) File "/usr/local/lib/python3.9/site-packages/tortoise/init.py", line 600, in init await cls._init_connections(connections_config, _create_db) File "/usr/local/lib/python3.9/site-packages/tortoise/init.py", line 392, in _init_connections await connection.create_connection(with_db=True) File "/usr/local/lib/python3.9/site-packages/tortoise/backends/asyncpg/client.py", line 106, in create_connection raise DBConnectionError(f"Can't establish connection to database {self.database}") tortoise.exceptions.DBConnectionError: Can't establish connection to database hello_fastapi_dev

    opened by nipunsadvilkar 1
  • Notes class in Database models refers to an invalid attribute

    Notes class in Database models refers to an invalid attribute

    https://github.com/testdrivenio/fastapi-vue/blob/master/services/backend/src/database/models.py#L22

    Currently: return f"{self.title}, {self.author_id} on {self.created_at}"

    However, the attribute author_id does not exist.

    Perhaps it should be this instead?

    return f"{self.title}, {self.author}, {self.id} on {self.created_at}"

    opened by kmcquade 1
  • chore: bump dependancies

    chore: bump dependancies

    • Bump python reqs version
    • Remove deprecated vuex-persistedstate
    • Upgrade Vue 2 to Vue 3
    • Replace aerich.ini with pyproject.toml
    • Update npm libs versions
    opened by amirtds 0
  • Vue3

    Vue3

    This change adds support for Vue.js v3 and upgrades all other dependencies to their latest version as well. Some things to note:

    • I didn't changed any styling or appearance. Should look exactly the same as before.
    • I kept the options API of Vue for convenience. But if this PR is merged, shouldn't be a problem to convert to Composition API if needed
    • I tested the frontend on my site and it works. For some reasons I wasn't able to test together with the FastAPI backend. So when reviewing this PR, please test the frontend AND the backend thoroughly
    • The package babel-eslint is now @babel/eslint-parser
    • The package vuex-persistedstate isn't maintained anymore, so I removed it without replacement. If you want its functionality, please implement an alternative.
    • The package vue-template-compiler isn't needed anymore with Vue3.

    So I hope this is useful for all who find this project as helpful as me.

    Implements #3

    opened by devmount 0
  • cant see notes

    cant see notes

    I followed the tutorial and reviewed it: https://testdriven.io/blog/developing-a-single-page-app-with-fastapi-and-vuejs/ found some typo in the router in index.js. its missing in the guide.

      {
        path: '/editnote/:id',
        name: 'EditNote',
        component: EditNote,
        meta: {requiresAuth: true},
        props: true,
      }
    

    but it still doesnt fix for me, still cant see notes. but if I clone the repo and start it, I can see the notes.

    one thing to make git clone work is editing the services/frontend/Dockerfile: FROM node:16-alpine maybe it help someone

    opened by samuk10 0
  • Backend not running unless rerunning docker-compose

    Backend not running unless rerunning docker-compose

    Hi, many thanks for the hard work and the post associated! It helped me a lot learn about those frameworks :)

    However, from a complete fresh start (aka, the first time I build the whole app), it seems I need to run the docker-compose up -d --build twice to get the uvicorn server up. If I only run the docker-compose command once only the frontend is responding to localhost. But when I run the docker-compose a second time, I can get the backend on the port 5000.

    I find this weird, considering I tried to connect to the backend container after the first docker-compose command and check if uvicorn was running with the top command in the detached terminal, and I indeed found a uvicorn process running, but the server was not responding on port 5000 until I rerun the docker-compose command.

    Any idea why? Is it an issue from my side? Don't know why would it be but still asking..

    Thanks!

    opened by julianlegouic 0
  • Bieli fix logout frontend

    Bieli fix logout frontend

    Without change state isLoggedIn=false we can see and have access to all NavBar options (like Dashboard, Profile). This patch disable access to Dashboard and Profile after click logOut on frontend.

    opened by bieli 0
  • Moving the model init to register.py

    Moving the model init to register.py

    This will initialize the model relationships with register.py and fix the issue below. This will cleanup main.py

    Issue referenced: https://stackoverflow.com/questions/65531387/tortoise-orm-for-python-no-returns-relations-of-entities-pyndantic-fastapi

    opened by nvpnathan 0
Owner
null
Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for your application.

Flask-Bcrypt Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for your application. Due to the recent increased prevelance of

Max Countryman 310 Dec 14, 2022
Flask-vs-FastAPI - Understanding Flask vs FastAPI Web Framework. A comparison of two different RestAPI frameworks.

Flask-vs-FastAPI Understanding Flask vs FastAPI Web Framework. A comparison of two different RestAPI frameworks. IntroductionIn Flask is a popular mic

Mithlesh Navlakhe 1 Jan 1, 2022
Sample-fastapi - A sample app using Fastapi that you can deploy on App Platform

Getting Started We provide a sample app using Fastapi that you can deploy on App

Erhan BÜTE 2 Jan 17, 2022
Cache-house - Caching tool for python, working with Redis single instance and Redis cluster mode

Caching tool for python, working with Redis single instance and Redis cluster mo

Tural 14 Jan 6, 2022
Qwerkey is a social media platform for connecting and learning more about mechanical keyboards built on React and Redux in the frontend and Flask in the backend on top of a PostgreSQL database.

Flask React Project This is the backend for the Flask React project. Getting started Clone this repository (only this branch) git clone https://github

Peter Mai 22 Dec 20, 2022
Restful Api developed with Flask using Prometheus and Grafana for monitoring and containerization with Docker :rocket:

Hephaestus ?? In Greek mythology, Hephaestus was either the son of Zeus and Hera or he was Hera's parthenogenous child. ... As a smithing god, Hephaes

Yasser Tahiri 16 Oct 7, 2022
Mixer -- Is a fixtures replacement. Supported Django, Flask, SqlAlchemy and custom python objects.

The Mixer is a helper to generate instances of Django or SQLAlchemy models. It's useful for testing and fixture replacement. Fast and convenient test-

Kirill Klenov 871 Dec 25, 2022
Formatting of dates and times in Flask templates using moment.js.

Flask-Moment This extension enhances Jinja2 templates with formatting of dates and times using moment.js. Quick Start Step 1: Initialize the extension

Miguel Grinberg 358 Nov 28, 2022
Beyonic API Python official client library simplified examples using Flask, Django and Fast API.

Beyonic API Python Examples. The beyonic APIs Doc Reference: https://apidocs.beyonic.com/ To start using the Beyonic API Python API, you need to start

Harun Mbaabu Mwenda 46 Sep 1, 2022
Flask + marshmallow for beautiful APIs

Flask-Marshmallow Flask + marshmallow for beautiful APIs Flask-Marshmallow is a thin integration layer for Flask (a Python web framework) and marshmal

marshmallow-code 768 Dec 22, 2022
A basic JSON-RPC implementation for your Flask-powered sites

Flask JSON-RPC A basic JSON-RPC implementation for your Flask-powered sites. Some reasons you might want to use: Simple, powerful, flexible and python

Cenobit Technologies 273 Dec 1, 2022
A Flask extension that enables or disables features based on configuration.

Flask FeatureFlags This is a Flask extension that adds feature flagging to your applications. This lets you turn parts of your site on or off based on

Rachel Greenfield 131 Sep 26, 2022
Regex Converter for Flask URL Routes

Flask-Reggie Enable Regex Routes within Flask Installation pip install flask-reggie Configuration To enable regex routes within your application from

Rhys Elsmore 48 Mar 7, 2022
Socket.IO integration for Flask applications.

Flask-SocketIO Socket.IO integration for Flask applications. Installation You can install this package as usual with pip: pip install flask-socketio

Miguel Grinberg 4.9k Jan 3, 2023
Pagination support for flask

flask-paginate Pagination support for flask framework (study from will_paginate). It supports several css frameworks. It requires Python2.6+ as string

Lix Xu 264 Nov 7, 2022
Adds GraphQL support to your Flask application.

Flask-GraphQL Adds GraphQL support to your Flask application. Usage Just use the GraphQLView view from flask_graphql from flask import Flask from flas

GraphQL Python 1.3k Dec 31, 2022
flask extension for integration with the awesome pydantic package

flask extension for integration with the awesome pydantic package

null 249 Jan 6, 2023
A minimal Streamlit app showing how to launch and stop a FastAPI process on demand

Simple Streamlit + FastAPI Integration A minimal Streamlit app showing how to launch and stop a FastAPI process on demand. The FastAPI /run route simu

Arvindra 18 Jan 2, 2023
This code generator creates FastAPI app from an openapi file.

fastapi-code-generator This code generator creates FastAPI app from an openapi file. This project is an experimental phase. fastapi-code-generator use

Koudai Aono 632 Jan 5, 2023