使用flask和sqlalchemy在Web开发项目中使用或不使用unicode [英] To use unicode or not in web development project using flask and sqlalchemy

查看:73
本文介绍了使用flask和sqlalchemy在Web开发项目中使用或不使用unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用flask和sqlalchemy orm进行Web开发项目.我的帖子与开发此应用程序时使用unicode有关. 到目前为止,我对unicode的了解:

I am working on a web development project using flask and sqlalchemy orm. My post is related to use of unicode in developing this app. What I have understood till now about unicode :

  1. 如果我想让我的Web应用程序以英语以外的其他语言处理数据,则需要对变量使用unicode数据类型.因为字符串变量不能处理unicode数据.

  1. If I want my webapp to handle data in languages other than English I need to use unicode data type for my variables. Because string variables can't handle unicode data.

我使用一些存储unicode数据的数据库,或者负责在保存时将unicode转换为原始,反之亦然. Sqlalchemy为我提供了两种方法来设置自动转换的选项,这样我就不必担心它们.

I use some database which stores unicode data or take responsibility to convert unicode to raw while saving and vice versa while retrieving. Sqlalchemy gives me option to set automatic conversion both ways, so that I dont have to worry about them.

我正在使用python2.7,因此我必须意识到正确处理unicode数据的情况. unicode数据上的正常字符串操作可能有问题.

I am using python2.7 so I have to be aware of processing unicode data properly. Normal string operations on unicode data maybe buggy.

如果以上任何假设有误,请纠正我.

Correct me if any of the above assumption is wrong.

现在我的疑问或疑问:

  1. 如果我现在不使用unicode,那么如果我或flask人们决定移植到python3,我会遇到一些问题吗?

  1. If I dont use unicodes now then will I have some problems if I or flask people decide to port to python3?

我现在不想因为自己的Webapp迎合不同语言而烦恼.我只想专注于首先创建应用程序.我可以稍后再做而无需立即使用unicode吗?

I dont want to hassle with the thought of my webapp catering to different languages right now. I just want to concentrate on first creating the app. Can I do that later without using unicode right now?

如果我现在使用unicode,那么它如何影响我的代码.是否用unicode替换每个字符串输入和输出或什么?

If I use unicode now then how it affects my code. Do I replace every string input and output with unicode or what?

保存到数据库时对Unicode的转换,这会导致性能问题吗?

Conversion of unicode when saving to database, Can it be source of performance problems?

基本上,我是在询问我是否需要使用unicode并在项目外解释我的需求和要求.

Basically I am asking whether to use unicode or not with explaining my needs and requirement out of the project.

推荐答案

  1. 否,但是请确保将二进制数据与文本数据分开.这样可以更轻松地移植.

  1. No, but make sure you separate binary data from text data. That makes it easier to port.

从一开始就更容易使用Unicode,但是您当然可以将其推迟.但这真的不是很困难.

It's easier to use Unicode from the start, but of course you can postpone it. But it's really not very difficult.

您应该用Unicode替换所有应为文本数据的内容.

You replace everything that should be text data with Unicode, yes.

只有你们中的很多人会进行大量文本的转换.

Only of you make loads of conversions of really massive amounts of text.

这篇关于使用flask和sqlalchemy在Web开发项目中使用或不使用unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