django.contrib.humanize 提供一些个性化的模板过滤器
——————————————————————————————
用户名称后台验证,正则表达式验证:
alphanumeric = RegexValidator(r'^[0-9a-zA-Z\_]*$', 'Only alphanumeric characters and underscore are allowed.')
try:
alphanumeric(username)
except:
messages.add_message(request, messages.WARNING,_('username can only contain letters digits and underscore'))
return HttpResponseRedirect(reverse('reg'))