| Django-ClsView. DjangoÀÇ ¶Ç ´Ù¸¥ Ŭ·¡½º ±â¹Ý ºä ½Ã½ºÅÛ |
Áö±Ý ´Ù¿î·Îµå |
Django-ClsView. ¼øÀ§ ¹× ¿ä¾à
- ƯÇã:
- Other/Proprietary Li...
- °Ô½ÃÀÚ À̸§:
- Zachary Voase
- °Ô½ÃÀÚ À¥»çÀÌÆ®:
- http://github.com/disturbyte/
Django-ClsView. ű×
Django-ClsView. ¼³¸í
DjangoÀÇ ¶Ç ´Ù¸¥ Ŭ·¡½º ±â¹Ý ºä ½Ã½ºÅÛ Django-ClsView´Â Django.Installation¿¡¼ Ŭ·¡½º ±â¹Ý ºäÀÇ ¹®Á¦¿¡ ´ëÇÑ ¶Ç ´Ù¸¥ ¼Ö·ç¼ÇÀ» °®Ãá Django ¾ÛÀÔ´Ï´Ù. PIP ¼³Ä¡ Django-CLSView # OREASY_INSTALL DJANGO-CLSVIEWTHERDER ¼³Ä¡ DJCLSVIEW¸¦ installation_apps ¼³Á¤¿¡ Ãß°¡ ÇÒ ÇÊ¿ä°¡ ¾ø½À´Ï´Ù .UsageClass ±â¹Ýº¸±â ( CBVS)´Â Django View ±â´É°ú ºñ½ÁÇÑ ¹æ½ÄÀ¸·Î ÇൿÇÏ´Â ¼ö¾÷ÀÔ´Ï´Ù. Djangoº¸±â¿¡ ´ëÇÑ ±âº» ¿ä±¸ »çÇ×Àº ÀÀ´ä ¿äûÀ» ¸ÅÇÎÇÏ´Â °ÍÀÔ´Ï´Ù. ¼ö¾÷À» »ç¿ëÇÏ¿© º¸ÀÏ·¯ Ç÷¹ÀÌÆ®¸¦ ÁÙÀÌ°í Àç»ç¿ë ¼ºÀ» ³ôÀ̱â À§ÇØ »ó¼ÓÀÇ ÀÌÁ¡À» ¾ò½À´Ï´Ù. Ŭ·¡½º ±â¹Ýº¸±â¿¡ ¸¹Àº Á¢±Ù ¹æ½ÄÀÌ ÀÖ½À´Ï´Ù. ÀÌ Æ¯Á¤ Á¢±Ù ¹æ½ÄÀº ´Ü¼ø¼º ¹× ³ª»ç º¸Á¶¸¦À§ÇÑ ¸Å¿ì ¾à°£ÀÇ ¼º´É ¹× ¸Þ¸ð¸® Dz ÇÁ¸°Æ®¸¦ °Å·¡ÇÕ´Ï´Ù. URLCONF¿¡¼ Á÷Á¢ Ŭ·¡½º ±â¹Ýº¸±â¸¦ °¡¸®Å³ ¼ö ÀÖ½À´Ï´Ù. URLPATTETNS = ÆÐÅÏ ( '', ... URL (R '^ View / $) ','myApp.Views.myView ', name ='my-view '), ...) ÇÔ¼öÀÇ µ¿ÀÛÀ» º¹Á¦Çϱâ À§ÇØ __new __ ()ÀÌ ¹«½ÃµÇ¾ú½À´Ï´Ù. className (¿äû, * args, ** kwargs)À» È£ÃâÇϸé Ŭ·¡½º¸¦ ÀνºÅϽºÈ ÇÑ ´ÙÀ½ °´Ã¼ (Áï, obj .__ È£Ãâ __ ())¸¦ È£ÃâÇÏ¿© ÇØ´ç ¸Þ¼Òµå°¡ ¹ÝȯµÇ´Â (django.http.httpresponse ÀνºÅϽº°¡µÇ¾î¾ß ÇÔ)À» ¹ÝȯÇÕ´Ï´Ù. µû¶ó¼ °¡Àå ³ôÀº ¼öÁØ¿¡¼ View Ŭ·¡½º´Â ±â´ÉÀ» º¾´Ï´Ù. ViewClass._new (¿äû, * args, ** kwargs)¸¦ »ç¿ëÇÏ¿© View Ŭ·¡½º¸¦ ÀνºÅϽºÈ ÇÒ ¼ö ÀÖ½À´Ï´Ù. ÀÌ°ÍÀº ´Ù¸¥ ºä Ŭ·¡½º¿¡¼ Á¤ÀÇ µÈ ±â´É¿¡ ¾×¼¼½º ÇؾßÇÏ´Â °æ¿ì À¯¿ë ÇÒ ¼ö ÀÖ½À´Ï´Ù (º°µµÀÇ À¯Æ¿¸®Æ¼ Ŭ·¡½º ¶Ç´Â ¹Í½º°¡ °øÀ¯ ±â´É¿¡ ´ëÇÑ ´õ ³ªÀº ¾ÆÀ̵ð¾î).ÀÌ ±¸Çö¿¡ ´ëÇÑ Âü°í »çÇ× : * __new __ () ¸Þ¼µå°¡ ¹«½ÃµÇ¾ú½À´Ï´Ù. »ý¼º ÈÄ¿¡ Áï½Ã ÀνºÅϽº¸¦ È£ÃâÇÕ´Ï´Ù. ÇÏÀ§ Ŭ·¡½º ¿¡¼ÀÌ ÀÛ¾÷À» ÅÍÄ¡ ÇÒ ÇÊ¿ä°¡ ¾ø½À´Ï´Ù. * ¿äû 󸮴 µÎ ´Ü°è¿¡¼ ¼öÇàµË´Ï´Ù. - ÃʱâÈ : view Ŭ·¡½ºÀÇ ÀνºÅϽº¿¡¼ view Ŭ·¡½ºÀÇ ÀνºÅϽº¿¡¼ __init __ () ¸Þ¼µå°¡ È£ÃâµË´Ï´Ù (Áï, (ÀÚü, ¿äû, * args, ** kwargs)). ±âº»ÀûÀ¸·Î ÀÌ°ÍÀº Self.request, self.args ¹× self.kwargsÀÇ ¿äû, À§Ä¡ ¹× Å°¿öµå Àμö¸¦ °¢°¢ self.request, self.args ¹× self.kwargs·Î ÀúÀåÇÕ´Ï´Ù .- ÀÀ´ä : __call __ () ¸Þ¼µå´Â Àμö¾øÀÌ (ÀÚü Á¦¿Ü) È£ÃâµË´Ï´Ù. ÀÌ°ÍÀº django.http.httpresponseÀÇ ÀνºÅϽº¸¦ ¹ÝȯÇؾßÇÕ´Ï´Ù. * ÀνºÅϽº ¸Þ¼ÒµåÀÇ µ¥ÄÚ·¹ÀÌÅÍ´Â django.utils.decorators.method_decorator ()·Î ·¡ÇεǾî¾ßÇÕ´Ï´Ù .method_decorator () : Somemodule °¡Á® ¿À±â django.utils.Decorators °¡Á® ¿À±â method_decorator class myview (º¸±â) : @Method_Decorator (some_decorator) def ¸Þ¼Òµå (ÀÚü) : ¹Ýȯ ¹º°¡ () Examplessimpleº¸±â Á¤ÀÇ ¹× È£Ãâ : >>>¿¡¼ djclsview °¡Á® ¿À±âº¸±â >>> Ŭ·¡½º MyView (º¸±â) : ... DEF __call __ (self) : ... Àμâ self.request ... print self.args .. . self.kwargs Àμâ >>> myview ( '¿äû', 'arg1', 'arg2', kwarg1 = '°ª', kwarg2 = '°ª') ¿äû ( 'arg1', 'arg2') { 'kwarg1': ' °ª ','kwarg2 ':'value '}º¸±â, sidestepping È£ÃâÀ» instantiating : >>> view = myview._new ('¿äû ','Àμö ', kwarg ='value ') >>> <__main __ myview °´Ã¼ 0x> ºä µ¥ÄÚ·¹ÀÌÅÍ°¡Àִº¸±â Àå½Ä : >>> DEF AUTH_REQUED (FUNC) : ... DEF ·¡ÆÛ (¿äû, * args, ** kwargs) : ... Assert ¿äû , "unauthenticated!"... Return Func (¿äû, * args, ** kwargs) ... ¹ÝÇ° ·¡ÆÛ >>> Ŭ·¡½º MyProtectedView (º¸±â) : ... DEF __call __ (ÀÚü) : ... Àμâ 'È£Ãâ'>>> MyProtectedView = myProtectedViewView (auth_required) >>> MyProtectedView ({ 'ÀÎÁõ µÈ': true}) È£Ãâ >>> MyProtectedView ({ 'ÀÎÁõ ': false}) ÃßÀû º¹¼ö (°¡Àå ÃÖ±ÙÀÇ È£Ãâ ¸¶Áö¸·) : ... AssertionError : ÀÎÁõµÇÁö ¾ÊÀ½! CLS._DeCorate ()¸¦ »ç¿ëÇÏ¸é ¿©±â¿¡ ÇÊ¿äÇÕ´Ï´Ù. ±×³É Ŭ·¡½º¸¦ ·¡ÇÎÇÏ¸é ·¡ÆÛ ÇÔ¼ö¸¦ ¹ÝȯÇÕ´Ï´Ù (Decorator°¡ ¸®ÅÏ µÈ´ë·Î). _decorate () __new __ ()À» ·¡ÇÎÇÏ°í Ŭ·¡½º¸¦ ¹ÝȯÇÕ´Ï´Ù. ¿ä±¸ »çÇ× : ¡¤ ÆÄÀ̽㠡¤ Àå°í
Django-ClsView. °ü·Ã ¼ÒÇÁÆ®¿þ¾î