I use this code from https://wtforms-alchemy.readthedocs.io/en/latest/introduction.html
import sqlalchemy as sa
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from wtforms_alchemy import ModelForm
engine = create_engine('sqlite:///:memory:')
Base = declarative_base(engine)
Session = sessionmaker(bind=engine)
session = Session()
class User(Base):
__tablename__ = 'user'
id = sa.Column(sa.BigInteger, autoincrement=True, primary_key=True)
name = sa.Column(sa.Unicode(100), nullable=False)
email = sa.Column(sa.Unicode(255), nullable=False)
class UserForm(ModelForm):
class Meta:
model = User
poetry show -l
blinker 1.9.0 1.9.0 Fast, simple object-to-object and broadcast signaling
bootstrap-flask 2.5.0 2.5.0 Bootstrap 4 & 5 helper for your Flask projects.
click 8.3.1 8.3.1 Composable command line interface toolkit
flask 3.1.2 3.1.2 A simple framework for building complex web applications.
flask-sqlalchemy 3.1.1 3.1.1 Add SQLAlchemy support to your Flask application.
flask-wtf 1.2.2 1.2.2 Form rendering, validation, and CSRF protection for Flask with WTForms.
greenlet 3.2.4 3.2.4 Lightweight in-process concurrent programming
infinity 1.5 1.5 All-in-one infinity value for Python. Can be compared to any object.
intervals 0.9.2 0.9.2 Python tools for handling intervals (ranges of comparable objects).
itsdangerous 2.2.0 2.2.0 Safely pass data to untrusted environments and back.
jinja2 3.1.6 3.1.6 A very fast and expressive template engine.
markupsafe 3.0.3 3.0.3 Safely add untrusted strings to HTML/XML markup.
sqlalchemy 2.0.44 2.0.44 Database Abstraction Library
sqlalchemy-utils 0.42.0 0.42.0 Various utility functions for SQLAlchemy.
typing-extensions 4.15.0 4.15.0 Backported and Experimental Type Hints for Python 3.9+
validators 0.35.0 0.35.0 Python Data Validation for Humans™
werkzeug 3.1.3 3.1.4 The comprehensive WSGI web application library.
wtforms 3.2.1 3.2.1 Form validation and rendering for Python web development.
wtforms-alchemy 0.19.1 0.19.1 Generates WTForms forms from SQLAlchemy models.
wtforms-components 0.11.0 0.11.0 Additional fields, validators and widgets for WTForms.
poetry run python .../test.py
gives me:
...test.py:8: MovedIn20Warning: The ``declarative_base()`` function is now available as sqlalchemy.orm.declarative_base(). (deprecated since: 2.0) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
Base = declarative_base(engine)
__init__.py", line 27, in declarative_base
return _declarative_base(*arg, **kw)
TypeError: declarative_base() takes 0 positional arguments but 1 was given
I tried different variants and examples from https://docs.sqlalchemy.org/en/20/errors.html#error-b8d9, but I could not get it up and running. A complete (up-to-date) would be nice to have.
Thanks in advance!
I use this code from https://wtforms-alchemy.readthedocs.io/en/latest/introduction.html
I tried different variants and examples from https://docs.sqlalchemy.org/en/20/errors.html#error-b8d9, but I could not get it up and running. A complete (up-to-date) would be nice to have.
Thanks in advance!