需要Django表单帮助 [英] Django Forms Help needed

查看:106
本文介绍了需要Django表单帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Im new to django,并尝试使用户注册表单,几个验证。
除此之外,我还想要一个用户名建议代码,它将告诉用户他正在尝试注册的用户名是否可用或已经在使用。那么它应该提供几个可能可供选择的建议。任何可能在同一或相同项目上工作的人都可以帮助我。

Im new to django and trying to make a user registration form with few validations. Apart from this I also want a username suggestion code which will tell the user if the username he is trying to register is available or already in use. Then it should give few suggestions that might be available to choose from. Can anyone who might have worked on the same or somewhat same project help me with this.

谢谢

推荐答案

你可以通过覆盖相应的干净的方法表单中的字段:

You can handle this by overriding the clean method of the corresponding field in the form:

def clean_username(self):
    if 'username' in self.cleaned_data:
        username = self.cleaned_data.get('username')
        #DO YOUR CHECK
        if THERE_IS_ALREADY_SUCH_USERNAME:
            err = _(u'This username already exists. Try one of the following: %(sug)s)' % SUGGESTIONS)
            raise forms.ValidationError(err)
        return username

这篇关于需要Django表单帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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