Where are forms usually defined?

0 views
Skip to first unread message

Nick Arnett

unread,
Nov 3, 2009, 2:20:41 PM11/3/09
to django...@googlegroups.com
I find myself frequently frustrated by examples and tutorials that include code snippets that don't identify where they live.  In particular, I haven't quite figured out where forms usually are defined and then where they need to be imported.

I see that forms sometimes are in a file called forms.py... but somewhere I'd expect to then see an import statement along the lines of "from mysite.forms import *".  If I use forms.py for my forms, where does that file need to be imported? 

Thanks,

Nick

f4nt

unread,
Nov 3, 2009, 2:26:06 PM11/3/09
to Django users
forms.py is pretty standard. You'd end up importing them in your
views.py.

Nick Arnett

unread,
Nov 3, 2009, 2:28:00 PM11/3/09
to django...@googlegroups.com
On Tue, Nov 3, 2009 at 11:26 AM, f4nt <xxf4...@gmail.com> wrote:

forms.py is pretty standard. You'd end up importing them in your
views.py.

Thanks... that's what I was guessing.  But it appears to me that I sometimes see ModelForms in models.py... wondering if that's typical.

Nick

f4nt

unread,
Nov 3, 2009, 2:49:00 PM11/3/09
to Django users
I've seen that before as well, and I don't particularly like it. Some
people also customize the admin in the models.py file, which is also
annoying :).

On Nov 3, 1:28 pm, Nick Arnett <nick.arn...@gmail.com> wrote:

hcarvalhoalves

unread,
Nov 4, 2009, 3:39:14 PM11/4/09
to Django users
The common convention seen on Django code and 3rd party apps is to
have a forms.py inside the app dir.

But It doesn't matter because Django doesn't enforce a particular file
name for this, you're free to organize your code tree as you like.
Keep in mind that Django is just Python, so if you're new to Python
you may want to understand how Python modules and imports work. Then
you will be comfortable on designing your code structure.
Reply all
Reply to author
Forward
0 new messages