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/