I'm learning Django 3.0 and I'm actually using the django.contrib.auth.views.LoginView
Here is my views.py file:
from django.contrib.auth.views import LoginView
class CustomLoginView(LoginView):
template_name = "blog/loginview.html"
And here is my urls.py file:
from django.contrib.auth.views import LoginView
from django.conf.urls import url
urlpattenrs = [
url(r'^login/$', views.CustomLoginView.as_view(), name='login')
]
I know I could put everything in the url without making my own view but I wanted to test it.
Here is my template:
<h1>Connection with LoginView</h1>
<form method="POST" action=".">
{% csrf_token %}
{{ form.as_p }}
<input type="hidden" name="next" value="{{ next }}" />
<input type="submit" value="Connect" />
</form>
Everything works perfectly, but on my page, I can see the default labels from the AuthenticationForm used by default by the LoginView.
These are Username: and Password:.
Now here are my questions:
Is it possible to change the labels to
fooinstead ofUsername:andbarinstead ofPassword:from the template and keep the{{ form.as_p }}in the template? Or even better, changing the labels from theCustomLoginView?Is it possible to use a custom form for the
CustomLoginView? Or even better, directly in theLoginView?
Yes it is possible to change the labels but it will be in
forms.pyfile, here is an example: