Reputation: 1798
I am following: I have built a project from following the general tutorial on the same site. https://docs.djangoproject.com/en/1.8/topics/forms/#building-a-form-in-django I have created this forms.py and placed it in my apps folder (polls).
My polls/templates/polls/index.html:
<form action="/your-name/" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit" />
</form>
The page shows the button "Submit", but no input field.
My polls/views.py:
class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_question_list'
def get_name(request):
... As in the link
polls/forms.py: from django import forms
class NameForm(forms.Form):
print("NAMEFORM NAMEFORM NAMEFORM")
your_name = forms.CharField(label="Your name", max_length = 100)
age = forms.IntegerField(label="Your age")
All I see is the "Submit" button. When I click it, the form-action works (directs to http://127.0.0.1:8000/your-name/ which is 404if that matters - my main problem is that I cant get the input field to show up) Thank you for your time
Upvotes: 1
Views: 113
Reputation: 14220
You are missing form_class = NameForm
, and also the get
and post
methods.
You should read the Handling forms with class-based views section of the the documentation as well.
Upvotes: 0