検索 - みる会図書館

検索対象: Two Scoops of Django Best Practices for Django 1.8

Two Scoops of Django Best Practices for Django 1.8から 36件ヒットしました。

Two Scoops of Django Best Practices for Django 1.8


カ ⅳ グ 7 な 25.1 25.2 31.1 31.2 31.3 32.1 35.1 35.2 488 Shou1d a Project Have a Task reu Comparing Task Queue S0ftware Gunicorn vs Apache vs uWSGl TimeIine of DevOps To 01S lnfrastructure Automation T001 Comparison . C ontinuous lntegration S ervices django. utils. translation Function Reference . S ecurity S ettings Reference . . 328 . 329 . 412 . 417 . 420 . 427 . 464 . 477

Two Scoops of Django Best Practices for Django 1.8


List ofTab1es Author's lce Cream Preferences . 1.1 lmports: AbsoIute vs. ExpIicit ReIative vs. lmplicit Relative . 3.1 Repository Root Files and Directories 3 ・ 2 Django Project Files and Directories 5.1 Settings files and their purpose 5.2 Setting DJANGO-SETTINGSMODULE per location . 6.1 Pros and Cons of the Mode1 lnheritance Styles 6.2 When to Use Null and Blank by Field 6.3 When to Use Nu11 and B1ank for Postgres Fie1ds . 7.1 When to Use Transact10ns Django CBV Usage TabIe . 10.1 TempIate Tags in base. html 13.1 Template Objects in about. html 13.2 15.1 DTL vs Ji 可 a2 Syntax Differences 15.2 DTL vs Ji 可 心 Syntax Similarities 16.1 HTTP Methods 16.2 HTTP Status Codes 16.3 URLConffor the Flavor REST APIs Fad-based Reasons to Rep1ace Components of Django 18.1 Documentation Django Projects ShouId Contain 23.1 . XXXIII 7 25 26 44 45 15 一 1 戸 ) 6 / 冖 / 93 . 122 . 184 . 186 . 203 . 204 . 214 . 216 . 218 . 244 . 312 487

Two Scoops of Django Best Practices for Django 1.8


from modets import WaffteCone implicit relative Often used when importing from another module in the current 叩 p, but not a good idea TabIe 1.1 : lmports: Absolute vs. Explicit Relative vs. lmplicit Relative Get into the habit ofusing explicit relative imports. lt's very easy to do, and using explicit relative Additional reading: http: //www. python.org/dev/peps/[email protected]/ http://2scoops . co/guido—on—pep—8—vs—pep—328 See what Guido Van Rossum, BDFL of Python says about it: TIP: Doesn't PEP 328 CIash With PEP 8 ? imports is a good habit for any Python programmer to develop. from django. db. models import ☆ from django. forms import ☆ # ANTI—PATTERN: Don't do thisl BAD EXAMPLE 1.2 Never do the following: from django. db import modets from dj ango import forms EXAMPLE 1.3 ln 99 % of 砠 our work, we explicitly import each module: 1.5 Avoid Using lmport* 7 results. over our current module's namesp ace , this can produce unpredictable and sometimes catastrophic "lhe reason for this is to avoid implicitly loading 砠 of another Python module's locals into and

Two Scoops of Django Best Practices for Django 1.8


CO 〃 た 〃 な -4- -4 -4 -6 一 0 ノ 0 -0 っ っ 0 ・ 4 一 5 ~ / 0 8 ・ . 9- 0 ノ ノ 6 Mode1 Best Practices 6.1 Basics 6.1.1 Break Up Apps With Too Many Models . 6.1.2 Be CarefuIWith ModeI lnheritance 6.1.3 Mode1 lnheritance in Practice: %e TimeStampedModel 6.1.4 Database Migrations 6.2 Django Model Design . Start NormaIized 6.2.1 6.2.2 Cache Before DenormaIizing ・ 6.2.3 DenormaIize OnIy ifAbsolutely Needed . 6.2.4 When to Use Nu11 and BIank . 6.2.5 When to Use BinaryFieId . 6.2.6 Try to Avoid Using Generic Relations 6.2.7 PostgreSQJ. u-Specific FieIds: When to Use NuIl and BIank 6.3 lhe Model uneta API . 6.4 Mode1 Managers ・ 6.5 Understanding Fat M odels 6.5.1 Mode1 Behaviors a. k. a Mixins S tateless Helper Functions 6.5.2 6.5.3 Mode1 Behaviors vs Helper Functions Summary . 7 Qyeries and the Database Layer 7.1 Use get-object-or-404() for Single Objects 7.2 Be CarefuI With Queries %at Might %row Exceptions . 7.2.1 ObjectDoesNotExist vs. DoesNotExist 7.2.2 When You Just Want One Object but Get FIhree Back 7.3 Use Lazy Evaluation to Make Queries Legible 7.4 Lean on Advanced 肥 T001S . 7.4.1 肥 Expressions 7.4.2 Database Functions 7.5 Don't Drop Down to Raw SQJ. , Unti1 lt's Necessary 7.6 Add lndexes as Needed 7.7 Transactions 7.7.1 Wrapping Each HTTP Request in a Transaction 7.7.2 Explicit Transaction Declaration 6.6 1 イ 1 つ ん っ っ 0 -4 ・ 一 う -6 一 冖 / 8 ・ . ′ っ ~ 8 8 8 8 8 ) 一 8 8 8 8 8 8 一 8 ) ~ 8 一 ノ

