Amit Vadgama
Amit Vadgama

Reputation: 25

Can we use class as view in django?

view.py

class myapp():

   def index(self):
      return redirect(someusrl)

   def productview(self):
      return redirect(someusrl)

urls.py

path('', myapp.index, name="home"),

path('product', myapp.productview, name="Product_page")

like this way

thanks in advance :)

Upvotes: 2

Views: 29

Answers (1)

Jeet
Jeet

Reputation: 372

Why you are creating functions inside that class? Instead of this you should use django class-based views.

Here is the documentation :

https://docs.djangoproject.com/en/3.0/topics/class-based-views/

Upvotes: 1

Related Questions