I'm in the process of upgrading a website from Django 1.4 and I'm run into 
a problem of getting my code that shows a form on almost every page 
migrated.  I eventually want to upgrade to Django 1.11 but I'm currently 
working on upgrading from Django 1.4 to Django 1.5.  I have a “request 
information” form on each page except for a few sign-up pages.  

In Django 1.4 I used direct_to_template for most of the website.  I have a 
<base.html> that is inheirted by each page.  For example <home.html>, 
<about-us.html>, etc. inherit  from <base.html>.  In <base.html> I load the 
right columns html with 
    “{% block rightColumn  %} {%include "site/rightColumn.html"%}  
{%endblock%}” 
and then in <rightColumn.html> I load the form's html with 
    “{%include "site/reqInfoForm.html"%}”.      

To get the from on each page I used middleware similar to this 
http://stackoverflow.com/questions/2734055/putting-a-django-login-form-on-every-page.
  
I created a class with a method “def process_view(self, request, view_func, 
view_args, view_kwargs)”.  In the method if a POST request and not one of 
the signup pages then I create a form instance from the request and if the 
form is valid then process it then redirect to thanks page, otherwise 
attach the form to the request so that I can show the errors in the form 
template.  

This worked perfectly in Django 1.4 though it seemed like a hack.

While upgrading to Django 1.5 in the url.py I switched from 
“direct_to_template” to “TemplateView.as_view”.  Now when there is an error 
in the form (i.e., leave a required field blank), I get an error “"POST / 
HTTP/1.1" 405 0” while running with the local server.  When I did some 
research, it appears TemplateView doesn't have a POST method.

It seems one way may be to add TemplateView for each page but it seems like 
I would have to add a post method for each page(or maybe a mixin).  Any 
thoughts on this method?  I found another method using context processors 
but I'm not following it.  Also any suggestions on other ways of adding a 
form to almost all pages?

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/52c882b9-09d5-4b58-8234-b967785650de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to