Two Scoops of Django Best Practices for Django 1.8


CO 〃 た 〃 な -4- -4 -4 -6 一 0 ノ 0 -0 っ っ 0 ・ 4 一 5 ~ / 0 8 ・ . 9- 0 ノ ノ 6 Mode1 Best Practices 6.1 Basics 6.1.1 Break Up Apps With Too Many Models . 6.1.2 Be CarefuIWith ModeI lnheritance 6.1.3 Mode1 lnheritance in Practice: %e TimeStampedModel 6.1.4 Database Migrations 6.2 Django Model Design . Start NormaIized 6.2.1 6.2.2 Cache Before DenormaIizing ・ 6.2.3 DenormaIize OnIy ifAbsolutely Needed . 6.2.4 When to Use Nu11 and BIank . 6.2.5 When to Use BinaryFieId . 6.2.6 Try to Avoid Using Generic Relations 6.2.7 PostgreSQJ. u-Specific FieIds: When to Use NuIl and BIank 6.3 lhe Model uneta API . 6.4 Mode1 Managers ・ 6.5 Understanding Fat M odels 6.5.1 Mode1 Behaviors a. k. a Mixins S tateless Helper Functions 6.5.2 6.5.3 Mode1 Behaviors vs Helper Functions Summary . 7 Qyeries and the Database Layer 7.1 Use get-object-or-404() for Single Objects 7.2 Be CarefuI With Queries %at Might %row Exceptions . 7.2.1 ObjectDoesNotExist vs. DoesNotExist 7.2.2 When You Just Want One Object but Get FIhree Back 7.3 Use Lazy Evaluation to Make Queries Legible 7.4 Lean on Advanced 肥 T001S . 7.4.1 肥 Expressions 7.4.2 Database Functions 7.5 Don't Drop Down to Raw SQJ. , Unti1 lt's Necessary 7.6 Add lndexes as Needed 7.7 Transactions 7.7.1 Wrapping Each HTTP Request in a Transaction 7.7.2 Explicit Transaction Declaration 6.6 1 イ 1 つ ん っ っ 0 -4 ・ 一 う -6 一 冖 / 8 ・ . ′ っ ~ 8 8 8 8 8 ) 一 8 8 8 8 8 8 一 8 ) ~ 8 一 ノ

Two Scoops of Django Best Practices for Django 1.8


17.9 Usefu1 Resources . 17.10 Summary . 18 Tradeoffs of RepIacing Core Components 18.1 FIhe Temptation to BuiId FrankenDjango . 18.2 Non-Re1ational Databases vs. Re1ational Databases 18.2.1 Not AII Non-Relational Databases Are ACID Compliant . 18.2.2 Don't Use Non-Re1ationaI Databases for Re1ationaI Tasks . 18.2.3 lgnore the Hype and Do Your Own Research 18.2.4 How We Use Non-ReIationa1 Databases With Django 18.3 What About Replacing the Django TempIate Language? 18.4 Summary . 19 、 vorking 、 Vith the DjangoAdmin 19.1 19.2 19.3 19.4 19.5 19.6 19.7 19.8 19.9 lt's Not for End Users . Admin Customization vs. New Views Viewing String Representations of Objects Adding Callab1es to Mode1Admin Classes Don't Use list-editable in Multiuser Environments Django's . Admin Documentation Generator Securing the Django Admin and Django Admin Docs . Using Custom Skins With the Django Admin . 19.8.1 Eva1uation Point: Documentation is Everything 19.8.2 Write Tests for Any Admin Extensions You Create Summary . 20 Dealing 、 Vith the User Model 20.1 Use Django's T001S for Finding the User ModeI 20.1.1 Use settings. AUTH-USER-MODEL for Foreign Keys to User 20.1.2 Don't Use get-user=model() for Foreign Keys to User 20.2 Migrating Pre-1.5 User ModeIs to 1.5 + ' s Custom User Models 20.3 Custom User FieIds for Django 1.8 Projects 20.3.1 Option 1 : SubcIass AbstractUser 20.3.2 Option 2 : Subc1ass AbstractBaseUser . 20.3.3 Option 3 : Linking Back From a ReIated ModeI XVZ . 242 . 242 243 . 244 . 245 . 245 . 246 . 246 . 247 . 247 . 247 249 . 250 . 250 . 250 . 254 . 255 . 256 . 257 . 257 . 258 . 258 . 259 261 . 261 . 262 . 262 . 263 . 263 . 264 . 265 . 265

Two Scoops of Django Best Practices for Django 1.8


