app-generator / docs

App Generator - The Official Documentation | AppSeed
https://docs.appseed.us
1 stars 1 forks source link

Flask Rocket (free) - Full DOCS #102

Open app-generator opened 1 month ago

app-generator commented 1 month ago
Rocket Icon

Rocket Flask

Flask TailwindCSS / FlowbiteAPICeleryChartsDockerCI/CD

Demo   •   Support   •   PRO Version (soon)


Flask Rocket - Open-source Starter styled with Tailwind and Flowbite.


Why Rocket Flask

Supercharge your app instantly, launch faster, make $

Login users, process payments and send emails at lightspeed. Spend your time building your startup, not integrating APIs. Rocket Flask provides you with the boilerplate code you need to launch, FAST.

Rocket your startup in days, not weeks

The Django boilerplate with all you need to build your SaaS, AI tool, or any other web app. From idea to production in 5 minutes.

48+ hours of headaches


Start With Docker

Download code

$ git clone https://github.com/app-generator/rocket-flask.git
$ cd rocket-flask

Start with Docker Compose

$ docker-compose up --build 

Visit the app in the browser localhost:5085.


Manual Build

Install modules via VENV

$ virtualenv env
$ source env/bin/activate
$ pip install -r requirements.txt

Install Tailwind (another terminal)

$ cd static
$ yarn  
$ npx tailwindcss -i ./src/input.css -o ./dist/css/output.css --watch           

Start APP

$ flask run 


Start Celery (async task)

$ export DJANGO_SETTINGS_MODULE="core.settings"  
$ celery -A apps.tasks worker -l info -B


How to switch to PostgreSQL

step :1 Install the necessary packages

Make sure you have the required packages installed. You need Flask, Flask-SQLAlchemy, and psycopg2 for working with PostgreSQL. You can install them using pip:

pip install Flask Flask-SQLAlchemy psycopg2

Step 2: Configure your Flask app

In your Flask app, you need to update the database configuration to use PostgreSQL. Open your main Flask application file (e.g., app.py) and add the following code:

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://username:password@localhost/mydatabase'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False  # Optional, but recommended to suppress SQLAlchemy warnings
db = SQLAlchemy(app)

Replace 'username' and 'password' with your PostgreSQL username and password, and 'mydatabase' with the name of your PostgreSQL database.

Step 3: Define your database models

In your Flask project, you likely have database models defined using SQLAlchemy. Open the file where your models are defined (e.g., models.py). Update the import statement to use SQLAlchemy from flask_sqlalchemy:

from app import db

You can then define your models as usual using the SQLAlchemy syntax. Make sure to update any PostgreSQL-specific data types or features if necessary.

Step 4: Migrate the database

If you already have existing data and database tables, you need to perform a database migration to update the schema to match the new PostgreSQL configuration.

To use Flask-Migrate for database migrations, you need to create a migration repository. Open your terminal in the project directory and run the following commands:

flask db init

This will create a migrations folder in your project.

Next, generate an initial migration script:

flask db migrate -m "Initial migration"

This will generate a migration script based on your current models.

Finally, apply the migration to the database:

flask db upgrade

This will create the necessary tables in your PostgreSQL database.

Step 5: Run your Flask app

After completing the above steps, you can run your Flask app to start using PostgreSQL as the database. Make sure you have a PostgreSQL server running and accessible with the provided credentials.

In your terminal, run the following command:

flask run

Your Flask app will now use PostgreSQL as the database.

Add a new app/blueprint

To add a new app or blueprint in Flask, you can follow these steps:

  1. Create a new Python file for your app or blueprint. You can name it something like my_app.py or my_blueprint.py.

  2. Import the necessary modules and create an instance of the Flask application. For example:

from flask import Flask

app = Flask(__name__)
  1. Define the routes and views for your app or blueprint. You can use the @app.route decorator to specify the URL route for each view. Here's an example:
@app.route('/')
def home():
    return 'Welcome to my app!'

You can add more routes and views as needed.

  1. If you're creating a blueprint, you need to register it with the Flask application. For example:
from flask import Blueprint

my_blueprint = Blueprint('my_blueprint', __name__)

@my_blueprint.route('/')
def home():
    return 'Welcome to my blueprint!'

app.register_blueprint(my_blueprint)

Make sure to replace 'my_blueprint' with an appropriate name for your blueprint.

  1. Save the file and run your Flask application. You can typically run it using the flask run command in the terminal, assuming you have Flask installed and your environment is properly set up.
flask run

Flask will start the development server, and you should be able to access your app or blueprint at the specified route, such as http://localhost:5000/.


Deploy on Render

At this point, the product should be LIVE.


License

@MIT



Rocket Flask - Open-source starter styled with Tailwind/Flowbite actively suported by AppSeed.