python - GAE : User By Name/Regex Expressions

标签 python regex google-app-engine web-applications web

Possible Duplicate:
How to make case insensitive filter queries with Google App Engine?

目前在我的网络应用程序上,

如果我输入 www.website.com/Rohit ,它会将我带到我想要的个人资料页面。

但是如果我输入 www.website.com/rohit ,它不会带我到那里,并且会发送到 404 错误。

基本上,我的用户名存储为:Rohit

任何给定用户的个人资料页面应该是:www.website.com/username

但我希望网站不关心大写字母。

更新

我现在知道了,感谢 Martijn,我的正则表达式没问题。这是代码,我用它来检查 Google App Engine 以查看用户名是否已存在:

u = User.all().filter('username =', username).get()

^如何使其适合大写字母(大写字母没有区别?)

最佳答案

使用 filter('username =', username.lower()) 预先转换为小写。

并且您需要转换数据库,将所有用户名也更改为小写:

users = User.all().fetch(1000000)
for user in users :
    if user.username != user.username.lower() :
        user.username = user.username.lower()
        user.put()  # save back to db only if changed

您可以从交互式控制台运行此程序,使用fetch(offset,count)来调整一次运行中转化的用户数量。

关于python - GAE : User By Name/Regex Expressions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13543558/

相关文章:

python - 如何在 Golang 中运行外部 Python 脚本?

Java 字符串修复缩写中的大写

Java 7 Unicode 正则表达式 仅制表符和仅空格

django自定义标签内联或 block

google-app-engine - Google App Engine 错误 : (gcloud. app.deploy) INVALID_ARGUMENT:组合版本和服务(模块)名称太长

javascript - 谷歌客户端API使用后端服务器进行身份验证不起作用

python - 试图让我的播放器transform.flip python

python - 从 Django 连接到 MySQL

python - python : x**y vs math. pow(x, y) 中的指数

php - 使用正则表达式解析嵌套的 IF 语句