Skip to content Skip to sidebar Skip to footer

Django Form Doesn't Render

Hello and thank you in advance. I have a django form that is not rendering on a template. The 'submit' button renders, but the form doesn't. I have been staring at this code for

Solution 1:

Reading the answers thread, it seems you're still out of luck.

Try performing these commands in a django interactive shell (python manage.py shell). It's possible that an exception is thrown when you try to format the form. When an exception is thrown during the form generation in the template, you won't see much in the HTML; but a django shell usually unveils the culprit.

python manage.py shell

In [1]: from simple.models import DraftForm

In [2]: form = DraftForm()

In [3]: form.as_p()

You can either see the HTML generated here, or would catch an exception. This will tell you more about what you need to fix.

Solution 2:

Either use {{ form.as_table }} or remove the <table></table> from around your form tag.

Solution 3:

I think that it is a sign to move to generics classes :) Just try CreateView class

In your views.py file:

classCreateDraftInputView(CreateView):
    model = DraftInput
    template_name = "test/draftinput_form.html"
    success_url = "/test/listdraft/"

Simple create template:

<formmethod="POST"action="."><table>
    {% csrf_token %}
    {{ form.as_table }}
    <inputtype="submit" /></table></form>

And very simple list of records in your urls.py:

, (r"^listdraft/$", ListView.as_view(model = DraftInput, template_name = "draftinput_list.html"))

Solution 4:

Try {{ form.as_p }} for example. There are other shortcuts. You can also manually create the form. Have a look into the Django Docs : https://docs.djangoproject.com/en/dev/topics/forms/?from=olddocs

Solution 5:

Try "form.as_p" or "form.as_table" instead of just "form" in your html file.

EDIT: check out the documentation and use one of their examples as a model: https://docs.djangoproject.com/en/dev/topics/forms/modelforms/

In your example, you define form parameters in your model, which may be incorrect. You want to leave form specific modifications, like help_text in the DraftForm class, now in the DraftInput model.

This is a simple issue, you should just replicate something from the docs and then work towards what you want.

Hope this helps.

Post a Comment for "Django Form Doesn't Render"