0

I am aware there are already a lot of other answered questions about this. After reading them, I came up with the following code, so that I can style my email input field in my user registration form and in my login form. Focus is on the "widget=forms.EmailField(attrs={'id': 'rmkinput'})", which, as far as I understand from the readings, should give me css accessibility:

class UserRegForm(UserCreationForm) :
    email = forms.EmailField(widget=forms.EmailField(attrs={'id': 'inputfield'}), label='eMail Adresse')

Nevertheless, when I "manage.py runserver", I get an error message:

    super().__init__(strip=True, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\django\forms\fields.py", line 214, in __init__
    super().__init__(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'attrs'

I kept reading the documentation and the other stakcoverflow questions, but I just can't figure it out. Can anybody help?

If more code is required to answer the question, let me know. Thanks!

1 Answer 1

2

The widget name is EmailInput not EmailField:

class UserRegForm(UserCreationForm) :
    email = forms.EmailField(widget=forms.EmailInput(attrs={'id': 'inputfield'}), label='eMail Adresse')
Sign up to request clarification or add additional context in comments.

1 Comment

...oh...hehe... who would have known. That did the trick! Thanks!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.