python - Django Form not rendering in template -


i must overlooking here, after stripping - can't seem django render either form or modelform template. code below:

#forms.py class contactform(forms.form):    subject = forms.charfield(max_length=100)    message = forms.charfield()    sender = forms.emailfield()    cc_myself = forms.booleanfield(required=false)  #views.py def index(request):     if request.method == 'post':         form = contactform(request.post)         if form.is_valid(): # validation rules pass             return httpresponseredirect('/thanks/')     else:         form = contactform() # unbound form     return render_to_response('home/new_website.html',{         'form': form,         })  #new_website_html <html> <body>     <form method = "post" action = "">         {{ form.as_p }}     </form> </body> </html> 

i had same issue , after many tries solution:

change view this

#views.py else:     form = contactform() # unbound form return render_to_response('home/new_website.html',{     'form': form,     }) 

to that:

#views.py else:     form = contactform() # unbound form     return render_to_response('home/new_website.html',{         'form': form,         }) 

or simple newline enough:

#views.py else:     form = contactform() # unbound form  return render_to_response('home/new_website.html',{     'form': form,     }) 

strange thing is, after these changes original code worked.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -