中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx

上传人:wj 文档编号:145543 上传时间:2023-04-28 格式:DOCX 页数:49 大小:797.75KB
下载 相关 举报
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第1页
第1页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第2页
第2页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第3页
第3页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第4页
第4页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第5页
第5页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第6页
第6页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第7页
第7页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第8页
第8页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第9页
第9页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第10页
第10页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第11页
第11页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第12页
第12页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第13页
第13页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第14页
第14页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第15页
第15页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第16页
第16页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第17页
第17页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第18页
第18页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第19页
第19页 / 共49页
中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx_第20页
第20页 / 共49页
亲,该文档总共49页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx

《中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx》由会员分享,可在线阅读,更多相关《中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx(49页珍藏版)》请在冰点文库上搜索。

中英文双语计算机专业毕业设计外文文献翻译成品:Django框架介绍(最新).docx

此文档是毕业设计外文翻译成品(含英文原文+中文翻译),无需调整复杂的格式!

下载之后直接可用,方便快捷!

本文价格不贵,也就几十块钱!

一辈子也就一次的事!

外文标题:

IntroductiontotheDjangoFramework

外文作者:

DanielRubio

文献出处:

DanielRubio.IntroductiontotheDjangoFramework[M].BeginningDjango.2017:

1-29

英文8701单词,40127字符,中文12987汉字。

IntroductiontotheDjangoFramework

DanielRubio

TheDjangoframeworkstartedin2003,asaprojectdonebyAdrianHolovatyandSimonWillisonattheJournal-WorldnewspaperinLawrence,Kansas,intheUnitedStates.In2005,HolovatyandWillisonreleasedthefirstpublicversionoftheframework,namingitaftertheBelgian-FrenchguitaristDjangoReinhardt.

Fastforwardto2017–theDjangoframeworknowoperatesundertheguidanceoftheDjangoSoftwareFoundation(DSF),theframeworkcorehasover1000contributorswithmorethan15releaseversions,andthereareover3000packagesspecificallydesignedtoworkwiththeDjangoframework.1

TheDjangoframeworkhasremainedtruetoitsoriginsasaModel-View-Controller(MVC)server-sideframeworkdesignedtooperatewithrelationaldatabases.Nevertheless,Djangohasstayeduptodatewithmostwebdevelopmenttendencies–viathird-partypackages–tooperatealongsidetechnologieslikenon-relationaldatabases(NoSQL),real-timeInternetcommunication,andmodernJavaScriptpractices.Allthistothepoint,theDjangoframeworkisnowthewebdevelopmentframeworkofchoiceforawidearrayoforganizations,includingthephotosharingsitesInstagram2andPinterest3;thePublicBroadcastingSystem(PBS)4;intheUnitedStates,NationalGeographic5;andwiththehelpofthisbook,yourorganization!

Inthischapteryou’lllearnabouttheDjangoframeworkdesignprinciples,whicharekeytounderstandingtheday-to-dayaspectsofworkingwiththeDjangoframework.Next,you’lllearnhowtoinstallDjangoinvariousways:

asatar.gzfile,withpip,

usinggit,andwithvirtualenv.

OnceyouinstalltheDjangoframework,you’lllearnhowtostartaDjangoprojectandhowtosetitupwitharelationaldatabase.Next,you’lllearnaboutthecorebuildingblocksintheDjangoframework–urls,templates,andapps–andhowtheyworkwithoneanothertosetupcontent.Finally,you’lllearnhowtosetuptheDjangoadminsite,whichisaweb-basedinterfacedesignedtoaccesstherelationaldatabaseconnectedtoaDjangoproject.

DjangoFrameworkDesignPrinciples

Ifyouworklongenoughinwebdevelopment,you’lleventuallycometotheconclusionthatyoucanproducethesameresultswithjustaboutanywebframeworkandprogramminglanguage.Butwhileyoucan,infact,produceidenticalresults,whatwillvarydrasticallyisthetimeyouspendcreatingasolution:

thetimecreatingaprototype,thetimeaddingnewfeatures,thetimedoingtesting,thetimedoingdebugging,andthetimedeployingtoscale,amongotherthings.

Inthissense,theDjangoframeworkusesasetofdesignprinciplesthatproducesoneofthemostproductivewebdevelopmentprocessescomparedtomanyotherwebframeworks.Note,I’mnotsayingDjangoisasilverbullet(e.g.,thebestatprototyping,themostscalable);I’msayingthatattheendoftheday,theDjangoframeworkincorporatesasetofdesignprinciplesandtrade-offsthatmakeitoneofthemostproductiveframeworksforbuildingthefeaturesneededbymostmediumtolargewebapplications.Now,whileyoumightthinkI’mbiased–afterallI’mwritinganentirebookaboutthetopic–I’lllayoutthesedesignprinciplesfirst,soyoucangainabetterunderstandingofwhatgivestheDjangoframeworkthisedge.

Don’tRepeatYourself(DRY)Principle

Repetitionmightbegoodtoemphasizeapoint,butwhenitcomestowebdevelopment,itjustleadstoadditionalandtime-consumingwork.Infact,theverynatureofwebdevelopment,whichoperatesacrossmultipletiersinteractingwithoneanother(e.g.,HTMLtemplates,businesslogicmethods,anddatabases),lendsitselftorepetition.

TheDjangoframeworkreallytriestoforceyounottorepeatyourself,solet’sseehowDjangoenforcesnotrepeatingyourselfandwhythisisagoodthing.Let’ssayyouwanttobuildacoffeehouseapplicationtopublishinformationaboutstoresandalsohaveacontactformforcustomers.Thefirstthingyou’llneedtodoisdeterminewhatkindofinformationisrequiredforstoresandthecontactform.Figure1-1illustratesa

