Getting Started
Installation
You can install JsWeb using pip:
pip install jsweb
To create a new project using the CLI:
jsweb new my_project
cd my_project
jsweb db prepare -m "Initial migration"
jsweb db upgrade
jsweb run
Project Structure
When you create a new project, JsWeb generates a standard project structure to get you started.
my_project/
├── app.py
├── config.py
├── models.py
├── views.py
├── forms.py
├── static/
└── templates/
Configuration
The config.py
file holds your application's configuration. You can override these settings using environment variables prefixed with JSWEB_
.
# config.py
import os
APP_NAME = "Demo-app"
DEBUG = True
SECRET_KEY = "YOUR_GENERATED_SECRET_KEY"
DATABASE_URL = f"sqlite:///{os.path.join(os.path.abspath(os.path.dirname(__file__)), 'jsweb.db')}"
# ... and other settings
Your First Application
The app.py
file is the heart of your application, where you initialize the JsWebApp
and register routes.
# app.py
from jsweb.app import JsWebApp
import config
app = JsWebApp(config=config)
# Import and register views
from views import home_bp
app.register_blueprint(home_bp)
Running the Development Server
You can run the development server using the JsWeb CLI:
jsweb run --reload
The --reload
flag enables auto-reloading, so the server will restart automatically when you make changes to your code.