我正试图抓住 Django。我在 Eclipse 上使用 Pydev。我写了一个简单的注册页面,但我无法开始工作。Eclipse 抱怨 User.DoesNotExist 未定义。很可能,我错过了一些微不足道的东西。这是代码的相关部分:
from django.contrib.auth.models import User
...
class SignUpForm (forms.Form):
...
def clean_username (self):
try:
User.objects.get(username=self.cleaned_data['username'])
except User.DoesNotExist:
return self.cleaned_data['username']
raise forms.ValidationError(USERNAME_ALREADY_IN_USE)
...