おそらくよくない質問ですが、私はDjangoのUserCreationForm(電子メールを含むように少し変更)を使用していますが、Djangoが自動的にHTMLページに表示するhelp_textを削除したいと思います。Djangoからhelp_textを削除するUserCreateForm
私のHTMLページの「登録」部分には、ユーザー名、電子メール、パスワード1 &パスワード2フィールドがあります。しかし、ユーザー名の下には「必須、30文字以下の文字、数字、@ ...のみ」パスワード確認(パスワード2)の下に「確認のために上記と同じパスワードを入力してください」と表示されます。
どうすれば削除できますか?
あなたが__init__
from django.contrib.auth.forms import UserCreationForm
from django import forms
class UserCreateForm(UserCreationForm):
email = forms.EmailField(required=True)
def __init__(self, *args, **kwargs):
super(UserCreateForm, self).__init__(*args, **kwargs)
for fieldname in ['username', 'password1', 'password2']:
self.fields[fieldname].help_text = None
print UserCreateForm()
出力にNoneにフィールドのhelp_text
を設定することができ
#models.py
class UserCreateForm(UserCreationForm):
email = forms.EmailField(required=True)
def save(self, commit=True):
user = super(UserCreateForm, self).save(commit=False)
user.email = self.cleaned_data['email']
if commit:
user.save()
return user
class Meta:
model = User
fields = ("username", "email", "password1", "password2")
exclude = ('username.help_text')
#views.py
def index(request):
r = Movie.objects.all().order_by('-pub_date')
form = UserCreateForm()
return render_to_response('qanda/index.html', {'latest_movie_list': r, 'form':form}, context_instance = RequestContext(request))
#index.html
<form action = "/home/register/" method = "post" id = "register">{% csrf_token %}
<h6> Create an account </h6>
{{ form.as_p }}
<input type = "submit" value = "Create!">
<input type = "hidden" name = "next" value = "{{ next|escape }}" />
</form>
素晴らしい。助けてくれてありがとう! –