mock-upoftwoDjangomodelsforeachoftheseentities.

Figure1-1.Djangomodelsforstoreandcontactentities

NoticehowtheDjangomodelsinFigure1-1eachhavedifferentfieldnamesandadatatypetorestrictvalues.Forexample,thestatementname=models.CharField(max_length=30)tellsDjangoastorenameshouldhaveamaximumof30characters,whilethestatementemail=models.EmailField()tellsDjangothecontactentityshouldcontainavalidemailvalue.Ifthecoffeehouseislikemostwebapplications,you’llgenerallyendupdoingthefollowingforthestoreandcontactentities:

•Createrelationaldatabasetablestosaveentityinformation.

•Createbusinesslogictoensuretheentitiescomplywithrequirements.

•CreateHTMLformstoallowdatatobesubmittedfortheentities.

•Createaninterfacetoallowadministrativeuserstoaccessentitiesinthedatabase.

•CreateRESTservicestoexposeentitiesforamobileappversion.

Thecruxofdoingthislasttasklistisyouhavethepotentialofrepeatingdozensofsimilarpiecesofinformation(e.g.,names,valuelimits)indatabasedefinitionlanguage(DDL),HTMLforms,businessvalidationlogic,andURLs,amongotherthings–processthat’snotonlytimeconsuming,butalsoerrorprone.Wouldn’titbeeasierthatbasedonastatementlikemodels.CharField(max_length=30)youcouldgenerateanHTMLforminput,aDDLstatement,andautomaticallyvalidateinformationtoonlycontain30characters?

ThisisexactlywhatDjango’sDRYdesignprincipledoes.Figure1-2illustratesthesameDjangomodelsfromFigure1-1andthevariousconstructsyoucangeneratefromthesamemodelswithouttheneedtorepeatyourself.

Figure1-2.DjangomodelscreateseparateconstructsbasedonDRYprinciple

AsyoucanseeinFigure1-2,theentitiesthatrepresentDjangomodelsarecapableofgeneratingHTMLformstopresenttothepublic,anadministrativeinterfacetomanagetheentities,validationlogictoenforceentityvalues,aswellastheDDLtogeneratedatabasetablesrepresentingtheentities.

Whileit’salittleprematuretodiscusstheactualtechniquestogeneratesuchconstructsfromDjangomodels,needlesstosayit’smuchsimplerthankeepingtrackofmultiplereferencesofthesamething(e.g.,name,email)inHTMLforms,DDL,validationlogic,andotherlocations.

Inthissense,Djangoreallyhelpsyoudefinethingsinasingleplaceandnothavetorepeatthemelsewhere.Notethatit’salwayspossibletorepeatyourselftoobtaincustombehaviors,butbydefault,DjangoenforcesDRYprinciplesinnearlyeverythingyoudowithit.

ExplicitIsBetterThanImplicit

Python,theprogramminglanguageusedbyDjango,hasamantra-likestatementcalled“TheZenofPython”definedaspartofthelanguage’sPythonEnhancement

Proposals(PEP),specificallyPEP20.6OneofthestatementsinPEP20states“Explicitisbetterthanimplicit”andwithDjangobeingbasedonPython,thisprincipleisalsotakentoheart.

Beingexplicitleadstowebapplicationsthatareeasilyunderstoodandmaintainedbyagreaternumberofpeople.Addingnewfeaturesorunderstandingthelogicbehindawebapplicationcanbehardenoughforsomeonethatdidn’twriteitoriginally,butifyoutossintothemixconstructsthathaveimplicitbehaviors,usersonlyfacegreaterfrustrationtryingtofigureoutwhat’sbeingdoneimplicitly.Explicitdoesrequirealittlemoreworktyping,butit’swellworthitwhenyoucompareittothepotentialeffortyoucanfacetryingtodebugorsolveaproblem.

Let’stakeaquicklookatDjango’sexplicitnessinacommonwebdevelopmentconstructusedacrossdifferentMVCframeworks:

aviewmethod.AviewmethodactsastheC(ontroller)inanMVCframework,chargedwithhandlingincomingrequests,applyingbusinesslogic,andthenroutingrequestswithanappropriateresponse.

Togetabetterfeelforthisexplicitness,I’llpresentaDjangoviewmethodandanequivalentRubyonRailsviewmethodthatperformsthesamelogicoffetchingastorebyagivenidandroutingtheresponsetoatemplate.ThefollowingsnippetistheRubyonRailsversion;notethelineswith#thatarecommentsandindicatewhat’shappening.

classStoresController

#Automaticaccesstoparams,arubyhashwithrequestparametersandviewparameters@store=Store.find(params[:

id])

#Instancevariableslike@storeareautomaticallypassedontoviewtemplate

#Automaticallyusestemplateviews/stores/show.html.erbend

end

Althoughverysuccinct,noticealltheimplicitbehaviorsurroundingtheprocesstoaccessdata,passdatatoatemplate,andassignatemplate.ThefollowingsnippetisanequivalentDjangoviewmethod.

#Explicitrequestvariablecontainsrequestparameters

#Otherviewparametersmustbeexplicitlypassedtoviewsdefdetail(request,store_id):

store=Store.objects.get(id=store_id)

#Instancevariablesmustbeexplicitlypassedontoaviewtemplate#Explicittemplatemustbeassigned

returnrender(request,'stores/detail.html',{'store':

store})

Noticeinthislastsnippetthere’snoguessingwhereinputparameterscomefrom,they’reexplicitlydeclar

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2