mercredi 13 août 2014

python - Django formulaire soumission donne erreur 405 - Stack Overflow


I am trying to display a form and and take the submiision in post of my class-based view. code for displaying the form is (no i am not using django's form as it breaks my design and i m in haste :( ) code for my form goes like this:


<form action="." method="POST" >
<input type='hidden' name='pf_id' value='{{pf.id}}' />
<input type='hidden' name='content_type' value='portfolio' />
<textarea id="id_comment" name="comment"></textarea>
<section><input type="submit" value="submit" name="commentSubmit" class="comment-button" title="submit" class="comment-button" /></section>
</form>

in my views.py:


class ProjectDetailView(FormMixin, DetailView):
template_name = 'account/inner-profile-page.html'
model = ProjectDetail
context_object_name = 'project'

def get_object(self, queryset=None):
return get_object_or_404(ProjectDetail, title_slug = self.kwargs['title_slug'])

def get_context_data(self, **kwargs):
context = super(ProjectDetailView, self).get_context_data(**kwargs)
projects = []
for st in SubType.objects.all():
user = self.get_object().user
pd = ProjectDetail.objects.filter(user=user,project_sub_type__sub_type=st)
if pd.count() > 0:
projects.append((st.name, pd.count()))
context['projects'] = projects
return context

def post(self, request, *args, **kwargs):
import pdb;pdb.set_trace()

i am expecting the post method to be called when form is submitted (hopefully i am right in my assumption), but it does not , as submitting this form takes me to a blank page , url does not changes and i get 405 error message in my runserver shell.why is this happening ? my urls are like this:


url(r'^project-detail/(?P<title_slug>\w+)/$',ProjectDetailView.as_view(), name="project-detail-view"),
url(r'^project-page/(?P<user_slug>.+)/$',projectPage.as_view(),name='projectPage'),


I am trying to display a form and and take the submiision in post of my class-based view. code for displaying the form is (no i am not using django's form as it breaks my design and i m in haste :( ) code for my form goes like this:


<form action="." method="POST" >
<input type='hidden' name='pf_id' value='{{pf.id}}' />
<input type='hidden' name='content_type' value='portfolio' />
<textarea id="id_comment" name="comment"></textarea>
<section><input type="submit" value="submit" name="commentSubmit" class="comment-button" title="submit" class="comment-button" /></section>
</form>

in my views.py:


class ProjectDetailView(FormMixin, DetailView):
template_name = 'account/inner-profile-page.html'
model = ProjectDetail
context_object_name = 'project'

def get_object(self, queryset=None):
return get_object_or_404(ProjectDetail, title_slug = self.kwargs['title_slug'])

def get_context_data(self, **kwargs):
context = super(ProjectDetailView, self).get_context_data(**kwargs)
projects = []
for st in SubType.objects.all():
user = self.get_object().user
pd = ProjectDetail.objects.filter(user=user,project_sub_type__sub_type=st)
if pd.count() > 0:
projects.append((st.name, pd.count()))
context['projects'] = projects
return context

def post(self, request, *args, **kwargs):
import pdb;pdb.set_trace()

i am expecting the post method to be called when form is submitted (hopefully i am right in my assumption), but it does not , as submitting this form takes me to a blank page , url does not changes and i get 405 error message in my runserver shell.why is this happening ? my urls are like this:


url(r'^project-detail/(?P<title_slug>\w+)/$',ProjectDetailView.as_view(), name="project-detail-view"),
url(r'^project-page/(?P<user_slug>.+)/$',projectPage.as_view(),name='projectPage'),

0 commentaires:

Enregistrer un commentaire