Form doesn't show in HTML template

46 views
Skip to first unread message

Some Developer

unread,
Nov 20, 2014, 3:26:46 PM11/20/14
to django...@googlegroups.com
I'm having a bit of a perplexing issue with Django 1.7.1 running on Arch
Linux using Python 3.4.2. If it matters I'm using Pycharm 3.4 as my IDE.

I have the following Python modules installed in my virtualenv:

bcrypt
boto
braintree
cffi
django-braces
django-debug-toolbar
psycopg2
pycparser
requests
six
sqlparse

I have a FormView which takes a Django form object (not a ModelForm) and
tries to display a form. But when I view the template in a browser the
form itself is not shown.

At first I thought that for some reason the form context object was not
being passed to the template but I checked the template context object
(via django-debug-toolbar) and the form context variable is available in
the template and is the correct object.

I've tried various things including changing the view to a CreateView
object and obviously changing the form to ModelForm which does display
the form but for various reasons I'd rather have just a standard form
rather than a ModelForm and use FormView.

Here is the code in question:

http://dpaste.com/1S6W861

I have absolutely no idea what the problem is. Pretty much the same code
worked perfectly on Python 2.7.x and the only difference I can see is
that I am now using Python 3.4.x but I'm positive this can't be the
issue as it would have been picked up way before now.

Any help is appreciated as I'm finding this really perplexing.

If I've left anything out that would be useful let me know and I'll post
the information up.

James Schneider

unread,
Nov 20, 2014, 4:16:19 PM11/20/14
to django...@googlegroups.com

Dumb question, but there is a "main_content" block in base.html, right?

I'm assuming the "Please register..." message shows but the form doesn't? Or does that message not show up?

-James

--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/546E4E63.60207%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.

Some Developer

unread,
Nov 20, 2014, 4:40:45 PM11/20/14
to django...@googlegroups.com
On 20/11/14 21:15, James Schneider wrote:
> Dumb question, but there is a "main_content" block in base.html, right?
>
> I'm assuming the "Please register..." message shows but the form
> doesn't? Or does that message not show up?
>
> -James
>

Yes main_content block exists and the page displays the forms submit
button and the "Please register..." text just fine. The only thing that
is not displayed is the email, password and password_confirm form fields
in the form object which is strange. Even the csrf_token displays fine
(which I forgot to add to the source code I posted on dpaste).

Vijay Khemlani

unread,
Nov 20, 2014, 5:07:47 PM11/20/14
to django...@googlegroups.com
If you set the settings TEMPLATE_DEBUG to True, does it display any errors?

--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Some Developer

unread,
Nov 20, 2014, 5:11:00 PM11/20/14
to django...@googlegroups.com
On 20/11/14 22:07, Vijay Khemlani wrote:
> If you set the settings TEMPLATE_DEBUG to True, does it display any errors?
>

No.

Some Developer

unread,
Nov 21, 2014, 10:29:48 AM11/21/14
to django...@googlegroups.com
On 20/11/14 22:07, Vijay Khemlani wrote:
> If you set the settings TEMPLATE_DEBUG to True, does it display any errors?
>

Hmm still been trying to figure out what is going on but haven't really
managed to get very far. I'm completely stumped.

Has anyone got any tips as to what the problem might be?

Vijay Khemlani

unread,
Nov 21, 2014, 10:31:27 AM11/21/14
to django...@googlegroups.com
If you manually call the form "as_p" method in the view (not the template), does it print the form?

--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Some Developer

unread,
Nov 21, 2014, 11:02:02 AM11/21/14
to django...@googlegroups.com
On 21/11/14 15:31, Vijay Khemlani wrote:
> If you manually call the form "as_p" method in the view (not the
> template), does it print the form?
>

Which method in the FormView class would I override to put that in?
The get() method or the render_to_response() method?

Some Developer

unread,
Nov 21, 2014, 11:33:16 AM11/21/14
to django...@googlegroups.com
On 21/11/14 15:31, Vijay Khemlani wrote:
> If you manually call the form "as_p" method in the view (not the
> template), does it print the form?
>

OK. Sorted that out.

Running my program through the debugger shows that the form object
exists and has the correct fields associated with it.

I don't understand this. Everything I look at says that the form should
display correctly and it just isn't. The form_class has been
instantiated correctly, there are no errors or warnings when I run my
code. The template gets the form object passed to it as a context
object. The only thing that doesn't happen is the form being displayed.

Very strange indeed.

Collin Anderson

unread,
Nov 24, 2014, 8:46:24 AM11/24/14
to django...@googlegroups.com
Hi,

Are the form fields in the html source (view source) and then getting hidden using CSS or removed using JavaScript?

What does this output? {% if form %}Yes, there's a form{% else %}No form{% endif %}

Collin
Reply all
Reply to author
Forward
0 new messages