[Answer]-Django render doesn`t give a view

1👍

as_view() of a class based view isn’t supposed to return an http response, but a callable function…
If you want to send out a response for a GET request, add a get method to you view class:

class MyView(View):
    def get(request):
        # return your http response here

If you want to browse Django’s class based views a bit, here’s a nice documentation!

0👍

why don’t you use Django FormView? This is the documentation.

from django.views.generic.edit import FormView

class MyFormView(FormView):
    form_class = myForm
    template_name = 'my_template.html'
    success_url = '/thanks/'

    def get_context_data(self, **kwargs):
        #This is you GET
        return super(MyFormView. self).get_context_data(**kwargs)

    def form_valid(self, form):
        #This is after the post, when the form is valid
        return super(MyFormView, self).form_valid(form)

    def form_invalid(self, form):
        #This is after the post, when the form is invalid
        return super(MyFormView, self).form_invalid(form)

You can play with get_succes_url() method to redirect so somewhere.

I Hope that helps.

Leave a comment