Hello, everybody! I've tried using FormMixin with DetailView and I get error 405 on post method. Can anybody help me? Thanks a lot.

30 views
Skip to first unread message

Catalina Popescu

unread,
Aug 22, 2019, 7:31:57 PM8/22/19
to Django users
views.py

class BookDisplay(DetailView):
    model = Book
    template_name = 'books/book_detail.html'
    
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['form'] = WishBookForm()
        return context

class WishBook(SingleObjectMixin, FormView):
    form_class = WishBookForm()
    template_name = 'books/book_detail.html'
    model = Status
    
    def post(self, request):
        if not request.user.is_authenticated:
            return HttpResponseForbidden()
            self.object = self.get_object()
            return super().post(request)
        
    def get_success_url(self):
        return reverse('books/book_detail', kwargs = {'pk': self.object.pk})

    
class BookDetail(View):
    def get(self, request):
        view = BookDisplay.as_view()
        return view(request)
        
    def post(self, request):
        view = WishBook.as_view()
        return view(request)

forms.py

class WishBookForm(forms.Form):
    status = forms.ChoiceField(choices=Status.GIVEAWAY_STATUS[:2], initial='Cu chef de ducă')


James Schneider

unread,
Aug 22, 2019, 9:28:27 PM8/22/19
to django...@googlegroups.com
Post the full error message and/or traceback reported by the server when the error occurs.

-James

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/231fd7dc-3bf2-465c-993b-c476b0ca4dc1%40googlegroups.com.

Catalina Popescu

unread,
Aug 23, 2019, 6:58:22 AM8/23/19
to Django users
Morning, James

The browser just throws HTTP ERROR 405. 
In CMD: 
Method Not Allowed (POST): books/book/10/
Method Not Allowed: books/book/10/
"POST /book/book/10/ HTTP/1.1" 405.0


On Friday, August 23, 2019 at 12:28:27 AM UTC+3, James Schneider wrote:
Post the full error message and/or traceback reported by the server when the error occurs.

-James

To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

Mehmet Demirkaya

unread,
Aug 23, 2019, 11:20:18 AM8/23/19
to django...@googlegroups.com
Do have relation with Mr Popescu from Romanian Central (National) Bank?

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/31cab945-367f-448c-97fd-56e90f63bb3d%40googlegroups.com.


--
Mehmet Demirkaya

Catalina Popescu

unread,
Aug 23, 2019, 11:22:42 AM8/23/19
to django...@googlegroups.com
I'm afraid not. Popescu is a very common first name here. 
But your help depends on that presumed relation? ;) Joking. 


Reply all
Reply to author
Forward
0 new messages