安萍
3 years ago
#flask #python
Flask-Migrate: 下 flask db downgrade 指令,遇到錯誤訊息:
if len(ident) > self.max_identifier_length:
TypeError: object of type 'NoneType' has no len()


drop_constraint etc. should check for name=None and ...
latest #37
安萍
3 years ago
有設外鍵,新增 record 時卻跟我說沒有設外鍵,不知道是我哪裡弄錯還是發生什麼事。總之先用底下 primaryjoin 的方式頂著
How do I do a join without a real foreign key constr...
立即下載
安萍
3 years ago
Flask SQLAlchemy query, specify column names用with_entities查訊,印出來的東西乍看之下是 tuple,例如:
from models import Product
products = Product.query.with_entities(http://Product.name/..., Product.price, Product.image_url).all()
print(products)

印出:[('商品 1', 27361, 'https://imgs.plurk.com/QzP/ivz/aqeDrap18M6QGWg1kVOCEQ8B7mZ_lg.jpg
但是可以用 key(?) 的方式取值:
print(products[0].price)
印出:27361
安萍
3 years ago
Flask SQLAlchemy query, specify column names用with_entities查訊,印出來的東西乍看之下是 tuple,例如:
from models import Product
products = Product.query.with_entities(Product.name, Product.price, Product.image_url).all()
print(products)

印出:[('商品 1', 27361, 'some_url')]
但是可以用 key(?) 的方式取值:
print(products[0].price)
印出:27361
安萍
3 years ago
print(type(products[0]))
印出:<class 'sqlalchemy.engine.row.Row'>
安萍
3 years ago
Flask-RESTful render_template cannot work【Flask-RESTful does not use render_template. It is designed to work with REST API calls and render JSON responses. Unless you are building a REST API, you don't need Flask-RESTful, just Flask.】
安萍
3 years ago
SQLAlchemy 的 relationship 可以排序
Configuring Relationships — SQLAlchemy 1.3 Documenta...
安萍
3 years ago
不知道哪來的錯誤訊息,繼續觀察
sqlalchemy.exc.TimeoutError: QueuePool limit of size 10 overflow 10 reached
安萍
3 years ago
修改 session,但修改的結果沒有存起來
Flask session variable not persisting between reques...【Flask uses a CallbackDict to track modifications to sessions.

It will only register modifications when you set or delete a key. Here, you modify the values in place, which it will not detect.
session.modified = True
安萍
3 years ago
取得網頁的根目錄網址
flask.request.url_root
Python Examples of flask.request.url_root
安萍
3 years ago
Application Server、WSGI Server、Web Server 之間的關係
Flask想上線? 你還需要一些酷東西
安萍
3 years ago
Flask-上傳檔案和訪問上傳的檔案 - IT閱讀
在路由裡用 return send_from_directory(UPLOAD_PATH,filename),就可以隱藏檔案的真實位置
安萍
3 years ago
那 Django 到底是怎麼用你的程式?這就要從 WSGI 開始說起
Django Tutorial for Programmers: 2. 談 Django - iT 邦幫...
back to top