匿名用户2021年12月10日
164阅读

技术信息

授权协议
MIT License

作品详情

Slapdash

Boilerplateforbootstrappigscalablemulti-pageDashapplicatios

DashisaPythoframeworkforbuildigaalyticalwebapplicatios.Slapdashprovidesasesibleprojectlayoutforquicklybuildigoutamulti-pageDashapplicatiowithroomforgrowth.Italsoicludes:

Pre-builtlayoutsbasedoBootstrap(withthehelpofDashBootstrapCompoets),whichcabeextededorswappedoutforlayoutscostructedusigyourowDash/CSScompoets.ScriptsforcoveietlylauchigyourappibothdevadprodevirometsAURLrouterthathelpsyoumaageyourapplicatio'spages

ThisprojectisitededforbootstrappigiitialDashapplicatios,ratherthabeigadepedecyforyourapplicatio.Youshould'tassumethatSlapdash'siteralstructureaditerfaceswillbestable,astheywillchage.

BoilerplateOverview__iit__.pyCotaishelperfuctiosforcreatigtheFlaskadDashistaces.app.pyEtrypoititotheapp.CreatesboththeFlaskadDashistacesusedfortheappadtheimportstherestoftheappthroughtheidexmodule.idex.pyURLroutesadtherouteraredefiedhere,alogwiththeavbaraditscorrespodigetries.wsgi.pyCotaistheFlaskapplicatioattributesuitableforpoitigWSGIserversat.settigs.pyCofigurablesettigsfortheapplicatio.prod_settigs.pyCofigurablesettigsforruigtheapplicatioiaproductioeviromet.Settigsdefiedherewilltakeprecedeceoverthosefoudisettigs.py.exceptios.pyExceptiosusedbyyourappcabedefiedhere.compoets.pyCoveietPythopseudo-compoetsaredefiedhere.utils.pyUtilitythigs.pagesThesuggestedprojectlayoutistoplaceeachpageofyourappwithithisdirectory,treatigeachpageasamodularsub-appcotaiigalayoutsattributethatyoucaregisterwiththerouteriidex.py.assetsLocatioforstaticassetsthatwillbeexposedtothewebserver.Istallatio

Note:SlapdashrequiresPytho3.6+

SlapdashisaCookiecutterproject.ThismeasyoufirsteedtogeerateyourowprojectfromtheSlapdashprojecttemplate.

IstallthelatestCookiecutterifyouhave'tistalledityet:

pipistall-Ucookiecutter

Geerateyourprojectbyruigthiscommadadfollowigtheprompts:

cookiecutterhttps://github.com/ed2/slapdash

TheresultigprojectisaPythopackage,whichyoutheeedtoistalllikeso:

$pipistallPATH_TO_PROJECT

Durigdevelopmetyouwilllikelywattoperformaeditableistallsothatchagestothesourcecodetakeimmediateeffectotheistalledpackage.

$pipistall-ePATH_TO_PROJECTUsageIapp.py,selectthemailayoutyouwatfromlayouts.py.Createthepagesofyourappidifferetfileswithithepagesdirectory,bydefiigwithieachatop-levellayoutattributeadcallbacksregisteredwiththeDashappistacefromtheappmodule.AddthepagesofyourapptotheURLrouteriidex.py.Addaydesiredpagestoavbariidex.py.Modifyassets/slapdash.cssoraddadditioalstylesheetsiassets.Modifycofigisettigs.pyasrequired.TheURLRouter

SlapdashusesDash'sbuilt-isupportforcreatigmulti-pageapps.Thisivolvescreatigacallbackthattargetsacotaierhtml.Diviyourlayout,adijectslayoutfragmetsitothechildrepropertyofthecotaierwheusersclickolikscostructedwithdcc.Lik.SlapdashprovidesacoveiececlassDashRouter,whichassistswiththecostructioofthiscallback.Thefollowigsippetprovidesaexampleofitsuse:

urls=(("",page1.layout),("page1",page1.layout),("page2",page2.layout),("page3",page3.get_layout),)router=DashRouter(app,urls)

TheDashRouterclasstakesasiputaDashistace,adasequeceofURLtuples,whereeachtuplecotaisastrigrepresetigtheURLedpoitforthepageasthefirstitem,adthelayoutfragmettoassociatewiththatURLasthesecod.ThelayoutfragmetcaeitherbeaistaceofDash'sCompoetclass(suchasahtml.Div)oracallablethatretursaCompoetistace,suchasthefuctioget_layoutitheabovesippet.Thiscallableshouldtakeavariableumberofkeywordargumets,asayqueryparameterspresetitheURLwillbepasseditothelayoutcallableaskeywordargumets.forexampleyoucouldpassvaluesitothelayoutfuctiobelowusigtheURLhttps://hostame?param1=value1&param2=value2.

defget_layout(**query_params):param1_value=query_params.get("param1","param1otprovided")param2_value=query_params.get("param2","param1otprovided")returhtml.Div([param1_value,param2_value])

NotethattheURLedpoitswillbeautomaticallyprefixedwithDash's'routes_pathame_prefix'parameter,sowhespecifyigiteralURLlikswithiyourlayout,youwillwattouseutil.get_urlwhichprefixestheURLpathforyou.

LoadigSpiers

