0
請幫助解決錯誤如何從數據庫中檢索的用戶名?
我添加到站點和訪問授權系統的用戶配置文件。每個用戶都有更改登錄的能力。爲此,他必須在以下表格輸入登錄並點擊提交:
from django import forms
from userprofile.models import UserProfile
from django.contrib.auth.models import User
from django.conf import settings
import os
class UserProfileForm (forms.ModelForm):
class Meta:
model = UserProfile
fields = ('family', 'name', 'nation', 'status', 'login', 'nation_show')
def clean_family (self):
family = self.cleaned_data ['family']
letters_quantity = len (family)
if letters_quantity < 4 :
raise forms.ValidationError (" little beech in the name! ")
return family
def clean_login (self):
login = self.cleaned_data ['login']. strip()
if login! ='':
login_form_db = User.objects.filter (username = 'qwe')
if login_form_db:
login_form_db = login_form_db.username
if login == login_form_db:
raise forms.ValidationError (" this username is busy ")
else:
User.username = login
User.save (self)
return login
但最終我得到以下信息的錯誤:
AttributeError at/userprofile/
'QuerySet' object has no attribute 'username'
Request Method: POST
Request URL: http://127.0.0.1:8000/userprofile/
Django Version: 1.6.2
Exception Type: AttributeError
Exception Value:
'QuerySet' object has no attribute 'username'
Exception Location: c: \ Python33 \ django_projects \ mutants \ userprofile \ forms.py in clean_login, line 26