Вопрос

Here is my code. I was just trying to implement this but could not.I am in a stage of leaning Django

class BCD(View):
    def start(self):
        return HttpResponse("Huray Finally I called")

urls.py

urlpatterns = patterns('',
     url(r'^login1/$',BCD.as_view(),)

And even i tried

urlpatterns = patterns('',
     url(r'^login1/$',BCD.start.as_view(),)

It throws error.I have read the docs of django methods such as get and post ,head can be written they will be called directly according to the request made.But what I is need to make my own methods in class based views

Thanks in Advance

Это было полезно?

Решение

You need to call methods in get(), post() or whatever the HTTP request is. There isn't a start HTTP request so Django won't call that.

You can do the following in your view:

def get(self, request, *args, **kwargs):
    return self.start()

This return the result of self.start() whenever you visit your view with a HTTP GET request.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top