17.9 Usefu1 Resources . 17.10 Summary . 18 Tradeoffs of RepIacing Core Components 18.1 FIhe Temptation to BuiId FrankenDjango . 18.2 Non-Re1ational Databases vs. Re1ational Databases 18.2.1 Not AII Non-Relational Databases Are ACID Compliant . 18.2.2 Don't Use Non-Re1ationaI Databases for Re1ationaI Tasks . 18.2.3 lgnore the Hype and Do Your Own Research 18.2.4 How We Use Non-ReIationa1 Databases With Django 18.3 What About Replacing the Django TempIate Language? 18.4 Summary . 19 、 vorking 、 Vith the DjangoAdmin 19.1 19.2 19.3 19.4 19.5 19.6 19.7 19.8 19.9 lt's Not for End Users . Admin Customization vs. New Views Viewing String Representations of Objects Adding Callab1es to Mode1Admin Classes Don't Use list-editable in Multiuser Environments Django's . Admin Documentation Generator Securing the Django Admin and Django Admin Docs . Using Custom Skins With the Django Admin . 19.8.1 Eva1uation Point: Documentation is Everything 19.8.2 Write Tests for Any Admin Extensions You Create Summary . 20 Dealing 、 Vith the User Model 20.1 Use Django's T001S for Finding the User ModeI 20.1.1 Use settings. AUTH-USER-MODEL for Foreign Keys to User 20.1.2 Don't Use get-user=model() for Foreign Keys to User 20.2 Migrating Pre-1.5 User ModeIs to 1.5 + ' s Custom User Models 20.3 Custom User FieIds for Django 1.8 Projects 20.3.1 Option 1 : SubcIass AbstractUser 20.3.2 Option 2 : Subc1ass AbstractBaseUser . 20.3.3 Option 3 : Linking Back From a ReIated ModeI XVZ . 242 . 242 243 . 244 . 245 . 245 . 246 . 246 . 247 . 247 . 247 249 . 250 . 250 . 250 . 254 . 255 . 256 . 257 . 257 . 258 . 258 . 259 261 . 261 . 262 . 262 . 263 . 263 . 264 . 265 . 265

Two Scoops of Django Best Practices for Django 1.8


C み 孕 鑽 77. ・ ConsumingRESTAPIs j 肥 http://jquery. com/ 、 MhiIe it's no longer the c 。 01 kid on the block, 75 percent of the web can't be wrong ・ "lhese libraries can re 1 メ improve what we fike tO c 引 1 the fimmediate user experience'. HO 、 with every good thing there are always things to consider and things to do. 17.1 Learn How t0 Debug the CIient Debugging client-side JavaScript is a 10t more than simply writing consote. 10g ( ) and con- sote. di r ( ) statements. Flhere are a number 0f t001S for debugging and finding errors' and some ofthem are specifically written for particularJavaScript frameworks. Once a t001 ofchoice is chosen, it S an excellent idea tO take a day tO learn hO 、 tO write client-side tests. Reference material: http://2scoops. co/chrome¯developer¯tools https://developer.mozilla.org/en-US/docs/Debugging—JavaScript cßSA の 0 Figure 17.1 : Server-side vs. client-side ice cream. 232

Two Scoops of Django Best Practices for Django 1.8


15 Django TempIates and Jinja2 With Django 1.8 comes support for multiple template engines. As of now, the only available backends for the Django template system are the Django templatelanguage (DTL) andJinja2, both ofwhich are built into Django itself. 15.1 What ・ s the SyntacticaI Difference? At the syntax level, DTL and Ji 可 a2 are very similar. ln fact, Ji 可 a2 was inspired by DTL. Here are the most significant syntax differences: Sub ・ ect Method 朝 FiIter A 「 guments LO 叩 Empty Argument Loop VariabIe CycIe DT L even' , 。 cycle "odd" " f0r100P } } , 。 empty % } toppingsljoin: user. get—favorites に Jinja2 { { 100P. cycle("odd" { { loop } } else / 0 toppingsljoin(" user. get-favorites() } } / 0 Tab1e 15.1 : DTL vs Ji 可 a2 Syntax Differences 203 contradict the Jinj a2 Documentation : scribed in http://_jinja ・ POC00. org/docs/dev/switching/#django. SimiIarities that PIease note that over time DTL has evolved to have syntax much closer to Ji 可 than is de-

Two Scoops of Django Best Practices for Django 1.8


Appendix G: Security Settings Reference Appendix G: Security Settings Reference ln Django, knowing which setting should be set to what value in development vs production requires an unfortunate amount Of domain kno 、 &'ledge. appendix is a reference for better understanding how to con 石 江 e a Django project for both development and production. Setting ALLOWEDNOSTS Cross Site Request Forgery protection DEBUG DEBUG-PROPAGATE-EXCEPTIONS Email SSL MIDDLEWARE-CLASSES SECRET-KEY SECURE9ROXYSLNEADER SECURE-SSL-HOST SESSION-COOKIESECURE SESSIONSERIALIZER DeveIopment a ny li st See next page True False See next page Standa 「 d Use cryptographic key None Fa lse Fa lse See below Production See subsection .2.4 See next page False False See next page Add SecurityMiddIeware See section 53 See next page T 「 ue TI 「 ue See next page TabIe 35.2 : Security Settings Reference 477