AttributeError with forms

41 views
Skip to first unread message

DimGo

unread,
Apr 27, 2020, 11:30:01 AM4/27/20
to Django users
Why is this this strange error?
Снимок экрана от 2020-04-27 18-06-28.png

Phako Perez

unread,
Apr 27, 2020, 1:18:00 PM4/27/20
to django...@googlegroups.com
In addition, you must define your model in models.py

And to get this attributes on your views.py from a post request, you could use like {{ form.attribute }}

Regards

Sent from my iPhone

On 27 Apr 2020, at 10:29, DimGo <proskur...@gmail.com> wrote:


Why is this this strange error?

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7a2089af-344a-479d-bf7c-8a943973159b%40googlegroups.com.
<Снимок экрана от 2020-04-27 18-06-28.png>

Ethem Güner

unread,
Apr 27, 2020, 2:23:56 PM4/27/20
to django...@googlegroups.com
It's not strange. You can't access to an attribute of a form class directly. Remember how do you define the form in a view. You're passing arguments such as data=request.POST. You're trying to access an undefined attribute. Because It's a form class and needs input.

Try to print t.__dict__  you'll get a dictionary of that class. But If you really need to access to the attribute like this, use t['date']

DimGo <proskur...@gmail.com>, 27 Nis 2020 Pzt, 18:29 tarihinde şunu yazdı:
Why is this this strange error?

--

Amitesh Sahay

unread,
Apr 27, 2020, 2:31:15 PM4/27/20
to django...@googlegroups.com
I couldn't open the screenshot . But to work with the django forms you need to perform below tasks.

1) create model of your choice in models.py.
2).  Python manage.py makemigrations
3) python manage py migrate.
4 create a python file called forms.py inside your app.
5) import your models there ( from .models import model_name
6) create class to extend forms module.
7) in views.py you either need to define class based views or function based views. 

On Mon, 27 Apr 2020 at 20:59, DimGo
Why is this this strange error?

--
Reply all
Reply to author
Forward
0 new messages