Sunday, February 14, 2021

Re: How to add css class and attribute to username,password

Try changing UserLoginForm(forms.ModelForm) to UserLoginForm(forms.Form)

On Sunday, February 7, 2021 at 9:41:35 PM UTC+1 tba...@gmail.com wrote:

Hello ,

I writing project which the user login with my own customized HTML page (boosstrap)

i can manually add the form.username and form.password , but seems they don't get the attribute from my forms.py , dode is added below , please advise

Thanks


urls.py

from django.urls import path from django.contrib.auth import views as auth_views from .views import * urlpatterns = [     path('login/', auth_views.LoginView.as_view(), name = 'login'),  path('signup/', SignUpView.as_view(), name='signup'), ]


views.py

from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.views import LoginView from django.urls import reverse_lazy from django.views import generic from .forms import * class UsersLoginView(LoginView):     template_name = 'login.html'     success_url = 'blog-home'     success_message = 'Welcome to your profile'     form_class = UserLoginForm

forms.py

from django import forms from django.forms import ModelForm from .models import User class UserLoginForm(forms.ModelForm):     username = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control', 'type':'email', 'name':'Username', 'placeholder':'Username'}))     password = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'form-control', 'type': 'password', 'name': 'password', 'placeholder':'Password'}))

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6ac6a8c7-bc9a-46f3-b8cb-e138a76ec298n%40googlegroups.com.

No comments:

Post a Comment