Class views in Django

前端 未结 9 1707
一生所求
一生所求 2020-12-05 06:15

Django view points to a function, which can be a problem if you want to change only a bit of functionality. Yes, I could have million keyword arguments and even more if stat

相关标签:
9条回答
  • 2020-12-05 06:58

    Unless you want to do something a little complex, using the generic views are the way to go. They are far more powerful than their name implies, and if you are just displaying model data generic views will do the job.

    0 讨论(0)
  • 2020-12-05 07:05

    You can always create a class, override the __call__ function and then point the URL file to an instance of the class. You can take a look at the FormWizard class to see how this is done.

    0 讨论(0)
  • 2020-12-05 07:06

    Generic views will usually be the way to go, but ultimately you're free to handle URLs however you want. FormWizard does things in a class-based way, as do some apps for RESTful APIs.

    Basically with a URL you are given a bunch of variables and place to provide a callable, what callable you provide is completely up to you - the standard way is to provide a function - but ultimately Django puts no restrictions on what you do.

    I do agree that a few more examples of how to do this would be good, FormWizard is probably the place to start though.

    0 讨论(0)
提交回复
热议问题