V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
gseven0312
V2EX  ›  Python

用 Flask-SQLAlchemy+mysql 查询中文内容返回时报错

  •  
  •   gseven0312 · 2016-05-17 20:11:02 +08:00 · 2881 次点击
    这是一个创建于 2907 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Python3 代码:

    # -*- coding: utf-8 -*-
    from flask import Flask
    from flask.ext.sqlalchemy import SQLAlchemy
    from datetime import datetime
    import config
    import os  
    basedir = os.path.abspath(os.path.dirname(__file__))
    
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = config.DB_URI
    #mysql://root:[email protected]:3306/survey?charset=utf8
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
    db = SQLAlchemy(app,use_native_unicode='utf8')
    
    class Role(db.Model):
        __tablename__ = 'roles'
        id = db.Column(db.Integer, primary_key=True) 
        name = db.Column(db.String(64), unique=True)
    
        def __repr__(self):
            return '<Role %r>' % self.name
        
    print(config.DB_URI)     
    print(Role.query.all())
    

    mysql status:

    roles sql :

    error:

    lz 试了能搜到的办法,实在不知哪错了才问的 顺便请教各位一下 有没有好的 flask mysql python3 的 docker ?

    2 条回复    2016-05-18 10:09:03 +08:00
    haozibi
        1
    haozibi  
       2016-05-18 08:25:55 +08:00 via Android
    mysql+pymysql://xxxxxxx
    jixiangqd
        2
    jixiangqd  
       2016-05-18 10:09:03 +08:00
    怎么感觉像 python2 的阵痛。。。真的是 python3 代码?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2315 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 03:28 · PVG 11:28 · LAX 20:28 · JFK 23:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.