SlapdashcomeswithsomeCSSloadigspiersbuilt-i.Iordertousethem,simplyaddoeoftheclassesloaderorloader-fadetothecompoetyouwattobevisuallyrederedasloadigwhileitiswaitigforacallbacktocomplete.Bothspierswillwaitoesecodbeforebeigappliedtoavoidaupleasatflickerigeffectforresposivecallbacks.Theloaderspierwillhidethecotetsofthecompoetaddisplayaspier,whiletheloader-fadewillreducetheopacityofthecompoet'scotetsadalsodisplayaspier.

RuigYourApp

Thisprojectcomeswithtwocoveiecescriptsforruigyourprojectidevelopmetadproductioeviromets,oryoucauseyourowWSGIservertorutheapp.

RuDevApp

Istalligthispackageitoyourvirtualevwillresultitothedevelopmetexecutablebeigistalleditoyourpathwhethevirtualevisactivated.ThiscommadivokesyourDashapp'sru_servermethod,whichiturusestheFlaskdevelopmetservertoruyourapp.Thecommadisivokedasfollows,withproj_slugbeigreplacedbythevalueprovidedforthiscookiecutterparameter.

$ru-project_slug-dev

Thescripttakesacoupleofargumetsoptioalparameters,whichyoucadiscoverwiththe--helpflag.Youmayeedtosettheportusigthe--portparameter.Ifyoueedtoexposeyourappoutsideyourlocalmachie,youwillwattoset--host0.0.0.0.

RuProdApp

Whilecoveiet,thedevelopmetwebservershouldotbeusediproductio.Istalligthispackagewillalsoresultiaproductioexecutablebeigistallediyourvirtualev.Thisisawrapperaroudthemod_wsgi-expresscommad,whichstreamliesuseofthemod_wsgiApachemoduletoruyouryourapp.Iadditiotoistalligthemod_wsgiPythopackage,youwilleedtohaveistalledApache.Seeistallatioistructiosithemod_wsgidocumetatio.Thisscriptalsotakesarageofcommadlieargumets,whichcabediscoveredwiththe--helpflag.

$ru-project_slug-prod

Thisscriptwillalsoapplysettigsfoudithemoduleproject_slug.prod_settigs(oracustomPythofilesuppliedwiththe--settigsflag)adwhichtakesprecedeceoverthesamesettigsfoudiproject_slug.settigs.

Aotableadvatageofusigmod_wsgioverotherWSGIserversisthatwedooteedtocofigureadruawebserverseparatetotheWSGIserver.WheusigotherWSGIservers(suchasGuicororuWSGI),youdootwattoexposethemdirectlytowebrequestsfromtheoutsideworldfortworeasos:1)icomigrequestswillotbebuffered,exposigyoutopotetialdeialofserviceattacks,ad2)youwillbeservigyourstaticassetsviaDash'sFlaskistace,whichisslow.Theproductioscriptusesmod_wsgi-expresstospiupaApacheprocess(separatetoayprocessalreadyruigadlisteigoport80)thatwillbufferrequests,passigthemofftotheworkerprocessesruigyourapp,adwillalsosetuptheApacheistacetoserveyourstaticassetsmuchfasterthawouldbethecasethroughthePythoworkerprocesses.

Note:Youwilleedtoreistallthispackageiorderforchagestotheprodscripttotakeeffecteveifyouusedaeditableistall(iepipistall-e).

RuigwithadifferetWSGIServer

YoucaeasilyruyourappusigaWSGIserverofyourchoice(suchasGuicorforexample)withtheproject_slug.wsgietrypoit(defiediwsgi.py)likeso:

$guicorproject_slug.wsgi

Note:ifyouwattoeableDash'sdebugmodewhileruigwithaWSGIserver,you'lleedtoexporttheDASH_DEBUGevirometvariabletotrue.SeetheDevToolssectiooftheDashDocsformoredetails.

IcludedLibraries

Slapdashicludesafewlibrariesforgettigfullyfuctioalapplicatiosoffthegroudfaster.Theseiclude:

DashBootstrapCompoets:AsuiteofDashcompoetsthatwrapBootstrapclasses,allowigforcleaeritegratioofBootstrapwithDashlayouts.Bootstrap-LocalcopyofBootstrapCSSfilessoyoucarutheappofflie.FotAwesome-LocalcopyofFotAwesomefilesforofflieaccess.Becauseeveryoewatsprettyicos.UsefulRefereces

TheDashUserGuide

PlotlyPythoclietfigurerefereceDocumetsthecotetsofplotly.graph_objs,whichcotaisthedifferettypesofchartsavailable,aswelltheLayoutclass,forcustomisigtheappearaceofcharts.

TheDashCommuityForum

DashShowadTellCommuityThread

TheDashGitHubRepository

Cotributig

PRsarewelcome!Ifyouhavebroaderchagesimid,thecreatigaissuefirstfordiscussiowouldbebest.

SeetigupaDevEviromet

AfterchagigdirectorytothetoplevelSlapdashdirectory:

IstallSlapdashitoyourvirtualev:$pipistall-e.Istallthedevelopmetrequiremets:$pipistall-rrequiremets-dev.txtIstallthepre-commithook(fortheBlackcodeformatter)$pre-commitistall

功能介绍

Slapdash Boilerplate for bootstrapping scalable multi-page Dash applications Dash is a Python fra...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论