あなたの助けが必要です。問題: 新しいユーザーを作成するためのテンプレート、ビュー、およびフォームがあり、登録で同じエラー (例: password1 != password2) を行うと、テンプレートにエラーが表示されるはずですが、そうではありません。SOS!
ビュー:
def registration(request):
if request.method == "POST" :
form = UserCreationForm(request.POST, request.FILES)
if form.is_valid():
print "form is valid"
form.save()
return render_to_response("action_succes.html")
else:
print form.is_valid()
print form.errors
form = UserCreationForm(request.POST)
else:
form = UserCreationForm()
args = {}
args.update(csrf(request))
form = UserCreationForm()
#args["form"] = UserCreationForm()
#return render_to_response("registration.html", args)
return render(request, "registration.html", {'form':form})
モデル:
class User(AbstractBaseUser):
email = models.EmailField(
verbose_name='Email address',
max_length=45,
unique=True,
db_index=True,
)
username = models.TextField(verbose_name='Nick', max_length=15, unique=True)
profession = models.TextField(verbose_name='Profession', max_length=15)
avatar = models.FileField(upload_to=get_upload_file_name, blank=True, null=True)
profile_vkontakte = models.TextField(verbose_name='Profile in vkontakte', max_length=10, null=True)
coordinate_x = models.FloatField(verbose_name='X', null=True)
coordinate_y = models.FloatField(verbose_name='Y', null=True)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
objects = UserManager()
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email']
def get_full_name(self):
return '%s %s' % (self.first_name, self.last_name,)
def get_short_name(self):
return self.username
def __unicode__(self):
return self.email
def has_perm(self, perm, obj=None):
return True
def has_module_perms(self, app_label):
return True
@property
def is_staff(self):
return self.is_admin
テンプレート:
<form action="registration" method="POST" enctype="multipart/form-data">{%csrf_token%}
<label for="id_email">Email</label><br>
{{form.email}}<br>
<label for="id_username">Username</label><br>
{{form.username}}<br>
<label for="id_profession">Profession</label><br>
{{form.profession}}<br>
<label for="id_avatar">Avatar</label><br>
{{form.avatar}}<br>
<label for="id_password1">Password</label><br>
{{form.password1}}<br>
<label for="id_password2">Password (confirm)</label><br>
{{form.password2}}<br>
<label for="id_profile_vkontakte">Vkontakte ID: </label><br>
{{ form.profile_vkontakte }}<br>
<br><br>
Choice you current location:<br>
<label for="id_coordinate_x">X: </label><br>
{{ form.coordinate_x }}<br>
<label for="id_coordinate_y">Y: </label><br>
{{ form.coordinate_y }}<br>
{% for i in form.errors %}
{{i}}
{% endfor %}
{% if form.errors %}
error!
{% endif %}
<input type="submit" value="Register"/><br>