今、基本的なログインをしています。ここにそれを撃つDjangoの「ログイン」フォームを拡張するにはどうすればよいですか?
(r'^login/?$','django.contrib.auth.views.login',{'template_name':'login.html'}),
:
@csrf_protect
@never_cache
def login(request, template_name='registration/login.html',
redirect_field_name=REDIRECT_FIELD_NAME,
authentication_form=AuthenticationForm):
は、そのビューがAuthenticationFormフォームモデルを使用しています:urls.pyでは、私が寄贈ログインジャンゴに行く
class AuthenticationForm(forms.Form):
"""
Base class for authenticating users. Extend this to get a form that accepts
username/password logins.
"""
username = forms.CharField(label=_("Username"), max_length=30)
password = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
そうに.. 私の目的は、ユーザー名の書式を変更することです!これにこれを加えることによって:widget = forms.TextInput(attrs={'placeholder': 'username'})
。それでおしまい。それが私がユーザー名入力ボックスに追加したいものです。しかし、私は実際のdjango forms.pyファイルを変更したくないです。これはdjango contribの一部であり、そのファイルを変更するのが悪いと感じています。
私は何をしますか? AuthenticationFormを拡張するフォームを作成する必要がありますか?もしそうなら、私はどのようにそれをインポートするのですか?そして、私はそれをurls.pyを介して引数としてどのように渡しますか?私は何をすべきかわからない。
感謝さっぱりしたポインタ! – rikb