flask.html 349 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>flask package &#8212; proxypool documentation</title>
  7. <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
  8. <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '../',
  12. VERSION: '',
  13. COLLAPSE_INDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="../_static/jquery.js"></script>
  19. <script type="text/javascript" src="../_static/underscore.js"></script>
  20. <script type="text/javascript" src="../_static/doctools.js"></script>
  21. <link rel="index" title="Index" href="../genindex.html" />
  22. <link rel="search" title="Search" href="../search.html" />
  23. <link rel="top" title="proxypool documentation" href="../index.html" />
  24. <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  25. <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
  26. </head>
  27. <body role="document">
  28. <div class="document">
  29. <div class="documentwrapper">
  30. <div class="bodywrapper">
  31. <div class="body" role="main">
  32. <div class="section" id="flask-package">
  33. <h1>flask package<a class="headerlink" href="#flask-package" title="Permalink to this headline">¶</a></h1>
  34. <div class="section" id="subpackages">
  35. <h2>Subpackages<a class="headerlink" href="#subpackages" title="Permalink to this headline">¶</a></h2>
  36. <div class="toctree-wrapper compound">
  37. <ul>
  38. <li class="toctree-l1"><a class="reference internal" href="flask.ext.html">flask.ext package</a><ul>
  39. <li class="toctree-l2"><a class="reference internal" href="flask.ext.html#module-flask.ext">Module contents</a><ul>
  40. <li class="toctree-l3"><a class="reference internal" href="flask.ext.html#flask-ext">flask.ext</a></li>
  41. </ul>
  42. </li>
  43. </ul>
  44. </li>
  45. </ul>
  46. </div>
  47. </div>
  48. <div class="section" id="submodules">
  49. <h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this headline">¶</a></h2>
  50. </div>
  51. <div class="section" id="module-flask.app">
  52. <span id="flask-app-module"></span><h2>flask.app module<a class="headerlink" href="#module-flask.app" title="Permalink to this headline">¶</a></h2>
  53. <div class="section" id="flask-app">
  54. <h3>flask.app<a class="headerlink" href="#flask-app" title="Permalink to this headline">¶</a></h3>
  55. <p>This module implements the central WSGI application object.</p>
  56. <table class="docutils field-list" frame="void" rules="none">
  57. <col class="field-name" />
  58. <col class="field-body" />
  59. <tbody valign="top">
  60. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  61. <li>2015 by Armin Ronacher.</li>
  62. </ol>
  63. </td>
  64. </tr>
  65. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  66. </td>
  67. </tr>
  68. </tbody>
  69. </table>
  70. <dl class="class">
  71. <dt id="flask.app.Flask">
  72. <em class="property">class </em><code class="descclassname">flask.app.</code><code class="descname">Flask</code><span class="sig-paren">(</span><em>import_name</em>, <em>static_path=None</em>, <em>static_url_path=None</em>, <em>static_folder='static'</em>, <em>template_folder='templates'</em>, <em>instance_path=None</em>, <em>instance_relative_config=False</em>, <em>root_path=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask" title="Permalink to this definition">¶</a></dt>
  73. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">flask.helpers._PackageBoundObject</span></code></p>
  74. <p>The flask object implements a WSGI application and acts as the central
  75. object. It is passed the name of the module or package of the
  76. application. Once it is created it will act as a central registry for
  77. the view functions, the URL rules, template configuration and much more.</p>
  78. <p>The name of the package is used to resolve resources from inside the
  79. package or the folder the module is contained in depending on if the
  80. package parameter resolves to an actual python package (a folder with
  81. an <code class="file docutils literal"><span class="pre">__init__.py</span></code> file inside) or a standard module (just a <code class="docutils literal"><span class="pre">.py</span></code> file).</p>
  82. <p>For more information about resource loading, see <code class="xref py py-func docutils literal"><span class="pre">open_resource()</span></code>.</p>
  83. <p>Usually you create a <a class="reference internal" href="#flask.app.Flask" title="flask.app.Flask"><code class="xref py py-class docutils literal"><span class="pre">Flask</span></code></a> instance in your main module or
  84. in the <code class="file docutils literal"><span class="pre">__init__.py</span></code> file of your package like this:</p>
  85. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">flask</span> <span class="k">import</span> <span class="n">Flask</span>
  86. <span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span>
  87. </pre></div>
  88. </div>
  89. <div class="admonition-about-the-first-parameter admonition">
  90. <p class="first admonition-title">About the First Parameter</p>
  91. <p>The idea of the first parameter is to give Flask an idea of what
  92. belongs to your application. This name is used to find resources
  93. on the filesystem, can be used by extensions to improve debugging
  94. information and a lot more.</p>
  95. <p>So it&#8217;s important what you provide there. If you are using a single
  96. module, <cite>__name__</cite> is always the correct value. If you however are
  97. using a package, it&#8217;s usually recommended to hardcode the name of
  98. your package there.</p>
  99. <p>For example if your application is defined in <code class="file docutils literal"><span class="pre">yourapplication/app.py</span></code>
  100. you should create it with one of the two versions below:</p>
  101. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="s1">&#39;yourapplication&#39;</span><span class="p">)</span>
  102. <span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="n">__name__</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
  103. </pre></div>
  104. </div>
  105. <p class="last">Why is that? The application will work even with <cite>__name__</cite>, thanks
  106. to how resources are looked up. However it will make debugging more
  107. painful. Certain extensions can make assumptions based on the
  108. import name of your application. For example the Flask-SQLAlchemy
  109. extension will look for the code in your application that triggered
  110. an SQL query in debug mode. If the import name is not properly set
  111. up, that debugging information is lost. (For example it would only
  112. pick up SQL queries in <cite>yourapplication.app</cite> and not
  113. <cite>yourapplication.views.frontend</cite>)</p>
  114. </div>
  115. <div class="versionadded">
  116. <p><span class="versionmodified">New in version 0.7: </span>The <cite>static_url_path</cite>, <cite>static_folder</cite>, and <cite>template_folder</cite>
  117. parameters were added.</p>
  118. </div>
  119. <div class="versionadded">
  120. <p><span class="versionmodified">New in version 0.8: </span>The <cite>instance_path</cite> and <cite>instance_relative_config</cite> parameters were
  121. added.</p>
  122. </div>
  123. <div class="versionadded">
  124. <p><span class="versionmodified">New in version 0.11: </span>The <cite>root_path</cite> parameter was added.</p>
  125. </div>
  126. <table class="docutils field-list" frame="void" rules="none">
  127. <col class="field-name" />
  128. <col class="field-body" />
  129. <tbody valign="top">
  130. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  131. <li><strong>import_name</strong> &#8211; the name of the application package</li>
  132. <li><strong>static_url_path</strong> &#8211; can be used to specify a different path for the
  133. static files on the web. Defaults to the name
  134. of the <cite>static_folder</cite> folder.</li>
  135. <li><strong>static_folder</strong> &#8211; the folder with static files that should be served
  136. at <cite>static_url_path</cite>. Defaults to the <code class="docutils literal"><span class="pre">'static'</span></code>
  137. folder in the root path of the application.</li>
  138. <li><strong>template_folder</strong> &#8211; the folder that contains the templates that should
  139. be used by the application. Defaults to
  140. <code class="docutils literal"><span class="pre">'templates'</span></code> folder in the root path of the
  141. application.</li>
  142. <li><strong>instance_path</strong> &#8211; An alternative instance path for the application.
  143. By default the folder <code class="docutils literal"><span class="pre">'instance'</span></code> next to the
  144. package or module is assumed to be the instance
  145. path.</li>
  146. <li><strong>instance_relative_config</strong> &#8211; if set to <code class="docutils literal"><span class="pre">True</span></code> relative filenames
  147. for loading the config are assumed to
  148. be relative to the instance path instead
  149. of the application root.</li>
  150. <li><strong>root_path</strong> &#8211; Flask by default will automatically calculate the path
  151. to the root of the application. In certain situations
  152. this cannot be achieved (for instance if the package
  153. is a Python 3 namespace package) and needs to be
  154. manually defined.</li>
  155. </ul>
  156. </td>
  157. </tr>
  158. </tbody>
  159. </table>
  160. <dl class="method">
  161. <dt id="flask.app.Flask.add_template_filter">
  162. <code class="descname">add_template_filter</code><span class="sig-paren">(</span><em>f</em>, <em>name=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.add_template_filter"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.add_template_filter" title="Permalink to this definition">¶</a></dt>
  163. <dd><p>Register a custom template filter. Works exactly like the
  164. <a class="reference internal" href="#flask.app.Flask.template_filter" title="flask.app.Flask.template_filter"><code class="xref py py-meth docutils literal"><span class="pre">template_filter()</span></code></a> decorator.</p>
  165. <table class="docutils field-list" frame="void" rules="none">
  166. <col class="field-name" />
  167. <col class="field-body" />
  168. <tbody valign="top">
  169. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> &#8211; the optional name of the filter, otherwise the
  170. function name will be used.</td>
  171. </tr>
  172. </tbody>
  173. </table>
  174. </dd></dl>
  175. <dl class="method">
  176. <dt id="flask.app.Flask.add_template_global">
  177. <code class="descname">add_template_global</code><span class="sig-paren">(</span><em>f</em>, <em>name=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.add_template_global"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.add_template_global" title="Permalink to this definition">¶</a></dt>
  178. <dd><p>Register a custom template global function. Works exactly like the
  179. <a class="reference internal" href="#flask.app.Flask.template_global" title="flask.app.Flask.template_global"><code class="xref py py-meth docutils literal"><span class="pre">template_global()</span></code></a> decorator.</p>
  180. <div class="versionadded">
  181. <p><span class="versionmodified">New in version 0.10.</span></p>
  182. </div>
  183. <table class="docutils field-list" frame="void" rules="none">
  184. <col class="field-name" />
  185. <col class="field-body" />
  186. <tbody valign="top">
  187. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> &#8211; the optional name of the global function, otherwise the
  188. function name will be used.</td>
  189. </tr>
  190. </tbody>
  191. </table>
  192. </dd></dl>
  193. <dl class="method">
  194. <dt id="flask.app.Flask.add_template_test">
  195. <code class="descname">add_template_test</code><span class="sig-paren">(</span><em>f</em>, <em>name=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.add_template_test"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.add_template_test" title="Permalink to this definition">¶</a></dt>
  196. <dd><p>Register a custom template test. Works exactly like the
  197. <a class="reference internal" href="#flask.app.Flask.template_test" title="flask.app.Flask.template_test"><code class="xref py py-meth docutils literal"><span class="pre">template_test()</span></code></a> decorator.</p>
  198. <div class="versionadded">
  199. <p><span class="versionmodified">New in version 0.10.</span></p>
  200. </div>
  201. <table class="docutils field-list" frame="void" rules="none">
  202. <col class="field-name" />
  203. <col class="field-body" />
  204. <tbody valign="top">
  205. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> &#8211; the optional name of the test, otherwise the
  206. function name will be used.</td>
  207. </tr>
  208. </tbody>
  209. </table>
  210. </dd></dl>
  211. <dl class="method">
  212. <dt id="flask.app.Flask.add_url_rule">
  213. <code class="descname">add_url_rule</code><span class="sig-paren">(</span><em>rule</em>, <em>endpoint=None</em>, <em>view_func=None</em>, <em>**options</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.add_url_rule"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.add_url_rule" title="Permalink to this definition">¶</a></dt>
  214. <dd><p>Connects a URL rule. Works exactly like the <a class="reference internal" href="#flask.app.Flask.route" title="flask.app.Flask.route"><code class="xref py py-meth docutils literal"><span class="pre">route()</span></code></a>
  215. decorator. If a view_func is provided it will be registered with the
  216. endpoint.</p>
  217. <p>Basically this example:</p>
  218. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>
  219. <span class="k">def</span> <span class="nf">index</span><span class="p">():</span>
  220. <span class="k">pass</span>
  221. </pre></div>
  222. </div>
  223. <p>Is equivalent to the following:</p>
  224. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">index</span><span class="p">():</span>
  225. <span class="k">pass</span>
  226. <span class="n">app</span><span class="o">.</span><span class="n">add_url_rule</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">,</span> <span class="s1">&#39;index&#39;</span><span class="p">,</span> <span class="n">index</span><span class="p">)</span>
  227. </pre></div>
  228. </div>
  229. <p>If the view_func is not provided you will need to connect the endpoint
  230. to a view function like so:</p>
  231. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">view_functions</span><span class="p">[</span><span class="s1">&#39;index&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">index</span>
  232. </pre></div>
  233. </div>
  234. <p>Internally <a class="reference internal" href="#flask.app.Flask.route" title="flask.app.Flask.route"><code class="xref py py-meth docutils literal"><span class="pre">route()</span></code></a> invokes <a class="reference internal" href="#flask.app.Flask.add_url_rule" title="flask.app.Flask.add_url_rule"><code class="xref py py-meth docutils literal"><span class="pre">add_url_rule()</span></code></a> so if you want
  235. to customize the behavior via subclassing you only need to change
  236. this method.</p>
  237. <p>For more information refer to <span class="xref std std-ref">url-route-registrations</span>.</p>
  238. <div class="versionchanged">
  239. <p><span class="versionmodified">Changed in version 0.2: </span><cite>view_func</cite> parameter added.</p>
  240. </div>
  241. <div class="versionchanged">
  242. <p><span class="versionmodified">Changed in version 0.6: </span><code class="docutils literal"><span class="pre">OPTIONS</span></code> is added automatically as method.</p>
  243. </div>
  244. <table class="docutils field-list" frame="void" rules="none">
  245. <col class="field-name" />
  246. <col class="field-body" />
  247. <tbody valign="top">
  248. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  249. <li><strong>rule</strong> &#8211; the URL rule as string</li>
  250. <li><strong>endpoint</strong> &#8211; the endpoint for the registered URL rule. Flask
  251. itself assumes the name of the view function as
  252. endpoint</li>
  253. <li><strong>view_func</strong> &#8211; the function to call when serving a request to the
  254. provided endpoint</li>
  255. <li><strong>options</strong> &#8211; the options to be forwarded to the underlying
  256. <code class="xref py py-class docutils literal"><span class="pre">Rule</span></code> object. A change
  257. to Werkzeug is handling of method options. methods
  258. is a list of methods this rule should be limited
  259. to (<code class="docutils literal"><span class="pre">GET</span></code>, <code class="docutils literal"><span class="pre">POST</span></code> etc.). By default a rule
  260. just listens for <code class="docutils literal"><span class="pre">GET</span></code> (and implicitly <code class="docutils literal"><span class="pre">HEAD</span></code>).
  261. Starting with Flask 0.6, <code class="docutils literal"><span class="pre">OPTIONS</span></code> is implicitly
  262. added and handled by the standard request handling.</li>
  263. </ul>
  264. </td>
  265. </tr>
  266. </tbody>
  267. </table>
  268. </dd></dl>
  269. <dl class="method">
  270. <dt id="flask.app.Flask.after_request">
  271. <code class="descname">after_request</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.after_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.after_request" title="Permalink to this definition">¶</a></dt>
  272. <dd><p>Register a function to be run after each request.</p>
  273. <p>Your function must take one parameter, an instance of
  274. <a class="reference internal" href="#flask.app.Flask.response_class" title="flask.app.Flask.response_class"><code class="xref py py-attr docutils literal"><span class="pre">response_class</span></code></a> and return a new response object or the
  275. same (see <a class="reference internal" href="#flask.app.Flask.process_response" title="flask.app.Flask.process_response"><code class="xref py py-meth docutils literal"><span class="pre">process_response()</span></code></a>).</p>
  276. <p>As of Flask 0.7 this function might not be executed at the end of the
  277. request in case an unhandled exception occurred.</p>
  278. </dd></dl>
  279. <dl class="attribute">
  280. <dt id="flask.app.Flask.after_request_funcs">
  281. <code class="descname">after_request_funcs</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.after_request_funcs" title="Permalink to this definition">¶</a></dt>
  282. <dd><p>A dictionary with lists of functions that should be called after
  283. each request. The key of the dictionary is the name of the blueprint
  284. this function is active for, <code class="docutils literal"><span class="pre">None</span></code> for all requests. This can for
  285. example be used to close database connections. To register a function
  286. here, use the <a class="reference internal" href="#flask.app.Flask.after_request" title="flask.app.Flask.after_request"><code class="xref py py-meth docutils literal"><span class="pre">after_request()</span></code></a> decorator.</p>
  287. </dd></dl>
  288. <dl class="method">
  289. <dt id="flask.app.Flask.app_context">
  290. <code class="descname">app_context</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.app_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.app_context" title="Permalink to this definition">¶</a></dt>
  291. <dd><p>Binds the application only. For as long as the application is bound
  292. to the current context the <code class="xref py py-data docutils literal"><span class="pre">flask.current_app</span></code> points to that
  293. application. An application context is automatically created when a
  294. request context is pushed if necessary.</p>
  295. <p>Example usage:</p>
  296. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">app</span><span class="o">.</span><span class="n">app_context</span><span class="p">():</span>
  297. <span class="o">...</span>
  298. </pre></div>
  299. </div>
  300. <div class="versionadded">
  301. <p><span class="versionmodified">New in version 0.9.</span></p>
  302. </div>
  303. </dd></dl>
  304. <dl class="attribute">
  305. <dt id="flask.app.Flask.app_ctx_globals_class">
  306. <code class="descname">app_ctx_globals_class</code><a class="headerlink" href="#flask.app.Flask.app_ctx_globals_class" title="Permalink to this definition">¶</a></dt>
  307. <dd><p>The class that is used for the <code class="xref py py-data docutils literal"><span class="pre">g</span></code> instance.</p>
  308. <p>Example use cases for a custom class:</p>
  309. <ol class="arabic simple">
  310. <li>Store arbitrary attributes on flask.g.</li>
  311. <li>Add a property for lazy per-request database connectors.</li>
  312. <li>Return None instead of AttributeError on unexpected attributes.</li>
  313. <li>Raise exception if an unexpected attr is set, a &#8220;controlled&#8221; flask.g.</li>
  314. </ol>
  315. <p>In Flask 0.9 this property was called <cite>request_globals_class</cite> but it
  316. was changed in 0.10 to <a class="reference internal" href="#flask.app.Flask.app_ctx_globals_class" title="flask.app.Flask.app_ctx_globals_class"><code class="xref py py-attr docutils literal"><span class="pre">app_ctx_globals_class</span></code></a> because the
  317. flask.g object is now application context scoped.</p>
  318. <div class="versionadded">
  319. <p><span class="versionmodified">New in version 0.10.</span></p>
  320. </div>
  321. <p>alias of <code class="xref py py-class docutils literal"><span class="pre">_AppCtxGlobals</span></code></p>
  322. </dd></dl>
  323. <dl class="method">
  324. <dt id="flask.app.Flask.auto_find_instance_path">
  325. <code class="descname">auto_find_instance_path</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.auto_find_instance_path"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.auto_find_instance_path" title="Permalink to this definition">¶</a></dt>
  326. <dd><p>Tries to locate the instance path if it was not provided to the
  327. constructor of the application class. It will basically calculate
  328. the path to a folder named <code class="docutils literal"><span class="pre">instance</span></code> next to your main file or
  329. the package.</p>
  330. <div class="versionadded">
  331. <p><span class="versionmodified">New in version 0.8.</span></p>
  332. </div>
  333. </dd></dl>
  334. <dl class="method">
  335. <dt id="flask.app.Flask.before_first_request">
  336. <code class="descname">before_first_request</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.before_first_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.before_first_request" title="Permalink to this definition">¶</a></dt>
  337. <dd><p>Registers a function to be run before the first request to this
  338. instance of the application.</p>
  339. <p>The function will be called without any arguments and its return
  340. value is ignored.</p>
  341. <div class="versionadded">
  342. <p><span class="versionmodified">New in version 0.8.</span></p>
  343. </div>
  344. </dd></dl>
  345. <dl class="attribute">
  346. <dt id="flask.app.Flask.before_first_request_funcs">
  347. <code class="descname">before_first_request_funcs</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.before_first_request_funcs" title="Permalink to this definition">¶</a></dt>
  348. <dd><p>A lists of functions that should be called at the beginning of the
  349. first request to this instance. To register a function here, use
  350. the <a class="reference internal" href="#flask.app.Flask.before_first_request" title="flask.app.Flask.before_first_request"><code class="xref py py-meth docutils literal"><span class="pre">before_first_request()</span></code></a> decorator.</p>
  351. <div class="versionadded">
  352. <p><span class="versionmodified">New in version 0.8.</span></p>
  353. </div>
  354. </dd></dl>
  355. <dl class="method">
  356. <dt id="flask.app.Flask.before_request">
  357. <code class="descname">before_request</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.before_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.before_request" title="Permalink to this definition">¶</a></dt>
  358. <dd><p>Registers a function to run before each request.</p>
  359. <p>The function will be called without any arguments.
  360. If the function returns a non-None value, it&#8217;s handled as
  361. if it was the return value from the view and further
  362. request handling is stopped.</p>
  363. </dd></dl>
  364. <dl class="attribute">
  365. <dt id="flask.app.Flask.before_request_funcs">
  366. <code class="descname">before_request_funcs</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.before_request_funcs" title="Permalink to this definition">¶</a></dt>
  367. <dd><p>A dictionary with lists of functions that should be called at the
  368. beginning of the request. The key of the dictionary is the name of
  369. the blueprint this function is active for, <code class="docutils literal"><span class="pre">None</span></code> for all requests.
  370. This can for example be used to open database connections or
  371. getting hold of the currently logged in user. To register a
  372. function here, use the <a class="reference internal" href="#flask.app.Flask.before_request" title="flask.app.Flask.before_request"><code class="xref py py-meth docutils literal"><span class="pre">before_request()</span></code></a> decorator.</p>
  373. </dd></dl>
  374. <dl class="attribute">
  375. <dt id="flask.app.Flask.blueprints">
  376. <code class="descname">blueprints</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.blueprints" title="Permalink to this definition">¶</a></dt>
  377. <dd><p>all the attached blueprints in a dictionary by name. Blueprints
  378. can be attached multiple times so this dictionary does not tell
  379. you how often they got attached.</p>
  380. <div class="versionadded">
  381. <p><span class="versionmodified">New in version 0.7.</span></p>
  382. </div>
  383. </dd></dl>
  384. <dl class="attribute">
  385. <dt id="flask.app.Flask.cli">
  386. <code class="descname">cli</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.cli" title="Permalink to this definition">¶</a></dt>
  387. <dd><p>The click command line context for this application. Commands
  388. registered here show up in the <strong class="command">flask</strong> command once the
  389. application has been discovered. The default commands are
  390. provided by Flask itself and can be overridden.</p>
  391. <p>This is an instance of a <code class="xref py py-class docutils literal"><span class="pre">click.Group</span></code> object.</p>
  392. </dd></dl>
  393. <dl class="attribute">
  394. <dt id="flask.app.Flask.config">
  395. <code class="descname">config</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.config" title="Permalink to this definition">¶</a></dt>
  396. <dd><p>The configuration dictionary as <code class="xref py py-class docutils literal"><span class="pre">Config</span></code>. This behaves
  397. exactly like a regular dictionary but supports additional methods
  398. to load a config from files.</p>
  399. </dd></dl>
  400. <dl class="attribute">
  401. <dt id="flask.app.Flask.config_class">
  402. <code class="descname">config_class</code><a class="headerlink" href="#flask.app.Flask.config_class" title="Permalink to this definition">¶</a></dt>
  403. <dd><p>The class that is used for the <code class="docutils literal"><span class="pre">config</span></code> attribute of this app.
  404. Defaults to <code class="xref py py-class docutils literal"><span class="pre">Config</span></code>.</p>
  405. <p>Example use cases for a custom class:</p>
  406. <ol class="arabic simple">
  407. <li>Default values for certain config options.</li>
  408. <li>Access to config values through attributes in addition to keys.</li>
  409. </ol>
  410. <div class="versionadded">
  411. <p><span class="versionmodified">New in version 0.11.</span></p>
  412. </div>
  413. <p>alias of <code class="xref py py-class docutils literal"><span class="pre">Config</span></code></p>
  414. </dd></dl>
  415. <dl class="method">
  416. <dt id="flask.app.Flask.context_processor">
  417. <code class="descname">context_processor</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.context_processor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.context_processor" title="Permalink to this definition">¶</a></dt>
  418. <dd><p>Registers a template context processor function.</p>
  419. </dd></dl>
  420. <dl class="method">
  421. <dt id="flask.app.Flask.create_global_jinja_loader">
  422. <code class="descname">create_global_jinja_loader</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.create_global_jinja_loader"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.create_global_jinja_loader" title="Permalink to this definition">¶</a></dt>
  423. <dd><p>Creates the loader for the Jinja2 environment. Can be used to
  424. override just the loader and keeping the rest unchanged. It&#8217;s
  425. discouraged to override this function. Instead one should override
  426. the <code class="xref py py-meth docutils literal"><span class="pre">jinja_loader()</span></code> function instead.</p>
  427. <p>The global loader dispatches between the loaders of the application
  428. and the individual blueprints.</p>
  429. <div class="versionadded">
  430. <p><span class="versionmodified">New in version 0.7.</span></p>
  431. </div>
  432. </dd></dl>
  433. <dl class="method">
  434. <dt id="flask.app.Flask.create_jinja_environment">
  435. <code class="descname">create_jinja_environment</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.create_jinja_environment"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.create_jinja_environment" title="Permalink to this definition">¶</a></dt>
  436. <dd><p>Creates the Jinja2 environment based on <a class="reference internal" href="#flask.app.Flask.jinja_options" title="flask.app.Flask.jinja_options"><code class="xref py py-attr docutils literal"><span class="pre">jinja_options</span></code></a>
  437. and <a class="reference internal" href="#flask.app.Flask.select_jinja_autoescape" title="flask.app.Flask.select_jinja_autoescape"><code class="xref py py-meth docutils literal"><span class="pre">select_jinja_autoescape()</span></code></a>. Since 0.7 this also adds
  438. the Jinja2 globals and filters after initialization. Override
  439. this function to customize the behavior.</p>
  440. <div class="versionadded">
  441. <p><span class="versionmodified">New in version 0.5.</span></p>
  442. </div>
  443. <div class="versionchanged">
  444. <p><span class="versionmodified">Changed in version 0.11: </span><code class="docutils literal"><span class="pre">Environment.auto_reload</span></code> set in accordance with
  445. <code class="docutils literal"><span class="pre">TEMPLATES_AUTO_RELOAD</span></code> configuration option.</p>
  446. </div>
  447. </dd></dl>
  448. <dl class="method">
  449. <dt id="flask.app.Flask.create_url_adapter">
  450. <code class="descname">create_url_adapter</code><span class="sig-paren">(</span><em>request</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.create_url_adapter"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.create_url_adapter" title="Permalink to this definition">¶</a></dt>
  451. <dd><p>Creates a URL adapter for the given request. The URL adapter
  452. is created at a point where the request context is not yet set up
  453. so the request is passed explicitly.</p>
  454. <div class="versionadded">
  455. <p><span class="versionmodified">New in version 0.6.</span></p>
  456. </div>
  457. <div class="versionchanged">
  458. <p><span class="versionmodified">Changed in version 0.9: </span>This can now also be called without a request object when the
  459. URL adapter is created for the application context.</p>
  460. </div>
  461. </dd></dl>
  462. <dl class="attribute">
  463. <dt id="flask.app.Flask.debug">
  464. <code class="descname">debug</code><a class="headerlink" href="#flask.app.Flask.debug" title="Permalink to this definition">¶</a></dt>
  465. <dd><p>The debug flag. Set this to <code class="docutils literal"><span class="pre">True</span></code> to enable debugging of the
  466. application. In debug mode the debugger will kick in when an unhandled
  467. exception occurs and the integrated server will automatically reload
  468. the application if changes in the code are detected.</p>
  469. <p>This attribute can also be configured from the config with the <code class="docutils literal"><span class="pre">DEBUG</span></code>
  470. configuration key. Defaults to <code class="docutils literal"><span class="pre">False</span></code>.</p>
  471. </dd></dl>
  472. <dl class="attribute">
  473. <dt id="flask.app.Flask.default_config">
  474. <code class="descname">default_config</code><em class="property"> = ImmutableDict({'JSON_AS_ASCII': True, 'PRESERVE_CONTEXT_ON_EXCEPTION': None, 'PERMANENT_SESSION_LIFETIME': datetime.timedelta(31), 'SESSION_COOKIE_SECURE': False, 'LOGGER_HANDLER_POLICY': 'always', 'SESSION_COOKIE_DOMAIN': None, 'SESSION_COOKIE_NAME': 'session', 'SESSION_REFRESH_EACH_REQUEST': True, 'TRAP_BAD_REQUEST_ERRORS': False, 'PREFERRED_URL_SCHEME': 'http', 'APPLICATION_ROOT': None, 'LOGGER_NAME': None, 'TEMPLATES_AUTO_RELOAD': None, 'EXPLAIN_TEMPLATE_LOADING': False, 'PROPAGATE_EXCEPTIONS': None, 'SESSION_COOKIE_HTTPONLY': True, 'JSON_SORT_KEYS': True, 'TESTING': False, 'TRAP_HTTP_EXCEPTIONS': False, 'SERVER_NAME': None, 'SECRET_KEY': None, 'USE_X_SENDFILE': False, 'DEBUG': False, 'MAX_CONTENT_LENGTH': None, 'SESSION_COOKIE_PATH': None, 'SEND_FILE_MAX_AGE_DEFAULT': datetime.timedelta(0, 43200), 'JSONIFY_MIMETYPE': 'application/json', 'JSONIFY_PRETTYPRINT_REGULAR': True})</em><a class="headerlink" href="#flask.app.Flask.default_config" title="Permalink to this definition">¶</a></dt>
  475. <dd><p>Default configuration parameters.</p>
  476. </dd></dl>
  477. <dl class="method">
  478. <dt id="flask.app.Flask.dispatch_request">
  479. <code class="descname">dispatch_request</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.dispatch_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.dispatch_request" title="Permalink to this definition">¶</a></dt>
  480. <dd><p>Does the request dispatching. Matches the URL and returns the
  481. return value of the view or error handler. This does not have to
  482. be a response object. In order to convert the return value to a
  483. proper response object, call <a class="reference internal" href="#flask.app.Flask.make_response" title="flask.app.Flask.make_response"><code class="xref py py-func docutils literal"><span class="pre">make_response()</span></code></a>.</p>
  484. <div class="versionchanged">
  485. <p><span class="versionmodified">Changed in version 0.7: </span>This no longer does the exception handling, this code was
  486. moved to the new <a class="reference internal" href="#flask.app.Flask.full_dispatch_request" title="flask.app.Flask.full_dispatch_request"><code class="xref py py-meth docutils literal"><span class="pre">full_dispatch_request()</span></code></a>.</p>
  487. </div>
  488. </dd></dl>
  489. <dl class="method">
  490. <dt id="flask.app.Flask.do_teardown_appcontext">
  491. <code class="descname">do_teardown_appcontext</code><span class="sig-paren">(</span><em>exc=&lt;object object at 0x000001E1FDEFF7A0&gt;</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.do_teardown_appcontext"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.do_teardown_appcontext" title="Permalink to this definition">¶</a></dt>
  492. <dd><p>Called when an application context is popped. This works pretty
  493. much the same as <a class="reference internal" href="#flask.app.Flask.do_teardown_request" title="flask.app.Flask.do_teardown_request"><code class="xref py py-meth docutils literal"><span class="pre">do_teardown_request()</span></code></a> but for the application
  494. context.</p>
  495. <div class="versionadded">
  496. <p><span class="versionmodified">New in version 0.9.</span></p>
  497. </div>
  498. </dd></dl>
  499. <dl class="method">
  500. <dt id="flask.app.Flask.do_teardown_request">
  501. <code class="descname">do_teardown_request</code><span class="sig-paren">(</span><em>exc=&lt;object object at 0x000001E1FDEFF7A0&gt;</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.do_teardown_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.do_teardown_request" title="Permalink to this definition">¶</a></dt>
  502. <dd><p>Called after the actual request dispatching and will
  503. call every as <a class="reference internal" href="#flask.app.Flask.teardown_request" title="flask.app.Flask.teardown_request"><code class="xref py py-meth docutils literal"><span class="pre">teardown_request()</span></code></a> decorated function. This is
  504. not actually called by the <a class="reference internal" href="#flask.app.Flask" title="flask.app.Flask"><code class="xref py py-class docutils literal"><span class="pre">Flask</span></code></a> object itself but is always
  505. triggered when the request context is popped. That way we have a
  506. tighter control over certain resources under testing environments.</p>
  507. <div class="versionchanged">
  508. <p><span class="versionmodified">Changed in version 0.9: </span>Added the <cite>exc</cite> argument. Previously this was always using the
  509. current exception information.</p>
  510. </div>
  511. </dd></dl>
  512. <dl class="method">
  513. <dt id="flask.app.Flask.endpoint">
  514. <code class="descname">endpoint</code><span class="sig-paren">(</span><em>endpoint</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.endpoint"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.endpoint" title="Permalink to this definition">¶</a></dt>
  515. <dd><p>A decorator to register a function as an endpoint.
  516. Example:</p>
  517. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">endpoint</span><span class="p">(</span><span class="s1">&#39;example.endpoint&#39;</span><span class="p">)</span>
  518. <span class="k">def</span> <span class="nf">example</span><span class="p">():</span>
  519. <span class="k">return</span> <span class="s2">&quot;example&quot;</span>
  520. </pre></div>
  521. </div>
  522. <table class="docutils field-list" frame="void" rules="none">
  523. <col class="field-name" />
  524. <col class="field-body" />
  525. <tbody valign="top">
  526. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>endpoint</strong> &#8211; the name of the endpoint</td>
  527. </tr>
  528. </tbody>
  529. </table>
  530. </dd></dl>
  531. <dl class="attribute">
  532. <dt id="flask.app.Flask.error_handler_spec">
  533. <code class="descname">error_handler_spec</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.error_handler_spec" title="Permalink to this definition">¶</a></dt>
  534. <dd><p>A dictionary of all registered error handlers. The key is <code class="docutils literal"><span class="pre">None</span></code>
  535. for error handlers active on the application, otherwise the key is
  536. the name of the blueprint. Each key points to another dictionary
  537. where the key is the status code of the http exception. The
  538. special key <code class="docutils literal"><span class="pre">None</span></code> points to a list of tuples where the first item
  539. is the class for the instance check and the second the error handler
  540. function.</p>
  541. <p>To register a error handler, use the <a class="reference internal" href="#flask.app.Flask.errorhandler" title="flask.app.Flask.errorhandler"><code class="xref py py-meth docutils literal"><span class="pre">errorhandler()</span></code></a>
  542. decorator.</p>
  543. </dd></dl>
  544. <dl class="attribute">
  545. <dt id="flask.app.Flask.error_handlers">
  546. <code class="descname">error_handlers</code><a class="headerlink" href="#flask.app.Flask.error_handlers" title="Permalink to this definition">¶</a></dt>
  547. <dd></dd></dl>
  548. <dl class="method">
  549. <dt id="flask.app.Flask.errorhandler">
  550. <code class="descname">errorhandler</code><span class="sig-paren">(</span><em>code_or_exception</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.errorhandler"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.errorhandler" title="Permalink to this definition">¶</a></dt>
  551. <dd><p>A decorator that is used to register a function give a given
  552. error code. Example:</p>
  553. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">errorhandler</span><span class="p">(</span><span class="mi">404</span><span class="p">)</span>
  554. <span class="k">def</span> <span class="nf">page_not_found</span><span class="p">(</span><span class="n">error</span><span class="p">):</span>
  555. <span class="k">return</span> <span class="s1">&#39;This page does not exist&#39;</span><span class="p">,</span> <span class="mi">404</span>
  556. </pre></div>
  557. </div>
  558. <p>You can also register handlers for arbitrary exceptions:</p>
  559. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">errorhandler</span><span class="p">(</span><span class="n">DatabaseError</span><span class="p">)</span>
  560. <span class="k">def</span> <span class="nf">special_exception_handler</span><span class="p">(</span><span class="n">error</span><span class="p">):</span>
  561. <span class="k">return</span> <span class="s1">&#39;Database connection failed&#39;</span><span class="p">,</span> <span class="mi">500</span>
  562. </pre></div>
  563. </div>
  564. <p>You can also register a function as error handler without using
  565. the <a class="reference internal" href="#flask.app.Flask.errorhandler" title="flask.app.Flask.errorhandler"><code class="xref py py-meth docutils literal"><span class="pre">errorhandler()</span></code></a> decorator. The following example is
  566. equivalent to the one above:</p>
  567. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">page_not_found</span><span class="p">(</span><span class="n">error</span><span class="p">):</span>
  568. <span class="k">return</span> <span class="s1">&#39;This page does not exist&#39;</span><span class="p">,</span> <span class="mi">404</span>
  569. <span class="n">app</span><span class="o">.</span><span class="n">error_handler_spec</span><span class="p">[</span><span class="kc">None</span><span class="p">][</span><span class="mi">404</span><span class="p">]</span> <span class="o">=</span> <span class="n">page_not_found</span>
  570. </pre></div>
  571. </div>
  572. <p>Setting error handlers via assignments to <a class="reference internal" href="#flask.app.Flask.error_handler_spec" title="flask.app.Flask.error_handler_spec"><code class="xref py py-attr docutils literal"><span class="pre">error_handler_spec</span></code></a>
  573. however is discouraged as it requires fiddling with nested dictionaries
  574. and the special case for arbitrary exception types.</p>
  575. <p>The first <code class="docutils literal"><span class="pre">None</span></code> refers to the active blueprint. If the error
  576. handler should be application wide <code class="docutils literal"><span class="pre">None</span></code> shall be used.</p>
  577. <div class="versionadded">
  578. <p><span class="versionmodified">New in version 0.7: </span>Use <a class="reference internal" href="#flask.app.Flask.register_error_handler" title="flask.app.Flask.register_error_handler"><code class="xref py py-meth docutils literal"><span class="pre">register_error_handler()</span></code></a> instead of modifying
  579. <a class="reference internal" href="#flask.app.Flask.error_handler_spec" title="flask.app.Flask.error_handler_spec"><code class="xref py py-attr docutils literal"><span class="pre">error_handler_spec</span></code></a> directly, for application wide error
  580. handlers.</p>
  581. </div>
  582. <div class="versionadded">
  583. <p><span class="versionmodified">New in version 0.7: </span>One can now additionally also register custom exception types
  584. that do not necessarily have to be a subclass of the
  585. <code class="xref py py-class docutils literal"><span class="pre">HTTPException</span></code> class.</p>
  586. </div>
  587. <table class="docutils field-list" frame="void" rules="none">
  588. <col class="field-name" />
  589. <col class="field-body" />
  590. <tbody valign="top">
  591. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>code</strong> &#8211; the code as integer for the handler</td>
  592. </tr>
  593. </tbody>
  594. </table>
  595. </dd></dl>
  596. <dl class="attribute">
  597. <dt id="flask.app.Flask.extensions">
  598. <code class="descname">extensions</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.extensions" title="Permalink to this definition">¶</a></dt>
  599. <dd><p>a place where extensions can store application specific state. For
  600. example this is where an extension could store database engines and
  601. similar things. For backwards compatibility extensions should register
  602. themselves like this:</p>
  603. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">app</span><span class="p">,</span> <span class="s1">&#39;extensions&#39;</span><span class="p">):</span>
  604. <span class="n">app</span><span class="o">.</span><span class="n">extensions</span> <span class="o">=</span> <span class="p">{}</span>
  605. <span class="n">app</span><span class="o">.</span><span class="n">extensions</span><span class="p">[</span><span class="s1">&#39;extensionname&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">SomeObject</span><span class="p">()</span>
  606. </pre></div>
  607. </div>
  608. <p>The key must match the name of the extension module. For example in
  609. case of a &#8220;Flask-Foo&#8221; extension in <cite>flask_foo</cite>, the key would be
  610. <code class="docutils literal"><span class="pre">'foo'</span></code>.</p>
  611. <div class="versionadded">
  612. <p><span class="versionmodified">New in version 0.7.</span></p>
  613. </div>
  614. </dd></dl>
  615. <dl class="method">
  616. <dt id="flask.app.Flask.full_dispatch_request">
  617. <code class="descname">full_dispatch_request</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.full_dispatch_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.full_dispatch_request" title="Permalink to this definition">¶</a></dt>
  618. <dd><p>Dispatches the request and on top of that performs request
  619. pre and postprocessing as well as HTTP exception catching and
  620. error handling.</p>
  621. <div class="versionadded">
  622. <p><span class="versionmodified">New in version 0.7.</span></p>
  623. </div>
  624. </dd></dl>
  625. <dl class="attribute">
  626. <dt id="flask.app.Flask.got_first_request">
  627. <code class="descname">got_first_request</code><a class="headerlink" href="#flask.app.Flask.got_first_request" title="Permalink to this definition">¶</a></dt>
  628. <dd><p>This attribute is set to <code class="docutils literal"><span class="pre">True</span></code> if the application started
  629. handling the first request.</p>
  630. <div class="versionadded">
  631. <p><span class="versionmodified">New in version 0.8.</span></p>
  632. </div>
  633. </dd></dl>
  634. <dl class="method">
  635. <dt id="flask.app.Flask.handle_exception">
  636. <code class="descname">handle_exception</code><span class="sig-paren">(</span><em>e</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.handle_exception"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.handle_exception" title="Permalink to this definition">¶</a></dt>
  637. <dd><p>Default exception handling that kicks in when an exception
  638. occurs that is not caught. In debug mode the exception will
  639. be re-raised immediately, otherwise it is logged and the handler
  640. for a 500 internal server error is used. If no such handler
  641. exists, a default 500 internal server error message is displayed.</p>
  642. <div class="versionadded">
  643. <p><span class="versionmodified">New in version 0.3.</span></p>
  644. </div>
  645. </dd></dl>
  646. <dl class="method">
  647. <dt id="flask.app.Flask.handle_http_exception">
  648. <code class="descname">handle_http_exception</code><span class="sig-paren">(</span><em>e</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.handle_http_exception"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.handle_http_exception" title="Permalink to this definition">¶</a></dt>
  649. <dd><p>Handles an HTTP exception. By default this will invoke the
  650. registered error handlers and fall back to returning the
  651. exception as response.</p>
  652. <div class="versionadded">
  653. <p><span class="versionmodified">New in version 0.3.</span></p>
  654. </div>
  655. </dd></dl>
  656. <dl class="method">
  657. <dt id="flask.app.Flask.handle_url_build_error">
  658. <code class="descname">handle_url_build_error</code><span class="sig-paren">(</span><em>error</em>, <em>endpoint</em>, <em>values</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.handle_url_build_error"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.handle_url_build_error" title="Permalink to this definition">¶</a></dt>
  659. <dd><p>Handle <code class="xref py py-class docutils literal"><span class="pre">BuildError</span></code> on <code class="xref py py-meth docutils literal"><span class="pre">url_for()</span></code>.</p>
  660. </dd></dl>
  661. <dl class="method">
  662. <dt id="flask.app.Flask.handle_user_exception">
  663. <code class="descname">handle_user_exception</code><span class="sig-paren">(</span><em>e</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.handle_user_exception"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.handle_user_exception" title="Permalink to this definition">¶</a></dt>
  664. <dd><p>This method is called whenever an exception occurs that should be
  665. handled. A special case are
  666. <code class="xref py py-class docutils literal"><span class="pre">HTTPException</span></code>s which are forwarded by
  667. this function to the <a class="reference internal" href="#flask.app.Flask.handle_http_exception" title="flask.app.Flask.handle_http_exception"><code class="xref py py-meth docutils literal"><span class="pre">handle_http_exception()</span></code></a> method. This
  668. function will either return a response value or reraise the
  669. exception with the same traceback.</p>
  670. <div class="versionadded">
  671. <p><span class="versionmodified">New in version 0.7.</span></p>
  672. </div>
  673. </dd></dl>
  674. <dl class="method">
  675. <dt id="flask.app.Flask.init_jinja_globals">
  676. <code class="descname">init_jinja_globals</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.init_jinja_globals"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.init_jinja_globals" title="Permalink to this definition">¶</a></dt>
  677. <dd><p>Deprecated. Used to initialize the Jinja2 globals.</p>
  678. <div class="versionadded">
  679. <p><span class="versionmodified">New in version 0.5.</span></p>
  680. </div>
  681. <div class="versionchanged">
  682. <p><span class="versionmodified">Changed in version 0.7: </span>This method is deprecated with 0.7. Override
  683. <a class="reference internal" href="#flask.app.Flask.create_jinja_environment" title="flask.app.Flask.create_jinja_environment"><code class="xref py py-meth docutils literal"><span class="pre">create_jinja_environment()</span></code></a> instead.</p>
  684. </div>
  685. </dd></dl>
  686. <dl class="method">
  687. <dt id="flask.app.Flask.inject_url_defaults">
  688. <code class="descname">inject_url_defaults</code><span class="sig-paren">(</span><em>endpoint</em>, <em>values</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.inject_url_defaults"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.inject_url_defaults" title="Permalink to this definition">¶</a></dt>
  689. <dd><p>Injects the URL defaults for the given endpoint directly into
  690. the values dictionary passed. This is used internally and
  691. automatically called on URL building.</p>
  692. <div class="versionadded">
  693. <p><span class="versionmodified">New in version 0.7.</span></p>
  694. </div>
  695. </dd></dl>
  696. <dl class="attribute">
  697. <dt id="flask.app.Flask.instance_path">
  698. <code class="descname">instance_path</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.instance_path" title="Permalink to this definition">¶</a></dt>
  699. <dd><p>Holds the path to the instance folder.</p>
  700. <div class="versionadded">
  701. <p><span class="versionmodified">New in version 0.8.</span></p>
  702. </div>
  703. </dd></dl>
  704. <dl class="method">
  705. <dt id="flask.app.Flask.iter_blueprints">
  706. <code class="descname">iter_blueprints</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.iter_blueprints"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.iter_blueprints" title="Permalink to this definition">¶</a></dt>
  707. <dd><p>Iterates over all blueprints by the order they were registered.</p>
  708. <div class="versionadded">
  709. <p><span class="versionmodified">New in version 0.11.</span></p>
  710. </div>
  711. </dd></dl>
  712. <dl class="attribute">
  713. <dt id="flask.app.Flask.jinja_env">
  714. <code class="descname">jinja_env</code><a class="reference internal" href="../_modules/flask/app.html#Flask.jinja_env"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.jinja_env" title="Permalink to this definition">¶</a></dt>
  715. <dd><p>The Jinja2 environment used to load templates.</p>
  716. </dd></dl>
  717. <dl class="attribute">
  718. <dt id="flask.app.Flask.jinja_environment">
  719. <code class="descname">jinja_environment</code><a class="headerlink" href="#flask.app.Flask.jinja_environment" title="Permalink to this definition">¶</a></dt>
  720. <dd><p>The class that is used for the Jinja environment.</p>
  721. <div class="versionadded">
  722. <p><span class="versionmodified">New in version 0.11.</span></p>
  723. </div>
  724. <p>alias of <code class="xref py py-class docutils literal"><span class="pre">Environment</span></code></p>
  725. </dd></dl>
  726. <dl class="attribute">
  727. <dt id="flask.app.Flask.jinja_options">
  728. <code class="descname">jinja_options</code><em class="property"> = ImmutableDict({'extensions': ['jinja2.ext.autoescape', 'jinja2.ext.with_']})</em><a class="headerlink" href="#flask.app.Flask.jinja_options" title="Permalink to this definition">¶</a></dt>
  729. <dd><p>Options that are passed directly to the Jinja2 environment.</p>
  730. </dd></dl>
  731. <dl class="attribute">
  732. <dt id="flask.app.Flask.json_decoder">
  733. <code class="descname">json_decoder</code><a class="headerlink" href="#flask.app.Flask.json_decoder" title="Permalink to this definition">¶</a></dt>
  734. <dd><p>The JSON decoder class to use. Defaults to <a class="reference internal" href="#flask.json.JSONDecoder" title="flask.json.JSONDecoder"><code class="xref py py-class docutils literal"><span class="pre">JSONDecoder</span></code></a>.</p>
  735. <div class="versionadded">
  736. <p><span class="versionmodified">New in version 0.10.</span></p>
  737. </div>
  738. <p>alias of <code class="xref py py-class docutils literal"><span class="pre">JSONDecoder</span></code></p>
  739. </dd></dl>
  740. <dl class="attribute">
  741. <dt id="flask.app.Flask.json_encoder">
  742. <code class="descname">json_encoder</code><a class="headerlink" href="#flask.app.Flask.json_encoder" title="Permalink to this definition">¶</a></dt>
  743. <dd><p>The JSON encoder class to use. Defaults to <a class="reference internal" href="#flask.json.JSONEncoder" title="flask.json.JSONEncoder"><code class="xref py py-class docutils literal"><span class="pre">JSONEncoder</span></code></a>.</p>
  744. <div class="versionadded">
  745. <p><span class="versionmodified">New in version 0.10.</span></p>
  746. </div>
  747. <p>alias of <code class="xref py py-class docutils literal"><span class="pre">JSONEncoder</span></code></p>
  748. </dd></dl>
  749. <dl class="method">
  750. <dt id="flask.app.Flask.log_exception">
  751. <code class="descname">log_exception</code><span class="sig-paren">(</span><em>exc_info</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.log_exception"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.log_exception" title="Permalink to this definition">¶</a></dt>
  752. <dd><p>Logs an exception. This is called by <a class="reference internal" href="#flask.app.Flask.handle_exception" title="flask.app.Flask.handle_exception"><code class="xref py py-meth docutils literal"><span class="pre">handle_exception()</span></code></a>
  753. if debugging is disabled and right before the handler is called.
  754. The default implementation logs the exception as error on the
  755. <a class="reference internal" href="#flask.app.Flask.logger" title="flask.app.Flask.logger"><code class="xref py py-attr docutils literal"><span class="pre">logger</span></code></a>.</p>
  756. <div class="versionadded">
  757. <p><span class="versionmodified">New in version 0.8.</span></p>
  758. </div>
  759. </dd></dl>
  760. <dl class="attribute">
  761. <dt id="flask.app.Flask.logger">
  762. <code class="descname">logger</code><a class="headerlink" href="#flask.app.Flask.logger" title="Permalink to this definition">¶</a></dt>
  763. <dd><p>A <code class="xref py py-class docutils literal"><span class="pre">logging.Logger</span></code> object for this application. The
  764. default configuration is to log to stderr if the application is
  765. in debug mode. This logger can be used to (surprise) log messages.
  766. Here some examples:</p>
  767. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;A value for debugging&#39;</span><span class="p">)</span>
  768. <span class="n">app</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">&#39;A warning occurred (</span><span class="si">%d</span><span class="s1"> apples)&#39;</span><span class="p">,</span> <span class="mi">42</span><span class="p">)</span>
  769. <span class="n">app</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;An error occurred&#39;</span><span class="p">)</span>
  770. </pre></div>
  771. </div>
  772. <div class="versionadded">
  773. <p><span class="versionmodified">New in version 0.3.</span></p>
  774. </div>
  775. </dd></dl>
  776. <dl class="attribute">
  777. <dt id="flask.app.Flask.logger_name">
  778. <code class="descname">logger_name</code><a class="headerlink" href="#flask.app.Flask.logger_name" title="Permalink to this definition">¶</a></dt>
  779. <dd><p>The name of the logger to use. By default the logger name is the
  780. package name passed to the constructor.</p>
  781. <div class="versionadded">
  782. <p><span class="versionmodified">New in version 0.4.</span></p>
  783. </div>
  784. </dd></dl>
  785. <dl class="method">
  786. <dt id="flask.app.Flask.make_config">
  787. <code class="descname">make_config</code><span class="sig-paren">(</span><em>instance_relative=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.make_config"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.make_config" title="Permalink to this definition">¶</a></dt>
  788. <dd><p>Used to create the config attribute by the Flask constructor.
  789. The <cite>instance_relative</cite> parameter is passed in from the constructor
  790. of Flask (there named <cite>instance_relative_config</cite>) and indicates if
  791. the config should be relative to the instance path or the root path
  792. of the application.</p>
  793. <div class="versionadded">
  794. <p><span class="versionmodified">New in version 0.8.</span></p>
  795. </div>
  796. </dd></dl>
  797. <dl class="method">
  798. <dt id="flask.app.Flask.make_default_options_response">
  799. <code class="descname">make_default_options_response</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.make_default_options_response"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.make_default_options_response" title="Permalink to this definition">¶</a></dt>
  800. <dd><p>This method is called to create the default <code class="docutils literal"><span class="pre">OPTIONS</span></code> response.
  801. This can be changed through subclassing to change the default
  802. behavior of <code class="docutils literal"><span class="pre">OPTIONS</span></code> responses.</p>
  803. <div class="versionadded">
  804. <p><span class="versionmodified">New in version 0.7.</span></p>
  805. </div>
  806. </dd></dl>
  807. <dl class="method">
  808. <dt id="flask.app.Flask.make_null_session">
  809. <code class="descname">make_null_session</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.make_null_session"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.make_null_session" title="Permalink to this definition">¶</a></dt>
  810. <dd><p>Creates a new instance of a missing session. Instead of overriding
  811. this method we recommend replacing the <a class="reference internal" href="#flask.app.Flask.session_interface" title="flask.app.Flask.session_interface"><code class="xref py py-class docutils literal"><span class="pre">session_interface</span></code></a>.</p>
  812. <div class="versionadded">
  813. <p><span class="versionmodified">New in version 0.7.</span></p>
  814. </div>
  815. </dd></dl>
  816. <dl class="method">
  817. <dt id="flask.app.Flask.make_response">
  818. <code class="descname">make_response</code><span class="sig-paren">(</span><em>rv</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.make_response"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.make_response" title="Permalink to this definition">¶</a></dt>
  819. <dd><p>Converts the return value from a view function to a real
  820. response object that is an instance of <a class="reference internal" href="#flask.app.Flask.response_class" title="flask.app.Flask.response_class"><code class="xref py py-attr docutils literal"><span class="pre">response_class</span></code></a>.</p>
  821. <p>The following types are allowed for <cite>rv</cite>:</p>
  822. <table border="1" class="docutils">
  823. <colgroup>
  824. <col width="35%" />
  825. <col width="65%" />
  826. </colgroup>
  827. <tbody valign="top">
  828. <tr class="row-odd"><td><a class="reference internal" href="#flask.app.Flask.response_class" title="flask.app.Flask.response_class"><code class="xref py py-attr docutils literal"><span class="pre">response_class</span></code></a></td>
  829. <td>the object is returned unchanged</td>
  830. </tr>
  831. <tr class="row-even"><td><code class="xref py py-class docutils literal"><span class="pre">str</span></code></td>
  832. <td>a response object is created with the
  833. string as body</td>
  834. </tr>
  835. <tr class="row-odd"><td><code class="xref py py-class docutils literal"><span class="pre">unicode</span></code></td>
  836. <td>a response object is created with the
  837. string encoded to utf-8 as body</td>
  838. </tr>
  839. <tr class="row-even"><td>a WSGI function</td>
  840. <td>the function is called as WSGI application
  841. and buffered as response object</td>
  842. </tr>
  843. <tr class="row-odd"><td><code class="xref py py-class docutils literal"><span class="pre">tuple</span></code></td>
  844. <td>A tuple in the form <code class="docutils literal"><span class="pre">(response,</span> <span class="pre">status,</span>
  845. <span class="pre">headers)</span></code> or <code class="docutils literal"><span class="pre">(response,</span> <span class="pre">headers)</span></code>
  846. where <cite>response</cite> is any of the
  847. types defined here, <cite>status</cite> is a string
  848. or an integer and <cite>headers</cite> is a list or
  849. a dictionary with header values.</td>
  850. </tr>
  851. </tbody>
  852. </table>
  853. <table class="docutils field-list" frame="void" rules="none">
  854. <col class="field-name" />
  855. <col class="field-body" />
  856. <tbody valign="top">
  857. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>rv</strong> &#8211; the return value from the view function</td>
  858. </tr>
  859. </tbody>
  860. </table>
  861. <div class="versionchanged">
  862. <p><span class="versionmodified">Changed in version 0.9: </span>Previously a tuple was interpreted as the arguments for the
  863. response object.</p>
  864. </div>
  865. </dd></dl>
  866. <dl class="method">
  867. <dt id="flask.app.Flask.make_shell_context">
  868. <code class="descname">make_shell_context</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.make_shell_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.make_shell_context" title="Permalink to this definition">¶</a></dt>
  869. <dd><p>Returns the shell context for an interactive shell for this
  870. application. This runs all the registered shell context
  871. processors.</p>
  872. <div class="versionadded">
  873. <p><span class="versionmodified">New in version 0.11.</span></p>
  874. </div>
  875. </dd></dl>
  876. <dl class="attribute">
  877. <dt id="flask.app.Flask.name">
  878. <code class="descname">name</code><a class="reference internal" href="../_modules/flask/app.html#Flask.name"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.name" title="Permalink to this definition">¶</a></dt>
  879. <dd><p>The name of the application. This is usually the import name
  880. with the difference that it&#8217;s guessed from the run file if the
  881. import name is main. This name is used as a display name when
  882. Flask needs the name of the application. It can be set and overridden
  883. to change the value.</p>
  884. <div class="versionadded">
  885. <p><span class="versionmodified">New in version 0.8.</span></p>
  886. </div>
  887. </dd></dl>
  888. <dl class="method">
  889. <dt id="flask.app.Flask.open_instance_resource">
  890. <code class="descname">open_instance_resource</code><span class="sig-paren">(</span><em>resource</em>, <em>mode='rb'</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.open_instance_resource"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.open_instance_resource" title="Permalink to this definition">¶</a></dt>
  891. <dd><p>Opens a resource from the application&#8217;s instance folder
  892. (<a class="reference internal" href="#flask.app.Flask.instance_path" title="flask.app.Flask.instance_path"><code class="xref py py-attr docutils literal"><span class="pre">instance_path</span></code></a>). Otherwise works like
  893. <code class="xref py py-meth docutils literal"><span class="pre">open_resource()</span></code>. Instance resources can also be opened for
  894. writing.</p>
  895. <table class="docutils field-list" frame="void" rules="none">
  896. <col class="field-name" />
  897. <col class="field-body" />
  898. <tbody valign="top">
  899. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  900. <li><strong>resource</strong> &#8211; the name of the resource. To access resources within
  901. subfolders use forward slashes as separator.</li>
  902. <li><strong>mode</strong> &#8211; resource file opening mode, default is &#8216;rb&#8217;.</li>
  903. </ul>
  904. </td>
  905. </tr>
  906. </tbody>
  907. </table>
  908. </dd></dl>
  909. <dl class="method">
  910. <dt id="flask.app.Flask.open_session">
  911. <code class="descname">open_session</code><span class="sig-paren">(</span><em>request</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.open_session"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.open_session" title="Permalink to this definition">¶</a></dt>
  912. <dd><p>Creates or opens a new session. Default implementation stores all
  913. session data in a signed cookie. This requires that the
  914. <a class="reference internal" href="#flask.app.Flask.secret_key" title="flask.app.Flask.secret_key"><code class="xref py py-attr docutils literal"><span class="pre">secret_key</span></code></a> is set. Instead of overriding this method
  915. we recommend replacing the <a class="reference internal" href="#flask.app.Flask.session_interface" title="flask.app.Flask.session_interface"><code class="xref py py-class docutils literal"><span class="pre">session_interface</span></code></a>.</p>
  916. <table class="docutils field-list" frame="void" rules="none">
  917. <col class="field-name" />
  918. <col class="field-body" />
  919. <tbody valign="top">
  920. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>request</strong> &#8211; an instance of <a class="reference internal" href="#flask.app.Flask.request_class" title="flask.app.Flask.request_class"><code class="xref py py-attr docutils literal"><span class="pre">request_class</span></code></a>.</td>
  921. </tr>
  922. </tbody>
  923. </table>
  924. </dd></dl>
  925. <dl class="attribute">
  926. <dt id="flask.app.Flask.permanent_session_lifetime">
  927. <code class="descname">permanent_session_lifetime</code><a class="headerlink" href="#flask.app.Flask.permanent_session_lifetime" title="Permalink to this definition">¶</a></dt>
  928. <dd><p>A <code class="xref py py-class docutils literal"><span class="pre">timedelta</span></code> which is used to set the expiration
  929. date of a permanent session. The default is 31 days which makes a
  930. permanent session survive for roughly one month.</p>
  931. <p>This attribute can also be configured from the config with the
  932. <code class="docutils literal"><span class="pre">PERMANENT_SESSION_LIFETIME</span></code> configuration key. Defaults to
  933. <code class="docutils literal"><span class="pre">timedelta(days=31)</span></code></p>
  934. </dd></dl>
  935. <dl class="method">
  936. <dt id="flask.app.Flask.preprocess_request">
  937. <code class="descname">preprocess_request</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.preprocess_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.preprocess_request" title="Permalink to this definition">¶</a></dt>
  938. <dd><p>Called before the actual request dispatching and will
  939. call each <a class="reference internal" href="#flask.app.Flask.before_request" title="flask.app.Flask.before_request"><code class="xref py py-meth docutils literal"><span class="pre">before_request()</span></code></a> decorated function, passing no
  940. arguments.
  941. If any of these functions returns a value, it&#8217;s handled as
  942. if it was the return value from the view and further
  943. request handling is stopped.</p>
  944. <p>This also triggers the <code class="xref py py-meth docutils literal"><span class="pre">url_value_processor()</span></code> functions before
  945. the actual <a class="reference internal" href="#flask.app.Flask.before_request" title="flask.app.Flask.before_request"><code class="xref py py-meth docutils literal"><span class="pre">before_request()</span></code></a> functions are called.</p>
  946. </dd></dl>
  947. <dl class="attribute">
  948. <dt id="flask.app.Flask.preserve_context_on_exception">
  949. <code class="descname">preserve_context_on_exception</code><a class="headerlink" href="#flask.app.Flask.preserve_context_on_exception" title="Permalink to this definition">¶</a></dt>
  950. <dd><p>Returns the value of the <code class="docutils literal"><span class="pre">PRESERVE_CONTEXT_ON_EXCEPTION</span></code>
  951. configuration value in case it&#8217;s set, otherwise a sensible default
  952. is returned.</p>
  953. <div class="versionadded">
  954. <p><span class="versionmodified">New in version 0.7.</span></p>
  955. </div>
  956. </dd></dl>
  957. <dl class="method">
  958. <dt id="flask.app.Flask.process_response">
  959. <code class="descname">process_response</code><span class="sig-paren">(</span><em>response</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.process_response"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.process_response" title="Permalink to this definition">¶</a></dt>
  960. <dd><p>Can be overridden in order to modify the response object
  961. before it&#8217;s sent to the WSGI server. By default this will
  962. call all the <a class="reference internal" href="#flask.app.Flask.after_request" title="flask.app.Flask.after_request"><code class="xref py py-meth docutils literal"><span class="pre">after_request()</span></code></a> decorated functions.</p>
  963. <div class="versionchanged">
  964. <p><span class="versionmodified">Changed in version 0.5: </span>As of Flask 0.5 the functions registered for after request
  965. execution are called in reverse order of registration.</p>
  966. </div>
  967. <table class="docutils field-list" frame="void" rules="none">
  968. <col class="field-name" />
  969. <col class="field-body" />
  970. <tbody valign="top">
  971. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>response</strong> &#8211; a <a class="reference internal" href="#flask.app.Flask.response_class" title="flask.app.Flask.response_class"><code class="xref py py-attr docutils literal"><span class="pre">response_class</span></code></a> object.</td>
  972. </tr>
  973. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a new response object or the same, has to be an
  974. instance of <a class="reference internal" href="#flask.app.Flask.response_class" title="flask.app.Flask.response_class"><code class="xref py py-attr docutils literal"><span class="pre">response_class</span></code></a>.</td>
  975. </tr>
  976. </tbody>
  977. </table>
  978. </dd></dl>
  979. <dl class="attribute">
  980. <dt id="flask.app.Flask.propagate_exceptions">
  981. <code class="descname">propagate_exceptions</code><a class="headerlink" href="#flask.app.Flask.propagate_exceptions" title="Permalink to this definition">¶</a></dt>
  982. <dd><p>Returns the value of the <code class="docutils literal"><span class="pre">PROPAGATE_EXCEPTIONS</span></code> configuration
  983. value in case it&#8217;s set, otherwise a sensible default is returned.</p>
  984. <div class="versionadded">
  985. <p><span class="versionmodified">New in version 0.7.</span></p>
  986. </div>
  987. </dd></dl>
  988. <dl class="method">
  989. <dt id="flask.app.Flask.raise_routing_exception">
  990. <code class="descname">raise_routing_exception</code><span class="sig-paren">(</span><em>request</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.raise_routing_exception"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.raise_routing_exception" title="Permalink to this definition">¶</a></dt>
  991. <dd><p>Exceptions that are recording during routing are reraised with
  992. this method. During debug we are not reraising redirect requests
  993. for non <code class="docutils literal"><span class="pre">GET</span></code>, <code class="docutils literal"><span class="pre">HEAD</span></code>, or <code class="docutils literal"><span class="pre">OPTIONS</span></code> requests and we&#8217;re raising
  994. a different error instead to help debug situations.</p>
  995. <table class="docutils field-list" frame="void" rules="none">
  996. <col class="field-name" />
  997. <col class="field-body" />
  998. <tbody valign="top">
  999. <tr class="field-odd field"><th class="field-name">Internal:</th><td class="field-body"></td>
  1000. </tr>
  1001. </tbody>
  1002. </table>
  1003. </dd></dl>
  1004. <dl class="method">
  1005. <dt id="flask.app.Flask.register_blueprint">
  1006. <code class="descname">register_blueprint</code><span class="sig-paren">(</span><em>blueprint</em>, <em>**options</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.register_blueprint"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.register_blueprint" title="Permalink to this definition">¶</a></dt>
  1007. <dd><p>Register a blueprint on the application. For information about
  1008. blueprints head over to <span class="xref std std-ref">blueprints</span>.</p>
  1009. <p>The blueprint name is passed in as the first argument.
  1010. Options are passed as additional keyword arguments and forwarded to
  1011. <cite>blueprints</cite> in an &#8220;options&#8221; dictionary.</p>
  1012. <table class="docutils field-list" frame="void" rules="none">
  1013. <col class="field-name" />
  1014. <col class="field-body" />
  1015. <tbody valign="top">
  1016. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  1017. <li><strong>subdomain</strong> &#8211; set a subdomain for the blueprint</li>
  1018. <li><strong>url_prefix</strong> &#8211; set the prefix for all URLs defined on the blueprint.
  1019. <code class="docutils literal"><span class="pre">(url_prefix='/&lt;lang</span> <span class="pre">code&gt;')</span></code></li>
  1020. <li><strong>url_defaults</strong> &#8211; a dictionary with URL defaults that is added to
  1021. each and every URL defined with this blueprint</li>
  1022. <li><strong>static_folder</strong> &#8211; add a static folder to urls in this blueprint</li>
  1023. <li><strong>static_url_path</strong> &#8211; add a static url path to urls in this blueprint</li>
  1024. <li><strong>template_folder</strong> &#8211; set an alternate template folder</li>
  1025. <li><strong>root_path</strong> &#8211; set an alternate root path for this blueprint</li>
  1026. </ul>
  1027. </td>
  1028. </tr>
  1029. </tbody>
  1030. </table>
  1031. <div class="versionadded">
  1032. <p><span class="versionmodified">New in version 0.7.</span></p>
  1033. </div>
  1034. </dd></dl>
  1035. <dl class="method">
  1036. <dt id="flask.app.Flask.register_error_handler">
  1037. <code class="descname">register_error_handler</code><span class="sig-paren">(</span><em>code_or_exception</em>, <em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.register_error_handler"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.register_error_handler" title="Permalink to this definition">¶</a></dt>
  1038. <dd><p>Alternative error attach function to the <a class="reference internal" href="#flask.app.Flask.errorhandler" title="flask.app.Flask.errorhandler"><code class="xref py py-meth docutils literal"><span class="pre">errorhandler()</span></code></a>
  1039. decorator that is more straightforward to use for non decorator
  1040. usage.</p>
  1041. <div class="versionadded">
  1042. <p><span class="versionmodified">New in version 0.7.</span></p>
  1043. </div>
  1044. </dd></dl>
  1045. <dl class="attribute">
  1046. <dt id="flask.app.Flask.request_class">
  1047. <code class="descname">request_class</code><a class="headerlink" href="#flask.app.Flask.request_class" title="Permalink to this definition">¶</a></dt>
  1048. <dd><p>The class that is used for request objects. See <code class="xref py py-class docutils literal"><span class="pre">Request</span></code>
  1049. for more information.</p>
  1050. <p>alias of <code class="xref py py-class docutils literal"><span class="pre">Request</span></code></p>
  1051. </dd></dl>
  1052. <dl class="method">
  1053. <dt id="flask.app.Flask.request_context">
  1054. <code class="descname">request_context</code><span class="sig-paren">(</span><em>environ</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.request_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.request_context" title="Permalink to this definition">¶</a></dt>
  1055. <dd><p>Creates a <a class="reference internal" href="#flask.ctx.RequestContext" title="flask.ctx.RequestContext"><code class="xref py py-class docutils literal"><span class="pre">RequestContext</span></code></a> from the given
  1056. environment and binds it to the current context. This must be used in
  1057. combination with the <code class="docutils literal"><span class="pre">with</span></code> statement because the request is only bound
  1058. to the current context for the duration of the <code class="docutils literal"><span class="pre">with</span></code> block.</p>
  1059. <p>Example usage:</p>
  1060. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">app</span><span class="o">.</span><span class="n">request_context</span><span class="p">(</span><span class="n">environ</span><span class="p">):</span>
  1061. <span class="n">do_something_with</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
  1062. </pre></div>
  1063. </div>
  1064. <p>The object returned can also be used without the <code class="docutils literal"><span class="pre">with</span></code> statement
  1065. which is useful for working in the shell. The example above is
  1066. doing exactly the same as this code:</p>
  1067. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">ctx</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">request_context</span><span class="p">(</span><span class="n">environ</span><span class="p">)</span>
  1068. <span class="n">ctx</span><span class="o">.</span><span class="n">push</span><span class="p">()</span>
  1069. <span class="k">try</span><span class="p">:</span>
  1070. <span class="n">do_something_with</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
  1071. <span class="k">finally</span><span class="p">:</span>
  1072. <span class="n">ctx</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
  1073. </pre></div>
  1074. </div>
  1075. <div class="versionchanged">
  1076. <p><span class="versionmodified">Changed in version 0.3: </span>Added support for non-with statement usage and <code class="docutils literal"><span class="pre">with</span></code> statement
  1077. is now passed the ctx object.</p>
  1078. </div>
  1079. <table class="docutils field-list" frame="void" rules="none">
  1080. <col class="field-name" />
  1081. <col class="field-body" />
  1082. <tbody valign="top">
  1083. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>environ</strong> &#8211; a WSGI environment</td>
  1084. </tr>
  1085. </tbody>
  1086. </table>
  1087. </dd></dl>
  1088. <dl class="attribute">
  1089. <dt id="flask.app.Flask.request_globals_class">
  1090. <code class="descname">request_globals_class</code><a class="headerlink" href="#flask.app.Flask.request_globals_class" title="Permalink to this definition">¶</a></dt>
  1091. <dd></dd></dl>
  1092. <dl class="attribute">
  1093. <dt id="flask.app.Flask.response_class">
  1094. <code class="descname">response_class</code><a class="headerlink" href="#flask.app.Flask.response_class" title="Permalink to this definition">¶</a></dt>
  1095. <dd><p>The class that is used for response objects. See
  1096. <code class="xref py py-class docutils literal"><span class="pre">Response</span></code> for more information.</p>
  1097. <p>alias of <code class="xref py py-class docutils literal"><span class="pre">Response</span></code></p>
  1098. </dd></dl>
  1099. <dl class="method">
  1100. <dt id="flask.app.Flask.route">
  1101. <code class="descname">route</code><span class="sig-paren">(</span><em>rule</em>, <em>**options</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.route"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.route" title="Permalink to this definition">¶</a></dt>
  1102. <dd><p>A decorator that is used to register a view function for a
  1103. given URL rule. This does the same thing as <a class="reference internal" href="#flask.app.Flask.add_url_rule" title="flask.app.Flask.add_url_rule"><code class="xref py py-meth docutils literal"><span class="pre">add_url_rule()</span></code></a>
  1104. but is intended for decorator usage:</p>
  1105. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>
  1106. <span class="k">def</span> <span class="nf">index</span><span class="p">():</span>
  1107. <span class="k">return</span> <span class="s1">&#39;Hello World&#39;</span>
  1108. </pre></div>
  1109. </div>
  1110. <p>For more information refer to <span class="xref std std-ref">url-route-registrations</span>.</p>
  1111. <table class="docutils field-list" frame="void" rules="none">
  1112. <col class="field-name" />
  1113. <col class="field-body" />
  1114. <tbody valign="top">
  1115. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  1116. <li><strong>rule</strong> &#8211; the URL rule as string</li>
  1117. <li><strong>endpoint</strong> &#8211; the endpoint for the registered URL rule. Flask
  1118. itself assumes the name of the view function as
  1119. endpoint</li>
  1120. <li><strong>options</strong> &#8211; the options to be forwarded to the underlying
  1121. <code class="xref py py-class docutils literal"><span class="pre">Rule</span></code> object. A change
  1122. to Werkzeug is handling of method options. methods
  1123. is a list of methods this rule should be limited
  1124. to (<code class="docutils literal"><span class="pre">GET</span></code>, <code class="docutils literal"><span class="pre">POST</span></code> etc.). By default a rule
  1125. just listens for <code class="docutils literal"><span class="pre">GET</span></code> (and implicitly <code class="docutils literal"><span class="pre">HEAD</span></code>).
  1126. Starting with Flask 0.6, <code class="docutils literal"><span class="pre">OPTIONS</span></code> is implicitly
  1127. added and handled by the standard request handling.</li>
  1128. </ul>
  1129. </td>
  1130. </tr>
  1131. </tbody>
  1132. </table>
  1133. </dd></dl>
  1134. <dl class="method">
  1135. <dt id="flask.app.Flask.run">
  1136. <code class="descname">run</code><span class="sig-paren">(</span><em>host=None</em>, <em>port=None</em>, <em>debug=None</em>, <em>**options</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.run"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.run" title="Permalink to this definition">¶</a></dt>
  1137. <dd><p>Runs the application on a local development server.</p>
  1138. <p>Do not use <code class="docutils literal"><span class="pre">run()</span></code> in a production setting. It is not intended to
  1139. meet security and performance requirements for a production server.
  1140. Instead, see <span class="xref std std-ref">deployment</span> for WSGI server recommendations.</p>
  1141. <p>If the <a class="reference internal" href="#flask.app.Flask.debug" title="flask.app.Flask.debug"><code class="xref py py-attr docutils literal"><span class="pre">debug</span></code></a> flag is set the server will automatically reload
  1142. for code changes and show a debugger in case an exception happened.</p>
  1143. <p>If you want to run the application in debug mode, but disable the
  1144. code execution on the interactive debugger, you can pass
  1145. <code class="docutils literal"><span class="pre">use_evalex=False</span></code> as parameter. This will keep the debugger&#8217;s
  1146. traceback screen active, but disable code execution.</p>
  1147. <p>It is not recommended to use this function for development with
  1148. automatic reloading as this is badly supported. Instead you should
  1149. be using the <strong class="command">flask</strong> command line script&#8217;s <code class="docutils literal"><span class="pre">run</span></code> support.</p>
  1150. <div class="admonition-keep-in-mind admonition">
  1151. <p class="first admonition-title">Keep in Mind</p>
  1152. <p class="last">Flask will suppress any server error with a generic error page
  1153. unless it is in debug mode. As such to enable just the
  1154. interactive debugger without the code reloading, you have to
  1155. invoke <a class="reference internal" href="#flask.app.Flask.run" title="flask.app.Flask.run"><code class="xref py py-meth docutils literal"><span class="pre">run()</span></code></a> with <code class="docutils literal"><span class="pre">debug=True</span></code> and <code class="docutils literal"><span class="pre">use_reloader=False</span></code>.
  1156. Setting <code class="docutils literal"><span class="pre">use_debugger</span></code> to <code class="docutils literal"><span class="pre">True</span></code> without being in debug mode
  1157. won&#8217;t catch any exceptions because there won&#8217;t be any to
  1158. catch.</p>
  1159. </div>
  1160. <div class="versionchanged">
  1161. <p><span class="versionmodified">Changed in version 0.10: </span>The default port is now picked from the <code class="docutils literal"><span class="pre">SERVER_NAME</span></code> variable.</p>
  1162. </div>
  1163. <table class="docutils field-list" frame="void" rules="none">
  1164. <col class="field-name" />
  1165. <col class="field-body" />
  1166. <tbody valign="top">
  1167. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  1168. <li><strong>host</strong> &#8211; the hostname to listen on. Set this to <code class="docutils literal"><span class="pre">'0.0.0.0'</span></code> to
  1169. have the server available externally as well. Defaults to
  1170. <code class="docutils literal"><span class="pre">'127.0.0.1'</span></code>.</li>
  1171. <li><strong>port</strong> &#8211; the port of the webserver. Defaults to <code class="docutils literal"><span class="pre">5000</span></code> or the
  1172. port defined in the <code class="docutils literal"><span class="pre">SERVER_NAME</span></code> config variable if
  1173. present.</li>
  1174. <li><strong>debug</strong> &#8211; if given, enable or disable debug mode.
  1175. See <a class="reference internal" href="#flask.app.Flask.debug" title="flask.app.Flask.debug"><code class="xref py py-attr docutils literal"><span class="pre">debug</span></code></a>.</li>
  1176. <li><strong>options</strong> &#8211; the options to be forwarded to the underlying
  1177. Werkzeug server. See
  1178. <code class="xref py py-func docutils literal"><span class="pre">werkzeug.serving.run_simple()</span></code> for more
  1179. information.</li>
  1180. </ul>
  1181. </td>
  1182. </tr>
  1183. </tbody>
  1184. </table>
  1185. </dd></dl>
  1186. <dl class="method">
  1187. <dt id="flask.app.Flask.save_session">
  1188. <code class="descname">save_session</code><span class="sig-paren">(</span><em>session</em>, <em>response</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.save_session"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.save_session" title="Permalink to this definition">¶</a></dt>
  1189. <dd><p>Saves the session if it needs updates. For the default
  1190. implementation, check <a class="reference internal" href="#flask.app.Flask.open_session" title="flask.app.Flask.open_session"><code class="xref py py-meth docutils literal"><span class="pre">open_session()</span></code></a>. Instead of overriding this
  1191. method we recommend replacing the <a class="reference internal" href="#flask.app.Flask.session_interface" title="flask.app.Flask.session_interface"><code class="xref py py-class docutils literal"><span class="pre">session_interface</span></code></a>.</p>
  1192. <table class="docutils field-list" frame="void" rules="none">
  1193. <col class="field-name" />
  1194. <col class="field-body" />
  1195. <tbody valign="top">
  1196. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  1197. <li><strong>session</strong> &#8211; the session to be saved (a
  1198. <code class="xref py py-class docutils literal"><span class="pre">SecureCookie</span></code>
  1199. object)</li>
  1200. <li><strong>response</strong> &#8211; an instance of <a class="reference internal" href="#flask.app.Flask.response_class" title="flask.app.Flask.response_class"><code class="xref py py-attr docutils literal"><span class="pre">response_class</span></code></a></li>
  1201. </ul>
  1202. </td>
  1203. </tr>
  1204. </tbody>
  1205. </table>
  1206. </dd></dl>
  1207. <dl class="attribute">
  1208. <dt id="flask.app.Flask.secret_key">
  1209. <code class="descname">secret_key</code><a class="headerlink" href="#flask.app.Flask.secret_key" title="Permalink to this definition">¶</a></dt>
  1210. <dd><p>If a secret key is set, cryptographic components can use this to
  1211. sign cookies and other things. Set this to a complex random value
  1212. when you want to use the secure cookie for instance.</p>
  1213. <p>This attribute can also be configured from the config with the
  1214. <code class="docutils literal"><span class="pre">SECRET_KEY</span></code> configuration key. Defaults to <code class="docutils literal"><span class="pre">None</span></code>.</p>
  1215. </dd></dl>
  1216. <dl class="method">
  1217. <dt id="flask.app.Flask.select_jinja_autoescape">
  1218. <code class="descname">select_jinja_autoescape</code><span class="sig-paren">(</span><em>filename</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.select_jinja_autoescape"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.select_jinja_autoescape" title="Permalink to this definition">¶</a></dt>
  1219. <dd><p>Returns <code class="docutils literal"><span class="pre">True</span></code> if autoescaping should be active for the given
  1220. template name. If no template name is given, returns <cite>True</cite>.</p>
  1221. <div class="versionadded">
  1222. <p><span class="versionmodified">New in version 0.5.</span></p>
  1223. </div>
  1224. </dd></dl>
  1225. <dl class="attribute">
  1226. <dt id="flask.app.Flask.send_file_max_age_default">
  1227. <code class="descname">send_file_max_age_default</code><a class="headerlink" href="#flask.app.Flask.send_file_max_age_default" title="Permalink to this definition">¶</a></dt>
  1228. <dd><p>A <code class="xref py py-class docutils literal"><span class="pre">timedelta</span></code> which is used as default cache_timeout
  1229. for the <code class="xref py py-func docutils literal"><span class="pre">send_file()</span></code> functions. The default is 12 hours.</p>
  1230. <p>This attribute can also be configured from the config with the
  1231. <code class="docutils literal"><span class="pre">SEND_FILE_MAX_AGE_DEFAULT</span></code> configuration key. This configuration
  1232. variable can also be set with an integer value used as seconds.
  1233. Defaults to <code class="docutils literal"><span class="pre">timedelta(hours=12)</span></code></p>
  1234. </dd></dl>
  1235. <dl class="attribute">
  1236. <dt id="flask.app.Flask.session_cookie_name">
  1237. <code class="descname">session_cookie_name</code><a class="headerlink" href="#flask.app.Flask.session_cookie_name" title="Permalink to this definition">¶</a></dt>
  1238. <dd><p>The secure cookie uses this for the name of the session cookie.</p>
  1239. <p>This attribute can also be configured from the config with the
  1240. <code class="docutils literal"><span class="pre">SESSION_COOKIE_NAME</span></code> configuration key. Defaults to <code class="docutils literal"><span class="pre">'session'</span></code></p>
  1241. </dd></dl>
  1242. <dl class="attribute">
  1243. <dt id="flask.app.Flask.session_interface">
  1244. <code class="descname">session_interface</code><em class="property"> = &lt;flask.sessions.SecureCookieSessionInterface object at 0x000001E1821AB278&gt;</em><a class="headerlink" href="#flask.app.Flask.session_interface" title="Permalink to this definition">¶</a></dt>
  1245. <dd><p>the session interface to use. By default an instance of
  1246. <a class="reference internal" href="#flask.sessions.SecureCookieSessionInterface" title="flask.sessions.SecureCookieSessionInterface"><code class="xref py py-class docutils literal"><span class="pre">SecureCookieSessionInterface</span></code></a> is used here.</p>
  1247. <div class="versionadded">
  1248. <p><span class="versionmodified">New in version 0.8.</span></p>
  1249. </div>
  1250. </dd></dl>
  1251. <dl class="method">
  1252. <dt id="flask.app.Flask.shell_context_processor">
  1253. <code class="descname">shell_context_processor</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.shell_context_processor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.shell_context_processor" title="Permalink to this definition">¶</a></dt>
  1254. <dd><p>Registers a shell context processor function.</p>
  1255. <div class="versionadded">
  1256. <p><span class="versionmodified">New in version 0.11.</span></p>
  1257. </div>
  1258. </dd></dl>
  1259. <dl class="attribute">
  1260. <dt id="flask.app.Flask.shell_context_processors">
  1261. <code class="descname">shell_context_processors</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.shell_context_processors" title="Permalink to this definition">¶</a></dt>
  1262. <dd><p>A list of shell context processor functions that should be run
  1263. when a shell context is created.</p>
  1264. <div class="versionadded">
  1265. <p><span class="versionmodified">New in version 0.11.</span></p>
  1266. </div>
  1267. </dd></dl>
  1268. <dl class="method">
  1269. <dt id="flask.app.Flask.should_ignore_error">
  1270. <code class="descname">should_ignore_error</code><span class="sig-paren">(</span><em>error</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.should_ignore_error"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.should_ignore_error" title="Permalink to this definition">¶</a></dt>
  1271. <dd><p>This is called to figure out if an error should be ignored
  1272. or not as far as the teardown system is concerned. If this
  1273. function returns <code class="docutils literal"><span class="pre">True</span></code> then the teardown handlers will not be
  1274. passed the error.</p>
  1275. <div class="versionadded">
  1276. <p><span class="versionmodified">New in version 0.10.</span></p>
  1277. </div>
  1278. </dd></dl>
  1279. <dl class="method">
  1280. <dt id="flask.app.Flask.teardown_appcontext">
  1281. <code class="descname">teardown_appcontext</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.teardown_appcontext"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.teardown_appcontext" title="Permalink to this definition">¶</a></dt>
  1282. <dd><p>Registers a function to be called when the application context
  1283. ends. These functions are typically also called when the request
  1284. context is popped.</p>
  1285. <p>Example:</p>
  1286. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">ctx</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">app_context</span><span class="p">()</span>
  1287. <span class="n">ctx</span><span class="o">.</span><span class="n">push</span><span class="p">()</span>
  1288. <span class="o">...</span>
  1289. <span class="n">ctx</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
  1290. </pre></div>
  1291. </div>
  1292. <p>When <code class="docutils literal"><span class="pre">ctx.pop()</span></code> is executed in the above example, the teardown
  1293. functions are called just before the app context moves from the
  1294. stack of active contexts. This becomes relevant if you are using
  1295. such constructs in tests.</p>
  1296. <p>Since a request context typically also manages an application
  1297. context it would also be called when you pop a request context.</p>
  1298. <p>When a teardown function was called because of an exception it will
  1299. be passed an error object.</p>
  1300. <p>The return values of teardown functions are ignored.</p>
  1301. <div class="versionadded">
  1302. <p><span class="versionmodified">New in version 0.9.</span></p>
  1303. </div>
  1304. </dd></dl>
  1305. <dl class="attribute">
  1306. <dt id="flask.app.Flask.teardown_appcontext_funcs">
  1307. <code class="descname">teardown_appcontext_funcs</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.teardown_appcontext_funcs" title="Permalink to this definition">¶</a></dt>
  1308. <dd><p>A list of functions that are called when the application context
  1309. is destroyed. Since the application context is also torn down
  1310. if the request ends this is the place to store code that disconnects
  1311. from databases.</p>
  1312. <div class="versionadded">
  1313. <p><span class="versionmodified">New in version 0.9.</span></p>
  1314. </div>
  1315. </dd></dl>
  1316. <dl class="method">
  1317. <dt id="flask.app.Flask.teardown_request">
  1318. <code class="descname">teardown_request</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.teardown_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.teardown_request" title="Permalink to this definition">¶</a></dt>
  1319. <dd><p>Register a function to be run at the end of each request,
  1320. regardless of whether there was an exception or not. These functions
  1321. are executed when the request context is popped, even if not an
  1322. actual request was performed.</p>
  1323. <p>Example:</p>
  1324. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">ctx</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">test_request_context</span><span class="p">()</span>
  1325. <span class="n">ctx</span><span class="o">.</span><span class="n">push</span><span class="p">()</span>
  1326. <span class="o">...</span>
  1327. <span class="n">ctx</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
  1328. </pre></div>
  1329. </div>
  1330. <p>When <code class="docutils literal"><span class="pre">ctx.pop()</span></code> is executed in the above example, the teardown
  1331. functions are called just before the request context moves from the
  1332. stack of active contexts. This becomes relevant if you are using
  1333. such constructs in tests.</p>
  1334. <p>Generally teardown functions must take every necessary step to avoid
  1335. that they will fail. If they do execute code that might fail they
  1336. will have to surround the execution of these code by try/except
  1337. statements and log occurring errors.</p>
  1338. <p>When a teardown function was called because of a exception it will
  1339. be passed an error object.</p>
  1340. <p>The return values of teardown functions are ignored.</p>
  1341. <div class="admonition-debug-note admonition">
  1342. <p class="first admonition-title">Debug Note</p>
  1343. <p class="last">In debug mode Flask will not tear down a request on an exception
  1344. immediately. Instead it will keep it alive so that the interactive
  1345. debugger can still access it. This behavior can be controlled
  1346. by the <code class="docutils literal"><span class="pre">PRESERVE_CONTEXT_ON_EXCEPTION</span></code> configuration variable.</p>
  1347. </div>
  1348. </dd></dl>
  1349. <dl class="attribute">
  1350. <dt id="flask.app.Flask.teardown_request_funcs">
  1351. <code class="descname">teardown_request_funcs</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.teardown_request_funcs" title="Permalink to this definition">¶</a></dt>
  1352. <dd><p>A dictionary with lists of functions that are called after
  1353. each request, even if an exception has occurred. The key of the
  1354. dictionary is the name of the blueprint this function is active for,
  1355. <code class="docutils literal"><span class="pre">None</span></code> for all requests. These functions are not allowed to modify
  1356. the request, and their return values are ignored. If an exception
  1357. occurred while processing the request, it gets passed to each
  1358. teardown_request function. To register a function here, use the
  1359. <a class="reference internal" href="#flask.app.Flask.teardown_request" title="flask.app.Flask.teardown_request"><code class="xref py py-meth docutils literal"><span class="pre">teardown_request()</span></code></a> decorator.</p>
  1360. <div class="versionadded">
  1361. <p><span class="versionmodified">New in version 0.7.</span></p>
  1362. </div>
  1363. </dd></dl>
  1364. <dl class="attribute">
  1365. <dt id="flask.app.Flask.template_context_processors">
  1366. <code class="descname">template_context_processors</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.template_context_processors" title="Permalink to this definition">¶</a></dt>
  1367. <dd><p>A dictionary with list of functions that are called without argument
  1368. to populate the template context. The key of the dictionary is the
  1369. name of the blueprint this function is active for, <code class="docutils literal"><span class="pre">None</span></code> for all
  1370. requests. Each returns a dictionary that the template context is
  1371. updated with. To register a function here, use the
  1372. <a class="reference internal" href="#flask.app.Flask.context_processor" title="flask.app.Flask.context_processor"><code class="xref py py-meth docutils literal"><span class="pre">context_processor()</span></code></a> decorator.</p>
  1373. </dd></dl>
  1374. <dl class="method">
  1375. <dt id="flask.app.Flask.template_filter">
  1376. <code class="descname">template_filter</code><span class="sig-paren">(</span><em>name=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.template_filter"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.template_filter" title="Permalink to this definition">¶</a></dt>
  1377. <dd><p>A decorator that is used to register custom template filter.
  1378. You can specify a name for the filter, otherwise the function
  1379. name will be used. Example:</p>
  1380. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">template_filter</span><span class="p">()</span>
  1381. <span class="k">def</span> <span class="nf">reverse</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
  1382. <span class="k">return</span> <span class="n">s</span><span class="p">[::</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
  1383. </pre></div>
  1384. </div>
  1385. <table class="docutils field-list" frame="void" rules="none">
  1386. <col class="field-name" />
  1387. <col class="field-body" />
  1388. <tbody valign="top">
  1389. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> &#8211; the optional name of the filter, otherwise the
  1390. function name will be used.</td>
  1391. </tr>
  1392. </tbody>
  1393. </table>
  1394. </dd></dl>
  1395. <dl class="method">
  1396. <dt id="flask.app.Flask.template_global">
  1397. <code class="descname">template_global</code><span class="sig-paren">(</span><em>name=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.template_global"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.template_global" title="Permalink to this definition">¶</a></dt>
  1398. <dd><p>A decorator that is used to register a custom template global function.
  1399. You can specify a name for the global function, otherwise the function
  1400. name will be used. Example:</p>
  1401. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">template_global</span><span class="p">()</span>
  1402. <span class="k">def</span> <span class="nf">double</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
  1403. <span class="k">return</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">n</span>
  1404. </pre></div>
  1405. </div>
  1406. <div class="versionadded">
  1407. <p><span class="versionmodified">New in version 0.10.</span></p>
  1408. </div>
  1409. <table class="docutils field-list" frame="void" rules="none">
  1410. <col class="field-name" />
  1411. <col class="field-body" />
  1412. <tbody valign="top">
  1413. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> &#8211; the optional name of the global function, otherwise the
  1414. function name will be used.</td>
  1415. </tr>
  1416. </tbody>
  1417. </table>
  1418. </dd></dl>
  1419. <dl class="method">
  1420. <dt id="flask.app.Flask.template_test">
  1421. <code class="descname">template_test</code><span class="sig-paren">(</span><em>name=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.template_test"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.template_test" title="Permalink to this definition">¶</a></dt>
  1422. <dd><p>A decorator that is used to register custom template test.
  1423. You can specify a name for the test, otherwise the function
  1424. name will be used. Example:</p>
  1425. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">template_test</span><span class="p">()</span>
  1426. <span class="k">def</span> <span class="nf">is_prime</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
  1427. <span class="k">if</span> <span class="n">n</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
  1428. <span class="k">return</span> <span class="kc">True</span>
  1429. <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">n</span><span class="p">)))</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
  1430. <span class="k">if</span> <span class="n">n</span> <span class="o">%</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
  1431. <span class="k">return</span> <span class="kc">False</span>
  1432. <span class="k">return</span> <span class="kc">True</span>
  1433. </pre></div>
  1434. </div>
  1435. <div class="versionadded">
  1436. <p><span class="versionmodified">New in version 0.10.</span></p>
  1437. </div>
  1438. <table class="docutils field-list" frame="void" rules="none">
  1439. <col class="field-name" />
  1440. <col class="field-body" />
  1441. <tbody valign="top">
  1442. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> &#8211; the optional name of the test, otherwise the
  1443. function name will be used.</td>
  1444. </tr>
  1445. </tbody>
  1446. </table>
  1447. </dd></dl>
  1448. <dl class="method">
  1449. <dt id="flask.app.Flask.test_client">
  1450. <code class="descname">test_client</code><span class="sig-paren">(</span><em>use_cookies=True</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.test_client"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.test_client" title="Permalink to this definition">¶</a></dt>
  1451. <dd><p>Creates a test client for this application. For information
  1452. about unit testing head over to <span class="xref std std-ref">testing</span>.</p>
  1453. <p>Note that if you are testing for assertions or exceptions in your
  1454. application code, you must set <code class="docutils literal"><span class="pre">app.testing</span> <span class="pre">=</span> <span class="pre">True</span></code> in order for the
  1455. exceptions to propagate to the test client. Otherwise, the exception
  1456. will be handled by the application (not visible to the test client) and
  1457. the only indication of an AssertionError or other exception will be a
  1458. 500 status code response to the test client. See the <a class="reference internal" href="#flask.app.Flask.testing" title="flask.app.Flask.testing"><code class="xref py py-attr docutils literal"><span class="pre">testing</span></code></a>
  1459. attribute. For example:</p>
  1460. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">testing</span> <span class="o">=</span> <span class="kc">True</span>
  1461. <span class="n">client</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">test_client</span><span class="p">()</span>
  1462. </pre></div>
  1463. </div>
  1464. <p>The test client can be used in a <code class="docutils literal"><span class="pre">with</span></code> block to defer the closing down
  1465. of the context until the end of the <code class="docutils literal"><span class="pre">with</span></code> block. This is useful if
  1466. you want to access the context locals for testing:</p>
  1467. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">app</span><span class="o">.</span><span class="n">test_client</span><span class="p">()</span> <span class="k">as</span> <span class="n">c</span><span class="p">:</span>
  1468. <span class="n">rv</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;/?vodka=42&#39;</span><span class="p">)</span>
  1469. <span class="k">assert</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s1">&#39;vodka&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;42&#39;</span>
  1470. </pre></div>
  1471. </div>
  1472. <p>Additionally, you may pass optional keyword arguments that will then
  1473. be passed to the application&#8217;s <a class="reference internal" href="#flask.app.Flask.test_client_class" title="flask.app.Flask.test_client_class"><code class="xref py py-attr docutils literal"><span class="pre">test_client_class</span></code></a> constructor.
  1474. For example:</p>
  1475. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">flask.testing</span> <span class="k">import</span> <span class="n">FlaskClient</span>
  1476. <span class="k">class</span> <span class="nc">CustomClient</span><span class="p">(</span><span class="n">FlaskClient</span><span class="p">):</span>
  1477. <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">authentication</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
  1478. <span class="n">FlaskClient</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
  1479. <span class="bp">self</span><span class="o">.</span><span class="n">_authentication</span> <span class="o">=</span> <span class="n">authentication</span>
  1480. <span class="n">app</span><span class="o">.</span><span class="n">test_client_class</span> <span class="o">=</span> <span class="n">CustomClient</span>
  1481. <span class="n">client</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">test_client</span><span class="p">(</span><span class="n">authentication</span><span class="o">=</span><span class="s1">&#39;Basic ....&#39;</span><span class="p">)</span>
  1482. </pre></div>
  1483. </div>
  1484. <p>See <a class="reference internal" href="#flask.testing.FlaskClient" title="flask.testing.FlaskClient"><code class="xref py py-class docutils literal"><span class="pre">FlaskClient</span></code></a> for more information.</p>
  1485. <div class="versionchanged">
  1486. <p><span class="versionmodified">Changed in version 0.4: </span>added support for <code class="docutils literal"><span class="pre">with</span></code> block usage for the client.</p>
  1487. </div>
  1488. <div class="versionadded">
  1489. <p><span class="versionmodified">New in version 0.7: </span>The <cite>use_cookies</cite> parameter was added as well as the ability
  1490. to override the client to be used by setting the
  1491. <a class="reference internal" href="#flask.app.Flask.test_client_class" title="flask.app.Flask.test_client_class"><code class="xref py py-attr docutils literal"><span class="pre">test_client_class</span></code></a> attribute.</p>
  1492. </div>
  1493. <div class="versionchanged">
  1494. <p><span class="versionmodified">Changed in version 0.11: </span>Added <cite>**kwargs</cite> to support passing additional keyword arguments to
  1495. the constructor of <a class="reference internal" href="#flask.app.Flask.test_client_class" title="flask.app.Flask.test_client_class"><code class="xref py py-attr docutils literal"><span class="pre">test_client_class</span></code></a>.</p>
  1496. </div>
  1497. </dd></dl>
  1498. <dl class="attribute">
  1499. <dt id="flask.app.Flask.test_client_class">
  1500. <code class="descname">test_client_class</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.test_client_class" title="Permalink to this definition">¶</a></dt>
  1501. <dd><p>the test client that is used with when <cite>test_client</cite> is used.</p>
  1502. <div class="versionadded">
  1503. <p><span class="versionmodified">New in version 0.7.</span></p>
  1504. </div>
  1505. </dd></dl>
  1506. <dl class="method">
  1507. <dt id="flask.app.Flask.test_request_context">
  1508. <code class="descname">test_request_context</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.test_request_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.test_request_context" title="Permalink to this definition">¶</a></dt>
  1509. <dd><p>Creates a WSGI environment from the given values (see
  1510. <code class="xref py py-class docutils literal"><span class="pre">werkzeug.test.EnvironBuilder</span></code> for more information, this
  1511. function accepts the same arguments).</p>
  1512. </dd></dl>
  1513. <dl class="attribute">
  1514. <dt id="flask.app.Flask.testing">
  1515. <code class="descname">testing</code><a class="headerlink" href="#flask.app.Flask.testing" title="Permalink to this definition">¶</a></dt>
  1516. <dd><p>The testing flag. Set this to <code class="docutils literal"><span class="pre">True</span></code> to enable the test mode of
  1517. Flask extensions (and in the future probably also Flask itself).
  1518. For example this might activate unittest helpers that have an
  1519. additional runtime cost which should not be enabled by default.</p>
  1520. <p>If this is enabled and PROPAGATE_EXCEPTIONS is not changed from the
  1521. default it&#8217;s implicitly enabled.</p>
  1522. <p>This attribute can also be configured from the config with the
  1523. <code class="docutils literal"><span class="pre">TESTING</span></code> configuration key. Defaults to <code class="docutils literal"><span class="pre">False</span></code>.</p>
  1524. </dd></dl>
  1525. <dl class="method">
  1526. <dt id="flask.app.Flask.trap_http_exception">
  1527. <code class="descname">trap_http_exception</code><span class="sig-paren">(</span><em>e</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.trap_http_exception"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.trap_http_exception" title="Permalink to this definition">¶</a></dt>
  1528. <dd><p>Checks if an HTTP exception should be trapped or not. By default
  1529. this will return <code class="docutils literal"><span class="pre">False</span></code> for all exceptions except for a bad request
  1530. key error if <code class="docutils literal"><span class="pre">TRAP_BAD_REQUEST_ERRORS</span></code> is set to <code class="docutils literal"><span class="pre">True</span></code>. It
  1531. also returns <code class="docutils literal"><span class="pre">True</span></code> if <code class="docutils literal"><span class="pre">TRAP_HTTP_EXCEPTIONS</span></code> is set to <code class="docutils literal"><span class="pre">True</span></code>.</p>
  1532. <p>This is called for all HTTP exceptions raised by a view function.
  1533. If it returns <code class="docutils literal"><span class="pre">True</span></code> for any exception the error handler for this
  1534. exception is not called and it shows up as regular exception in the
  1535. traceback. This is helpful for debugging implicitly raised HTTP
  1536. exceptions.</p>
  1537. <div class="versionadded">
  1538. <p><span class="versionmodified">New in version 0.8.</span></p>
  1539. </div>
  1540. </dd></dl>
  1541. <dl class="method">
  1542. <dt id="flask.app.Flask.try_trigger_before_first_request_functions">
  1543. <code class="descname">try_trigger_before_first_request_functions</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.try_trigger_before_first_request_functions"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.try_trigger_before_first_request_functions" title="Permalink to this definition">¶</a></dt>
  1544. <dd><p>Called before each request and will ensure that it triggers
  1545. the <a class="reference internal" href="#flask.app.Flask.before_first_request_funcs" title="flask.app.Flask.before_first_request_funcs"><code class="xref py py-attr docutils literal"><span class="pre">before_first_request_funcs</span></code></a> and only exactly once per
  1546. application instance (which means process usually).</p>
  1547. <table class="docutils field-list" frame="void" rules="none">
  1548. <col class="field-name" />
  1549. <col class="field-body" />
  1550. <tbody valign="top">
  1551. <tr class="field-odd field"><th class="field-name">Internal:</th><td class="field-body"></td>
  1552. </tr>
  1553. </tbody>
  1554. </table>
  1555. </dd></dl>
  1556. <dl class="method">
  1557. <dt id="flask.app.Flask.update_template_context">
  1558. <code class="descname">update_template_context</code><span class="sig-paren">(</span><em>context</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.update_template_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.update_template_context" title="Permalink to this definition">¶</a></dt>
  1559. <dd><p>Update the template context with some commonly used variables.
  1560. This injects request, session, config and g into the template
  1561. context as well as everything template context processors want
  1562. to inject. Note that the as of Flask 0.6, the original values
  1563. in the context will not be overridden if a context processor
  1564. decides to return a value with the same key.</p>
  1565. <table class="docutils field-list" frame="void" rules="none">
  1566. <col class="field-name" />
  1567. <col class="field-body" />
  1568. <tbody valign="top">
  1569. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>context</strong> &#8211; the context as a dictionary that is updated in place
  1570. to add extra variables.</td>
  1571. </tr>
  1572. </tbody>
  1573. </table>
  1574. </dd></dl>
  1575. <dl class="attribute">
  1576. <dt id="flask.app.Flask.url_build_error_handlers">
  1577. <code class="descname">url_build_error_handlers</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.url_build_error_handlers" title="Permalink to this definition">¶</a></dt>
  1578. <dd><p>A list of functions that are called when <code class="xref py py-meth docutils literal"><span class="pre">url_for()</span></code> raises a
  1579. <code class="xref py py-exc docutils literal"><span class="pre">BuildError</span></code>. Each function registered here
  1580. is called with <cite>error</cite>, <cite>endpoint</cite> and <cite>values</cite>. If a function
  1581. returns <code class="docutils literal"><span class="pre">None</span></code> or raises a <code class="xref py py-exc docutils literal"><span class="pre">BuildError</span></code> the next function is
  1582. tried.</p>
  1583. <div class="versionadded">
  1584. <p><span class="versionmodified">New in version 0.9.</span></p>
  1585. </div>
  1586. </dd></dl>
  1587. <dl class="attribute">
  1588. <dt id="flask.app.Flask.url_default_functions">
  1589. <code class="descname">url_default_functions</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.url_default_functions" title="Permalink to this definition">¶</a></dt>
  1590. <dd><p>A dictionary with lists of functions that can be used as URL value
  1591. preprocessors. The key <code class="docutils literal"><span class="pre">None</span></code> here is used for application wide
  1592. callbacks, otherwise the key is the name of the blueprint.
  1593. Each of these functions has the chance to modify the dictionary
  1594. of URL values before they are used as the keyword arguments of the
  1595. view function. For each function registered this one should also
  1596. provide a <a class="reference internal" href="#flask.app.Flask.url_defaults" title="flask.app.Flask.url_defaults"><code class="xref py py-meth docutils literal"><span class="pre">url_defaults()</span></code></a> function that adds the parameters
  1597. automatically again that were removed that way.</p>
  1598. <div class="versionadded">
  1599. <p><span class="versionmodified">New in version 0.7.</span></p>
  1600. </div>
  1601. </dd></dl>
  1602. <dl class="method">
  1603. <dt id="flask.app.Flask.url_defaults">
  1604. <code class="descname">url_defaults</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.url_defaults"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.url_defaults" title="Permalink to this definition">¶</a></dt>
  1605. <dd><p>Callback function for URL defaults for all view functions of the
  1606. application. It&#8217;s called with the endpoint and values and should
  1607. update the values passed in place.</p>
  1608. </dd></dl>
  1609. <dl class="attribute">
  1610. <dt id="flask.app.Flask.url_map">
  1611. <code class="descname">url_map</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.url_map" title="Permalink to this definition">¶</a></dt>
  1612. <dd><p>The <code class="xref py py-class docutils literal"><span class="pre">Map</span></code> for this instance. You can use
  1613. this to change the routing converters after the class was created
  1614. but before any routes are connected. Example:</p>
  1615. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">werkzeug.routing</span> <span class="k">import</span> <span class="n">BaseConverter</span>
  1616. <span class="k">class</span> <span class="nc">ListConverter</span><span class="p">(</span><span class="n">BaseConverter</span><span class="p">):</span>
  1617. <span class="k">def</span> <span class="nf">to_python</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
  1618. <span class="k">return</span> <span class="n">value</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">)</span>
  1619. <span class="k">def</span> <span class="nf">to_url</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span>
  1620. <span class="k">return</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">BaseConverter</span><span class="o">.</span><span class="n">to_url</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
  1621. <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">values</span><span class="p">)</span>
  1622. <span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span>
  1623. <span class="n">app</span><span class="o">.</span><span class="n">url_map</span><span class="o">.</span><span class="n">converters</span><span class="p">[</span><span class="s1">&#39;list&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ListConverter</span>
  1624. </pre></div>
  1625. </div>
  1626. </dd></dl>
  1627. <dl class="attribute">
  1628. <dt id="flask.app.Flask.url_rule_class">
  1629. <code class="descname">url_rule_class</code><a class="headerlink" href="#flask.app.Flask.url_rule_class" title="Permalink to this definition">¶</a></dt>
  1630. <dd><p>The rule object to use for URL rules created. This is used by
  1631. <a class="reference internal" href="#flask.app.Flask.add_url_rule" title="flask.app.Flask.add_url_rule"><code class="xref py py-meth docutils literal"><span class="pre">add_url_rule()</span></code></a>. Defaults to <code class="xref py py-class docutils literal"><span class="pre">werkzeug.routing.Rule</span></code>.</p>
  1632. <div class="versionadded">
  1633. <p><span class="versionmodified">New in version 0.7.</span></p>
  1634. </div>
  1635. <p>alias of <code class="xref py py-class docutils literal"><span class="pre">Rule</span></code></p>
  1636. </dd></dl>
  1637. <dl class="method">
  1638. <dt id="flask.app.Flask.url_value_preprocessor">
  1639. <code class="descname">url_value_preprocessor</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.url_value_preprocessor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.url_value_preprocessor" title="Permalink to this definition">¶</a></dt>
  1640. <dd><p>Registers a function as URL value preprocessor for all view
  1641. functions of the application. It&#8217;s called before the view functions
  1642. are called and can modify the url values provided.</p>
  1643. </dd></dl>
  1644. <dl class="attribute">
  1645. <dt id="flask.app.Flask.url_value_preprocessors">
  1646. <code class="descname">url_value_preprocessors</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.url_value_preprocessors" title="Permalink to this definition">¶</a></dt>
  1647. <dd><p>A dictionary with lists of functions that can be used as URL
  1648. value processor functions. Whenever a URL is built these functions
  1649. are called to modify the dictionary of values in place. The key
  1650. <code class="docutils literal"><span class="pre">None</span></code> here is used for application wide
  1651. callbacks, otherwise the key is the name of the blueprint.
  1652. Each of these functions has the chance to modify the dictionary</p>
  1653. <div class="versionadded">
  1654. <p><span class="versionmodified">New in version 0.7.</span></p>
  1655. </div>
  1656. </dd></dl>
  1657. <dl class="attribute">
  1658. <dt id="flask.app.Flask.use_x_sendfile">
  1659. <code class="descname">use_x_sendfile</code><a class="headerlink" href="#flask.app.Flask.use_x_sendfile" title="Permalink to this definition">¶</a></dt>
  1660. <dd><p>Enable this if you want to use the X-Sendfile feature. Keep in
  1661. mind that the server has to support this. This only affects files
  1662. sent with the <code class="xref py py-func docutils literal"><span class="pre">send_file()</span></code> method.</p>
  1663. <div class="versionadded">
  1664. <p><span class="versionmodified">New in version 0.2.</span></p>
  1665. </div>
  1666. <p>This attribute can also be configured from the config with the
  1667. <code class="docutils literal"><span class="pre">USE_X_SENDFILE</span></code> configuration key. Defaults to <code class="docutils literal"><span class="pre">False</span></code>.</p>
  1668. </dd></dl>
  1669. <dl class="attribute">
  1670. <dt id="flask.app.Flask.view_functions">
  1671. <code class="descname">view_functions</code><em class="property"> = None</em><a class="headerlink" href="#flask.app.Flask.view_functions" title="Permalink to this definition">¶</a></dt>
  1672. <dd><p>A dictionary of all view functions registered. The keys will
  1673. be function names which are also used to generate URLs and
  1674. the values are the function objects themselves.
  1675. To register a view function, use the <a class="reference internal" href="#flask.app.Flask.route" title="flask.app.Flask.route"><code class="xref py py-meth docutils literal"><span class="pre">route()</span></code></a> decorator.</p>
  1676. </dd></dl>
  1677. <dl class="method">
  1678. <dt id="flask.app.Flask.wsgi_app">
  1679. <code class="descname">wsgi_app</code><span class="sig-paren">(</span><em>environ</em>, <em>start_response</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#Flask.wsgi_app"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.Flask.wsgi_app" title="Permalink to this definition">¶</a></dt>
  1680. <dd><p>The actual WSGI application. This is not implemented in
  1681. <cite>__call__</cite> so that middlewares can be applied without losing a
  1682. reference to the class. So instead of doing this:</p>
  1683. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">app</span> <span class="o">=</span> <span class="n">MyMiddleware</span><span class="p">(</span><span class="n">app</span><span class="p">)</span>
  1684. </pre></div>
  1685. </div>
  1686. <p>It&#8217;s a better idea to do this instead:</p>
  1687. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">wsgi_app</span> <span class="o">=</span> <span class="n">MyMiddleware</span><span class="p">(</span><span class="n">app</span><span class="o">.</span><span class="n">wsgi_app</span><span class="p">)</span>
  1688. </pre></div>
  1689. </div>
  1690. <p>Then you still have the original application object around and
  1691. can continue to call methods on it.</p>
  1692. <div class="versionchanged">
  1693. <p><span class="versionmodified">Changed in version 0.7: </span>The behavior of the before and after request callbacks was changed
  1694. under error conditions and a new callback was added that will
  1695. always execute at the end of the request, independent on if an
  1696. error occurred or not. See <span class="xref std std-ref">callbacks-and-errors</span>.</p>
  1697. </div>
  1698. <table class="docutils field-list" frame="void" rules="none">
  1699. <col class="field-name" />
  1700. <col class="field-body" />
  1701. <tbody valign="top">
  1702. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  1703. <li><strong>environ</strong> &#8211; a WSGI environment</li>
  1704. <li><strong>start_response</strong> &#8211; a callable accepting a status code,
  1705. a list of headers and an optional
  1706. exception context to start the response</li>
  1707. </ul>
  1708. </td>
  1709. </tr>
  1710. </tbody>
  1711. </table>
  1712. </dd></dl>
  1713. </dd></dl>
  1714. <dl class="function">
  1715. <dt id="flask.app.setupmethod">
  1716. <code class="descclassname">flask.app.</code><code class="descname">setupmethod</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/app.html#setupmethod"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.app.setupmethod" title="Permalink to this definition">¶</a></dt>
  1717. <dd><p>Wraps a method so that it performs a check in debug mode if the
  1718. first request was already handled.</p>
  1719. </dd></dl>
  1720. </div>
  1721. </div>
  1722. <div class="section" id="module-flask.blueprints">
  1723. <span id="flask-blueprints-module"></span><h2>flask.blueprints module<a class="headerlink" href="#module-flask.blueprints" title="Permalink to this headline">¶</a></h2>
  1724. <div class="section" id="flask-blueprints">
  1725. <h3>flask.blueprints<a class="headerlink" href="#flask-blueprints" title="Permalink to this headline">¶</a></h3>
  1726. <p>Blueprints are the recommended way to implement larger or more
  1727. pluggable applications in Flask 0.7 and later.</p>
  1728. <table class="docutils field-list" frame="void" rules="none">
  1729. <col class="field-name" />
  1730. <col class="field-body" />
  1731. <tbody valign="top">
  1732. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  1733. <li>2015 by Armin Ronacher.</li>
  1734. </ol>
  1735. </td>
  1736. </tr>
  1737. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  1738. </td>
  1739. </tr>
  1740. </tbody>
  1741. </table>
  1742. <dl class="class">
  1743. <dt id="flask.blueprints.Blueprint">
  1744. <em class="property">class </em><code class="descclassname">flask.blueprints.</code><code class="descname">Blueprint</code><span class="sig-paren">(</span><em>name</em>, <em>import_name</em>, <em>static_folder=None</em>, <em>static_url_path=None</em>, <em>template_folder=None</em>, <em>url_prefix=None</em>, <em>subdomain=None</em>, <em>url_defaults=None</em>, <em>root_path=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint" title="Permalink to this definition">¶</a></dt>
  1745. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">flask.helpers._PackageBoundObject</span></code></p>
  1746. <p>Represents a blueprint. A blueprint is an object that records
  1747. functions that will be called with the
  1748. <a class="reference internal" href="#flask.blueprints.BlueprintSetupState" title="flask.blueprints.BlueprintSetupState"><code class="xref py py-class docutils literal"><span class="pre">BlueprintSetupState</span></code></a> later to register functions
  1749. or other things on the main application. See <span class="xref std std-ref">blueprints</span> for more
  1750. information.</p>
  1751. <div class="versionadded">
  1752. <p><span class="versionmodified">New in version 0.7.</span></p>
  1753. </div>
  1754. <dl class="method">
  1755. <dt id="flask.blueprints.Blueprint.add_app_template_filter">
  1756. <code class="descname">add_app_template_filter</code><span class="sig-paren">(</span><em>f</em>, <em>name=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.add_app_template_filter"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.add_app_template_filter" title="Permalink to this definition">¶</a></dt>
  1757. <dd><p>Register a custom template filter, available application wide. Like
  1758. <code class="xref py py-meth docutils literal"><span class="pre">Flask.add_template_filter()</span></code> but for a blueprint. Works exactly
  1759. like the <a class="reference internal" href="#flask.blueprints.Blueprint.app_template_filter" title="flask.blueprints.Blueprint.app_template_filter"><code class="xref py py-meth docutils literal"><span class="pre">app_template_filter()</span></code></a> decorator.</p>
  1760. <table class="docutils field-list" frame="void" rules="none">
  1761. <col class="field-name" />
  1762. <col class="field-body" />
  1763. <tbody valign="top">
  1764. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> &#8211; the optional name of the filter, otherwise the
  1765. function name will be used.</td>
  1766. </tr>
  1767. </tbody>
  1768. </table>
  1769. </dd></dl>
  1770. <dl class="method">
  1771. <dt id="flask.blueprints.Blueprint.add_app_template_global">
  1772. <code class="descname">add_app_template_global</code><span class="sig-paren">(</span><em>f</em>, <em>name=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.add_app_template_global"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.add_app_template_global" title="Permalink to this definition">¶</a></dt>
  1773. <dd><p>Register a custom template global, available application wide. Like
  1774. <code class="xref py py-meth docutils literal"><span class="pre">Flask.add_template_global()</span></code> but for a blueprint. Works exactly
  1775. like the <a class="reference internal" href="#flask.blueprints.Blueprint.app_template_global" title="flask.blueprints.Blueprint.app_template_global"><code class="xref py py-meth docutils literal"><span class="pre">app_template_global()</span></code></a> decorator.</p>
  1776. <div class="versionadded">
  1777. <p><span class="versionmodified">New in version 0.10.</span></p>
  1778. </div>
  1779. <table class="docutils field-list" frame="void" rules="none">
  1780. <col class="field-name" />
  1781. <col class="field-body" />
  1782. <tbody valign="top">
  1783. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> &#8211; the optional name of the global, otherwise the
  1784. function name will be used.</td>
  1785. </tr>
  1786. </tbody>
  1787. </table>
  1788. </dd></dl>
  1789. <dl class="method">
  1790. <dt id="flask.blueprints.Blueprint.add_app_template_test">
  1791. <code class="descname">add_app_template_test</code><span class="sig-paren">(</span><em>f</em>, <em>name=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.add_app_template_test"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.add_app_template_test" title="Permalink to this definition">¶</a></dt>
  1792. <dd><p>Register a custom template test, available application wide. Like
  1793. <code class="xref py py-meth docutils literal"><span class="pre">Flask.add_template_test()</span></code> but for a blueprint. Works exactly
  1794. like the <a class="reference internal" href="#flask.blueprints.Blueprint.app_template_test" title="flask.blueprints.Blueprint.app_template_test"><code class="xref py py-meth docutils literal"><span class="pre">app_template_test()</span></code></a> decorator.</p>
  1795. <div class="versionadded">
  1796. <p><span class="versionmodified">New in version 0.10.</span></p>
  1797. </div>
  1798. <table class="docutils field-list" frame="void" rules="none">
  1799. <col class="field-name" />
  1800. <col class="field-body" />
  1801. <tbody valign="top">
  1802. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> &#8211; the optional name of the test, otherwise the
  1803. function name will be used.</td>
  1804. </tr>
  1805. </tbody>
  1806. </table>
  1807. </dd></dl>
  1808. <dl class="method">
  1809. <dt id="flask.blueprints.Blueprint.add_url_rule">
  1810. <code class="descname">add_url_rule</code><span class="sig-paren">(</span><em>rule</em>, <em>endpoint=None</em>, <em>view_func=None</em>, <em>**options</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.add_url_rule"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.add_url_rule" title="Permalink to this definition">¶</a></dt>
  1811. <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.add_url_rule()</span></code> but for a blueprint. The endpoint for
  1812. the <code class="xref py py-func docutils literal"><span class="pre">url_for()</span></code> function is prefixed with the name of the blueprint.</p>
  1813. </dd></dl>
  1814. <dl class="method">
  1815. <dt id="flask.blueprints.Blueprint.after_app_request">
  1816. <code class="descname">after_app_request</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.after_app_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.after_app_request" title="Permalink to this definition">¶</a></dt>
  1817. <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.after_request()</span></code> but for a blueprint. Such a function
  1818. is executed after each request, even if outside of the blueprint.</p>
  1819. </dd></dl>
  1820. <dl class="method">
  1821. <dt id="flask.blueprints.Blueprint.after_request">
  1822. <code class="descname">after_request</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.after_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.after_request" title="Permalink to this definition">¶</a></dt>
  1823. <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.after_request()</span></code> but for a blueprint. This function
  1824. is only executed after each request that is handled by a function of
  1825. that blueprint.</p>
  1826. </dd></dl>
  1827. <dl class="method">
  1828. <dt id="flask.blueprints.Blueprint.app_context_processor">
  1829. <code class="descname">app_context_processor</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.app_context_processor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.app_context_processor" title="Permalink to this definition">¶</a></dt>
  1830. <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.context_processor()</span></code> but for a blueprint. Such a
  1831. function is executed each request, even if outside of the blueprint.</p>
  1832. </dd></dl>
  1833. <dl class="method">
  1834. <dt id="flask.blueprints.Blueprint.app_errorhandler">
  1835. <code class="descname">app_errorhandler</code><span class="sig-paren">(</span><em>code</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.app_errorhandler"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.app_errorhandler" title="Permalink to this definition">¶</a></dt>
  1836. <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.errorhandler()</span></code> but for a blueprint. This
  1837. handler is used for all requests, even if outside of the blueprint.</p>
  1838. </dd></dl>
  1839. <dl class="method">
  1840. <dt id="flask.blueprints.Blueprint.app_template_filter">
  1841. <code class="descname">app_template_filter</code><span class="sig-paren">(</span><em>name=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.app_template_filter"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.app_template_filter" title="Permalink to this definition">¶</a></dt>
  1842. <dd><p>Register a custom template filter, available application wide. Like
  1843. <code class="xref py py-meth docutils literal"><span class="pre">Flask.template_filter()</span></code> but for a blueprint.</p>
  1844. <table class="docutils field-list" frame="void" rules="none">
  1845. <col class="field-name" />
  1846. <col class="field-body" />
  1847. <tbody valign="top">
  1848. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> &#8211; the optional name of the filter, otherwise the
  1849. function name will be used.</td>
  1850. </tr>
  1851. </tbody>
  1852. </table>
  1853. </dd></dl>
  1854. <dl class="method">
  1855. <dt id="flask.blueprints.Blueprint.app_template_global">
  1856. <code class="descname">app_template_global</code><span class="sig-paren">(</span><em>name=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.app_template_global"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.app_template_global" title="Permalink to this definition">¶</a></dt>
  1857. <dd><p>Register a custom template global, available application wide. Like
  1858. <code class="xref py py-meth docutils literal"><span class="pre">Flask.template_global()</span></code> but for a blueprint.</p>
  1859. <div class="versionadded">
  1860. <p><span class="versionmodified">New in version 0.10.</span></p>
  1861. </div>
  1862. <table class="docutils field-list" frame="void" rules="none">
  1863. <col class="field-name" />
  1864. <col class="field-body" />
  1865. <tbody valign="top">
  1866. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> &#8211; the optional name of the global, otherwise the
  1867. function name will be used.</td>
  1868. </tr>
  1869. </tbody>
  1870. </table>
  1871. </dd></dl>
  1872. <dl class="method">
  1873. <dt id="flask.blueprints.Blueprint.app_template_test">
  1874. <code class="descname">app_template_test</code><span class="sig-paren">(</span><em>name=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.app_template_test"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.app_template_test" title="Permalink to this definition">¶</a></dt>
  1875. <dd><p>Register a custom template test, available application wide. Like
  1876. <code class="xref py py-meth docutils literal"><span class="pre">Flask.template_test()</span></code> but for a blueprint.</p>
  1877. <div class="versionadded">
  1878. <p><span class="versionmodified">New in version 0.10.</span></p>
  1879. </div>
  1880. <table class="docutils field-list" frame="void" rules="none">
  1881. <col class="field-name" />
  1882. <col class="field-body" />
  1883. <tbody valign="top">
  1884. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> &#8211; the optional name of the test, otherwise the
  1885. function name will be used.</td>
  1886. </tr>
  1887. </tbody>
  1888. </table>
  1889. </dd></dl>
  1890. <dl class="method">
  1891. <dt id="flask.blueprints.Blueprint.app_url_defaults">
  1892. <code class="descname">app_url_defaults</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.app_url_defaults"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.app_url_defaults" title="Permalink to this definition">¶</a></dt>
  1893. <dd><p>Same as <a class="reference internal" href="#flask.blueprints.Blueprint.url_defaults" title="flask.blueprints.Blueprint.url_defaults"><code class="xref py py-meth docutils literal"><span class="pre">url_defaults()</span></code></a> but application wide.</p>
  1894. </dd></dl>
  1895. <dl class="method">
  1896. <dt id="flask.blueprints.Blueprint.app_url_value_preprocessor">
  1897. <code class="descname">app_url_value_preprocessor</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.app_url_value_preprocessor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.app_url_value_preprocessor" title="Permalink to this definition">¶</a></dt>
  1898. <dd><p>Same as <a class="reference internal" href="#flask.blueprints.Blueprint.url_value_preprocessor" title="flask.blueprints.Blueprint.url_value_preprocessor"><code class="xref py py-meth docutils literal"><span class="pre">url_value_preprocessor()</span></code></a> but application wide.</p>
  1899. </dd></dl>
  1900. <dl class="method">
  1901. <dt id="flask.blueprints.Blueprint.before_app_first_request">
  1902. <code class="descname">before_app_first_request</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.before_app_first_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.before_app_first_request" title="Permalink to this definition">¶</a></dt>
  1903. <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.before_first_request()</span></code>. Such a function is
  1904. executed before the first request to the application.</p>
  1905. </dd></dl>
  1906. <dl class="method">
  1907. <dt id="flask.blueprints.Blueprint.before_app_request">
  1908. <code class="descname">before_app_request</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.before_app_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.before_app_request" title="Permalink to this definition">¶</a></dt>
  1909. <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.before_request()</span></code>. Such a function is executed
  1910. before each request, even if outside of a blueprint.</p>
  1911. </dd></dl>
  1912. <dl class="method">
  1913. <dt id="flask.blueprints.Blueprint.before_request">
  1914. <code class="descname">before_request</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.before_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.before_request" title="Permalink to this definition">¶</a></dt>
  1915. <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.before_request()</span></code> but for a blueprint. This function
  1916. is only executed before each request that is handled by a function of
  1917. that blueprint.</p>
  1918. </dd></dl>
  1919. <dl class="method">
  1920. <dt id="flask.blueprints.Blueprint.context_processor">
  1921. <code class="descname">context_processor</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.context_processor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.context_processor" title="Permalink to this definition">¶</a></dt>
  1922. <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.context_processor()</span></code> but for a blueprint. This
  1923. function is only executed for requests handled by a blueprint.</p>
  1924. </dd></dl>
  1925. <dl class="method">
  1926. <dt id="flask.blueprints.Blueprint.endpoint">
  1927. <code class="descname">endpoint</code><span class="sig-paren">(</span><em>endpoint</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.endpoint"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.endpoint" title="Permalink to this definition">¶</a></dt>
  1928. <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.endpoint()</span></code> but for a blueprint. This does not
  1929. prefix the endpoint with the blueprint name, this has to be done
  1930. explicitly by the user of this method. If the endpoint is prefixed
  1931. with a <cite>.</cite> it will be registered to the current blueprint, otherwise
  1932. it&#8217;s an application independent endpoint.</p>
  1933. </dd></dl>
  1934. <dl class="method">
  1935. <dt id="flask.blueprints.Blueprint.errorhandler">
  1936. <code class="descname">errorhandler</code><span class="sig-paren">(</span><em>code_or_exception</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.errorhandler"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.errorhandler" title="Permalink to this definition">¶</a></dt>
  1937. <dd><p>Registers an error handler that becomes active for this blueprint
  1938. only. Please be aware that routing does not happen local to a
  1939. blueprint so an error handler for 404 usually is not handled by
  1940. a blueprint unless it is caused inside a view function. Another
  1941. special case is the 500 internal server error which is always looked
  1942. up from the application.</p>
  1943. <p>Otherwise works as the <code class="xref py py-meth docutils literal"><span class="pre">errorhandler()</span></code> decorator
  1944. of the <code class="xref py py-class docutils literal"><span class="pre">Flask</span></code> object.</p>
  1945. </dd></dl>
  1946. <dl class="method">
  1947. <dt id="flask.blueprints.Blueprint.make_setup_state">
  1948. <code class="descname">make_setup_state</code><span class="sig-paren">(</span><em>app</em>, <em>options</em>, <em>first_registration=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.make_setup_state"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.make_setup_state" title="Permalink to this definition">¶</a></dt>
  1949. <dd><p>Creates an instance of <a class="reference internal" href="#flask.blueprints.BlueprintSetupState" title="flask.blueprints.BlueprintSetupState"><code class="xref py py-meth docutils literal"><span class="pre">BlueprintSetupState()</span></code></a>
  1950. object that is later passed to the register callback functions.
  1951. Subclasses can override this to return a subclass of the setup state.</p>
  1952. </dd></dl>
  1953. <dl class="method">
  1954. <dt id="flask.blueprints.Blueprint.record">
  1955. <code class="descname">record</code><span class="sig-paren">(</span><em>func</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.record"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.record" title="Permalink to this definition">¶</a></dt>
  1956. <dd><p>Registers a function that is called when the blueprint is
  1957. registered on the application. This function is called with the
  1958. state as argument as returned by the <a class="reference internal" href="#flask.blueprints.Blueprint.make_setup_state" title="flask.blueprints.Blueprint.make_setup_state"><code class="xref py py-meth docutils literal"><span class="pre">make_setup_state()</span></code></a>
  1959. method.</p>
  1960. </dd></dl>
  1961. <dl class="method">
  1962. <dt id="flask.blueprints.Blueprint.record_once">
  1963. <code class="descname">record_once</code><span class="sig-paren">(</span><em>func</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.record_once"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.record_once" title="Permalink to this definition">¶</a></dt>
  1964. <dd><p>Works like <a class="reference internal" href="#flask.blueprints.Blueprint.record" title="flask.blueprints.Blueprint.record"><code class="xref py py-meth docutils literal"><span class="pre">record()</span></code></a> but wraps the function in another
  1965. function that will ensure the function is only called once. If the
  1966. blueprint is registered a second time on the application, the
  1967. function passed is not called.</p>
  1968. </dd></dl>
  1969. <dl class="method">
  1970. <dt id="flask.blueprints.Blueprint.register">
  1971. <code class="descname">register</code><span class="sig-paren">(</span><em>app</em>, <em>options</em>, <em>first_registration=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.register"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.register" title="Permalink to this definition">¶</a></dt>
  1972. <dd><p>Called by <code class="xref py py-meth docutils literal"><span class="pre">Flask.register_blueprint()</span></code> to register a blueprint
  1973. on the application. This can be overridden to customize the register
  1974. behavior. Keyword arguments from
  1975. <code class="xref py py-func docutils literal"><span class="pre">register_blueprint()</span></code> are directly forwarded to this
  1976. method in the <cite>options</cite> dictionary.</p>
  1977. </dd></dl>
  1978. <dl class="method">
  1979. <dt id="flask.blueprints.Blueprint.register_error_handler">
  1980. <code class="descname">register_error_handler</code><span class="sig-paren">(</span><em>code_or_exception</em>, <em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.register_error_handler"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.register_error_handler" title="Permalink to this definition">¶</a></dt>
  1981. <dd><p>Non-decorator version of the <a class="reference internal" href="#flask.blueprints.Blueprint.errorhandler" title="flask.blueprints.Blueprint.errorhandler"><code class="xref py py-meth docutils literal"><span class="pre">errorhandler()</span></code></a> error attach
  1982. function, akin to the <code class="xref py py-meth docutils literal"><span class="pre">register_error_handler()</span></code>
  1983. application-wide function of the <code class="xref py py-class docutils literal"><span class="pre">Flask</span></code> object but
  1984. for error handlers limited to this blueprint.</p>
  1985. <div class="versionadded">
  1986. <p><span class="versionmodified">New in version 0.11.</span></p>
  1987. </div>
  1988. </dd></dl>
  1989. <dl class="method">
  1990. <dt id="flask.blueprints.Blueprint.route">
  1991. <code class="descname">route</code><span class="sig-paren">(</span><em>rule</em>, <em>**options</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.route"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.route" title="Permalink to this definition">¶</a></dt>
  1992. <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.route()</span></code> but for a blueprint. The endpoint for the
  1993. <code class="xref py py-func docutils literal"><span class="pre">url_for()</span></code> function is prefixed with the name of the blueprint.</p>
  1994. </dd></dl>
  1995. <dl class="method">
  1996. <dt id="flask.blueprints.Blueprint.teardown_app_request">
  1997. <code class="descname">teardown_app_request</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.teardown_app_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.teardown_app_request" title="Permalink to this definition">¶</a></dt>
  1998. <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.teardown_request()</span></code> but for a blueprint. Such a
  1999. function is executed when tearing down each request, even if outside of
  2000. the blueprint.</p>
  2001. </dd></dl>
  2002. <dl class="method">
  2003. <dt id="flask.blueprints.Blueprint.teardown_request">
  2004. <code class="descname">teardown_request</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.teardown_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.teardown_request" title="Permalink to this definition">¶</a></dt>
  2005. <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.teardown_request()</span></code> but for a blueprint. This
  2006. function is only executed when tearing down requests handled by a
  2007. function of that blueprint. Teardown request functions are executed
  2008. when the request context is popped, even when no actual request was
  2009. performed.</p>
  2010. </dd></dl>
  2011. <dl class="method">
  2012. <dt id="flask.blueprints.Blueprint.url_defaults">
  2013. <code class="descname">url_defaults</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.url_defaults"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.url_defaults" title="Permalink to this definition">¶</a></dt>
  2014. <dd><p>Callback function for URL defaults for this blueprint. It&#8217;s called
  2015. with the endpoint and values and should update the values passed
  2016. in place.</p>
  2017. </dd></dl>
  2018. <dl class="method">
  2019. <dt id="flask.blueprints.Blueprint.url_value_preprocessor">
  2020. <code class="descname">url_value_preprocessor</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#Blueprint.url_value_preprocessor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.Blueprint.url_value_preprocessor" title="Permalink to this definition">¶</a></dt>
  2021. <dd><p>Registers a function as URL value preprocessor for this
  2022. blueprint. It&#8217;s called before the view functions are called and
  2023. can modify the url values provided.</p>
  2024. </dd></dl>
  2025. <dl class="attribute">
  2026. <dt id="flask.blueprints.Blueprint.warn_on_modifications">
  2027. <code class="descname">warn_on_modifications</code><em class="property"> = False</em><a class="headerlink" href="#flask.blueprints.Blueprint.warn_on_modifications" title="Permalink to this definition">¶</a></dt>
  2028. <dd></dd></dl>
  2029. </dd></dl>
  2030. <dl class="class">
  2031. <dt id="flask.blueprints.BlueprintSetupState">
  2032. <em class="property">class </em><code class="descclassname">flask.blueprints.</code><code class="descname">BlueprintSetupState</code><span class="sig-paren">(</span><em>blueprint</em>, <em>app</em>, <em>options</em>, <em>first_registration</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#BlueprintSetupState"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.BlueprintSetupState" title="Permalink to this definition">¶</a></dt>
  2033. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
  2034. <p>Temporary holder object for registering a blueprint with the
  2035. application. An instance of this class is created by the
  2036. <code class="xref py py-meth docutils literal"><span class="pre">make_setup_state()</span></code> method and later passed
  2037. to all register callback functions.</p>
  2038. <dl class="method">
  2039. <dt id="flask.blueprints.BlueprintSetupState.add_url_rule">
  2040. <code class="descname">add_url_rule</code><span class="sig-paren">(</span><em>rule</em>, <em>endpoint=None</em>, <em>view_func=None</em>, <em>**options</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/blueprints.html#BlueprintSetupState.add_url_rule"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.blueprints.BlueprintSetupState.add_url_rule" title="Permalink to this definition">¶</a></dt>
  2041. <dd><p>A helper method to register a rule (and optionally a view function)
  2042. to the application. The endpoint is automatically prefixed with the
  2043. blueprint&#8217;s name.</p>
  2044. </dd></dl>
  2045. <dl class="attribute">
  2046. <dt id="flask.blueprints.BlueprintSetupState.app">
  2047. <code class="descname">app</code><em class="property"> = None</em><a class="headerlink" href="#flask.blueprints.BlueprintSetupState.app" title="Permalink to this definition">¶</a></dt>
  2048. <dd><p>a reference to the current application</p>
  2049. </dd></dl>
  2050. <dl class="attribute">
  2051. <dt id="flask.blueprints.BlueprintSetupState.blueprint">
  2052. <code class="descname">blueprint</code><em class="property"> = None</em><a class="headerlink" href="#flask.blueprints.BlueprintSetupState.blueprint" title="Permalink to this definition">¶</a></dt>
  2053. <dd><p>a reference to the blueprint that created this setup state.</p>
  2054. </dd></dl>
  2055. <dl class="attribute">
  2056. <dt id="flask.blueprints.BlueprintSetupState.first_registration">
  2057. <code class="descname">first_registration</code><em class="property"> = None</em><a class="headerlink" href="#flask.blueprints.BlueprintSetupState.first_registration" title="Permalink to this definition">¶</a></dt>
  2058. <dd><p>as blueprints can be registered multiple times with the
  2059. application and not everything wants to be registered
  2060. multiple times on it, this attribute can be used to figure
  2061. out if the blueprint was registered in the past already.</p>
  2062. </dd></dl>
  2063. <dl class="attribute">
  2064. <dt id="flask.blueprints.BlueprintSetupState.options">
  2065. <code class="descname">options</code><em class="property"> = None</em><a class="headerlink" href="#flask.blueprints.BlueprintSetupState.options" title="Permalink to this definition">¶</a></dt>
  2066. <dd><p>a dictionary with all options that were passed to the
  2067. <code class="xref py py-meth docutils literal"><span class="pre">register_blueprint()</span></code> method.</p>
  2068. </dd></dl>
  2069. <dl class="attribute">
  2070. <dt id="flask.blueprints.BlueprintSetupState.subdomain">
  2071. <code class="descname">subdomain</code><em class="property"> = None</em><a class="headerlink" href="#flask.blueprints.BlueprintSetupState.subdomain" title="Permalink to this definition">¶</a></dt>
  2072. <dd><p>The subdomain that the blueprint should be active for, <code class="docutils literal"><span class="pre">None</span></code>
  2073. otherwise.</p>
  2074. </dd></dl>
  2075. <dl class="attribute">
  2076. <dt id="flask.blueprints.BlueprintSetupState.url_defaults">
  2077. <code class="descname">url_defaults</code><em class="property"> = None</em><a class="headerlink" href="#flask.blueprints.BlueprintSetupState.url_defaults" title="Permalink to this definition">¶</a></dt>
  2078. <dd><p>A dictionary with URL defaults that is added to each and every
  2079. URL that was defined with the blueprint.</p>
  2080. </dd></dl>
  2081. <dl class="attribute">
  2082. <dt id="flask.blueprints.BlueprintSetupState.url_prefix">
  2083. <code class="descname">url_prefix</code><em class="property"> = None</em><a class="headerlink" href="#flask.blueprints.BlueprintSetupState.url_prefix" title="Permalink to this definition">¶</a></dt>
  2084. <dd><p>The prefix that should be used for all URLs defined on the
  2085. blueprint.</p>
  2086. </dd></dl>
  2087. </dd></dl>
  2088. </div>
  2089. </div>
  2090. <div class="section" id="module-flask.cli">
  2091. <span id="flask-cli-module"></span><h2>flask.cli module<a class="headerlink" href="#module-flask.cli" title="Permalink to this headline">¶</a></h2>
  2092. <div class="section" id="flask-cli">
  2093. <h3>flask.cli<a class="headerlink" href="#flask-cli" title="Permalink to this headline">¶</a></h3>
  2094. <p>A simple command line application to run flask apps.</p>
  2095. <table class="docutils field-list" frame="void" rules="none">
  2096. <col class="field-name" />
  2097. <col class="field-body" />
  2098. <tbody valign="top">
  2099. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  2100. <li>2015 by Armin Ronacher.</li>
  2101. </ol>
  2102. </td>
  2103. </tr>
  2104. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  2105. </td>
  2106. </tr>
  2107. </tbody>
  2108. </table>
  2109. <dl class="class">
  2110. <dt id="flask.cli.AppGroup">
  2111. <em class="property">class </em><code class="descclassname">flask.cli.</code><code class="descname">AppGroup</code><span class="sig-paren">(</span><em>name=None</em>, <em>commands=None</em>, <em>**attrs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#AppGroup"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.AppGroup" title="Permalink to this definition">¶</a></dt>
  2112. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">click.core.Group</span></code></p>
  2113. <p>This works similar to a regular click <code class="xref py py-class docutils literal"><span class="pre">Group</span></code> but it
  2114. changes the behavior of the <a class="reference internal" href="#flask.cli.AppGroup.command" title="flask.cli.AppGroup.command"><code class="xref py py-meth docutils literal"><span class="pre">command()</span></code></a> decorator so that it
  2115. automatically wraps the functions in <a class="reference internal" href="#flask.cli.with_appcontext" title="flask.cli.with_appcontext"><code class="xref py py-func docutils literal"><span class="pre">with_appcontext()</span></code></a>.</p>
  2116. <p>Not to be confused with <a class="reference internal" href="#flask.cli.FlaskGroup" title="flask.cli.FlaskGroup"><code class="xref py py-class docutils literal"><span class="pre">FlaskGroup</span></code></a>.</p>
  2117. <dl class="method">
  2118. <dt id="flask.cli.AppGroup.command">
  2119. <code class="descname">command</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#AppGroup.command"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.AppGroup.command" title="Permalink to this definition">¶</a></dt>
  2120. <dd><p>This works exactly like the method of the same name on a regular
  2121. <code class="xref py py-class docutils literal"><span class="pre">click.Group</span></code> but it wraps callbacks in <a class="reference internal" href="#flask.cli.with_appcontext" title="flask.cli.with_appcontext"><code class="xref py py-func docutils literal"><span class="pre">with_appcontext()</span></code></a>
  2122. unless it&#8217;s disabled by passing <code class="docutils literal"><span class="pre">with_appcontext=False</span></code>.</p>
  2123. </dd></dl>
  2124. <dl class="method">
  2125. <dt id="flask.cli.AppGroup.group">
  2126. <code class="descname">group</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#AppGroup.group"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.AppGroup.group" title="Permalink to this definition">¶</a></dt>
  2127. <dd><p>This works exactly like the method of the same name on a regular
  2128. <code class="xref py py-class docutils literal"><span class="pre">click.Group</span></code> but it defaults the group class to
  2129. <a class="reference internal" href="#flask.cli.AppGroup" title="flask.cli.AppGroup"><code class="xref py py-class docutils literal"><span class="pre">AppGroup</span></code></a>.</p>
  2130. </dd></dl>
  2131. </dd></dl>
  2132. <dl class="class">
  2133. <dt id="flask.cli.DispatchingApp">
  2134. <em class="property">class </em><code class="descclassname">flask.cli.</code><code class="descname">DispatchingApp</code><span class="sig-paren">(</span><em>loader</em>, <em>use_eager_loading=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#DispatchingApp"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.DispatchingApp" title="Permalink to this definition">¶</a></dt>
  2135. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
  2136. <p>Special application that dispatches to a flask application which
  2137. is imported by name in a background thread. If an error happens
  2138. it is is recorded and shows as part of the WSGI handling which in case
  2139. of the Werkzeug debugger means that it shows up in the browser.</p>
  2140. </dd></dl>
  2141. <dl class="class">
  2142. <dt id="flask.cli.FlaskGroup">
  2143. <em class="property">class </em><code class="descclassname">flask.cli.</code><code class="descname">FlaskGroup</code><span class="sig-paren">(</span><em>add_default_commands=True</em>, <em>create_app=None</em>, <em>**extra</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#FlaskGroup"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.FlaskGroup" title="Permalink to this definition">¶</a></dt>
  2144. <dd><p>Bases: <a class="reference internal" href="#flask.cli.AppGroup" title="flask.cli.AppGroup"><code class="xref py py-class docutils literal"><span class="pre">flask.cli.AppGroup</span></code></a></p>
  2145. <p>Special subclass of the <a class="reference internal" href="#flask.cli.AppGroup" title="flask.cli.AppGroup"><code class="xref py py-class docutils literal"><span class="pre">AppGroup</span></code></a> group that supports
  2146. loading more commands from the configured Flask app. Normally a
  2147. developer does not have to interface with this class but there are
  2148. some very advanced use cases for which it makes sense to create an
  2149. instance of this.</p>
  2150. <p>For information as of why this is useful see <span class="xref std std-ref">custom-scripts</span>.</p>
  2151. <table class="docutils field-list" frame="void" rules="none">
  2152. <col class="field-name" />
  2153. <col class="field-body" />
  2154. <tbody valign="top">
  2155. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  2156. <li><strong>add_default_commands</strong> &#8211; if this is True then the default run and
  2157. shell commands wil be added.</li>
  2158. <li><strong>create_app</strong> &#8211; an optional callback that is passed the script info
  2159. and returns the loaded app.</li>
  2160. </ul>
  2161. </td>
  2162. </tr>
  2163. </tbody>
  2164. </table>
  2165. <dl class="method">
  2166. <dt id="flask.cli.FlaskGroup.get_command">
  2167. <code class="descname">get_command</code><span class="sig-paren">(</span><em>ctx</em>, <em>name</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#FlaskGroup.get_command"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.FlaskGroup.get_command" title="Permalink to this definition">¶</a></dt>
  2168. <dd></dd></dl>
  2169. <dl class="method">
  2170. <dt id="flask.cli.FlaskGroup.list_commands">
  2171. <code class="descname">list_commands</code><span class="sig-paren">(</span><em>ctx</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#FlaskGroup.list_commands"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.FlaskGroup.list_commands" title="Permalink to this definition">¶</a></dt>
  2172. <dd></dd></dl>
  2173. <dl class="method">
  2174. <dt id="flask.cli.FlaskGroup.main">
  2175. <code class="descname">main</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#FlaskGroup.main"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.FlaskGroup.main" title="Permalink to this definition">¶</a></dt>
  2176. <dd></dd></dl>
  2177. </dd></dl>
  2178. <dl class="exception">
  2179. <dt id="flask.cli.NoAppException">
  2180. <em class="property">exception </em><code class="descclassname">flask.cli.</code><code class="descname">NoAppException</code><span class="sig-paren">(</span><em>message</em>, <em>ctx=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#NoAppException"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.NoAppException" title="Permalink to this definition">¶</a></dt>
  2181. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">click.exceptions.UsageError</span></code></p>
  2182. <p>Raised if an application cannot be found or loaded.</p>
  2183. </dd></dl>
  2184. <dl class="class">
  2185. <dt id="flask.cli.ScriptInfo">
  2186. <em class="property">class </em><code class="descclassname">flask.cli.</code><code class="descname">ScriptInfo</code><span class="sig-paren">(</span><em>app_import_path=None</em>, <em>create_app=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#ScriptInfo"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.ScriptInfo" title="Permalink to this definition">¶</a></dt>
  2187. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
  2188. <p>Help object to deal with Flask applications. This is usually not
  2189. necessary to interface with as it&#8217;s used internally in the dispatching
  2190. to click. In future versions of Flask this object will most likely play
  2191. a bigger role. Typically it&#8217;s created automatically by the
  2192. <a class="reference internal" href="#flask.cli.FlaskGroup" title="flask.cli.FlaskGroup"><code class="xref py py-class docutils literal"><span class="pre">FlaskGroup</span></code></a> but you can also manually create it and pass it
  2193. onwards as click object.</p>
  2194. <dl class="attribute">
  2195. <dt id="flask.cli.ScriptInfo.app_import_path">
  2196. <code class="descname">app_import_path</code><em class="property"> = None</em><a class="headerlink" href="#flask.cli.ScriptInfo.app_import_path" title="Permalink to this definition">¶</a></dt>
  2197. <dd><p>Optionally the import path for the Flask application.</p>
  2198. </dd></dl>
  2199. <dl class="attribute">
  2200. <dt id="flask.cli.ScriptInfo.create_app">
  2201. <code class="descname">create_app</code><em class="property"> = None</em><a class="headerlink" href="#flask.cli.ScriptInfo.create_app" title="Permalink to this definition">¶</a></dt>
  2202. <dd><p>Optionally a function that is passed the script info to create
  2203. the instance of the application.</p>
  2204. </dd></dl>
  2205. <dl class="attribute">
  2206. <dt id="flask.cli.ScriptInfo.data">
  2207. <code class="descname">data</code><em class="property"> = None</em><a class="headerlink" href="#flask.cli.ScriptInfo.data" title="Permalink to this definition">¶</a></dt>
  2208. <dd><p>A dictionary with arbitrary data that can be associated with
  2209. this script info.</p>
  2210. </dd></dl>
  2211. <dl class="method">
  2212. <dt id="flask.cli.ScriptInfo.load_app">
  2213. <code class="descname">load_app</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#ScriptInfo.load_app"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.ScriptInfo.load_app" title="Permalink to this definition">¶</a></dt>
  2214. <dd><p>Loads the Flask app (if not yet loaded) and returns it. Calling
  2215. this multiple times will just result in the already loaded app to
  2216. be returned.</p>
  2217. </dd></dl>
  2218. </dd></dl>
  2219. <dl class="function">
  2220. <dt id="flask.cli.find_best_app">
  2221. <code class="descclassname">flask.cli.</code><code class="descname">find_best_app</code><span class="sig-paren">(</span><em>module</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#find_best_app"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.find_best_app" title="Permalink to this definition">¶</a></dt>
  2222. <dd><p>Given a module instance this tries to find the best possible
  2223. application in the module or raises an exception.</p>
  2224. </dd></dl>
  2225. <dl class="function">
  2226. <dt id="flask.cli.find_default_import_path">
  2227. <code class="descclassname">flask.cli.</code><code class="descname">find_default_import_path</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#find_default_import_path"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.find_default_import_path" title="Permalink to this definition">¶</a></dt>
  2228. <dd></dd></dl>
  2229. <dl class="function">
  2230. <dt id="flask.cli.locate_app">
  2231. <code class="descclassname">flask.cli.</code><code class="descname">locate_app</code><span class="sig-paren">(</span><em>app_id</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#locate_app"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.locate_app" title="Permalink to this definition">¶</a></dt>
  2232. <dd><p>Attempts to locate the application.</p>
  2233. </dd></dl>
  2234. <dl class="function">
  2235. <dt id="flask.cli.main">
  2236. <code class="descclassname">flask.cli.</code><code class="descname">main</code><span class="sig-paren">(</span><em>as_module=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#main"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.main" title="Permalink to this definition">¶</a></dt>
  2237. <dd></dd></dl>
  2238. <dl class="function">
  2239. <dt id="flask.cli.prepare_exec_for_file">
  2240. <code class="descclassname">flask.cli.</code><code class="descname">prepare_exec_for_file</code><span class="sig-paren">(</span><em>filename</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#prepare_exec_for_file"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.prepare_exec_for_file" title="Permalink to this definition">¶</a></dt>
  2241. <dd><p>Given a filename this will try to calculate the python path, add it
  2242. to the search path and return the actual module name that is expected.</p>
  2243. </dd></dl>
  2244. <dl class="function">
  2245. <dt id="flask.cli.with_appcontext">
  2246. <code class="descclassname">flask.cli.</code><code class="descname">with_appcontext</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/cli.html#with_appcontext"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.cli.with_appcontext" title="Permalink to this definition">¶</a></dt>
  2247. <dd><p>Wraps a callback so that it&#8217;s guaranteed to be executed with the
  2248. script&#8217;s application context. If callbacks are registered directly
  2249. to the <code class="docutils literal"><span class="pre">app.cli</span></code> object then they are wrapped with this function
  2250. by default unless it&#8217;s disabled.</p>
  2251. </dd></dl>
  2252. </div>
  2253. </div>
  2254. <div class="section" id="module-flask.config">
  2255. <span id="flask-config-module"></span><h2>flask.config module<a class="headerlink" href="#module-flask.config" title="Permalink to this headline">¶</a></h2>
  2256. <div class="section" id="flask-config">
  2257. <h3>flask.config<a class="headerlink" href="#flask-config" title="Permalink to this headline">¶</a></h3>
  2258. <p>Implements the configuration related objects.</p>
  2259. <table class="docutils field-list" frame="void" rules="none">
  2260. <col class="field-name" />
  2261. <col class="field-body" />
  2262. <tbody valign="top">
  2263. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  2264. <li>2015 by Armin Ronacher.</li>
  2265. </ol>
  2266. </td>
  2267. </tr>
  2268. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  2269. </td>
  2270. </tr>
  2271. </tbody>
  2272. </table>
  2273. <dl class="class">
  2274. <dt id="flask.config.Config">
  2275. <em class="property">class </em><code class="descclassname">flask.config.</code><code class="descname">Config</code><span class="sig-paren">(</span><em>root_path</em>, <em>defaults=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/config.html#Config"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.config.Config" title="Permalink to this definition">¶</a></dt>
  2276. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">dict</span></code></p>
  2277. <p>Works exactly like a dict but provides ways to fill it from files
  2278. or special dictionaries. There are two common patterns to populate the
  2279. config.</p>
  2280. <p>Either you can fill the config from a config file:</p>
  2281. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">from_pyfile</span><span class="p">(</span><span class="s1">&#39;yourconfig.cfg&#39;</span><span class="p">)</span>
  2282. </pre></div>
  2283. </div>
  2284. <p>Or alternatively you can define the configuration options in the
  2285. module that calls <a class="reference internal" href="#flask.config.Config.from_object" title="flask.config.Config.from_object"><code class="xref py py-meth docutils literal"><span class="pre">from_object()</span></code></a> or provide an import path to
  2286. a module that should be loaded. It is also possible to tell it to
  2287. use the same module and with that provide the configuration values
  2288. just before the call:</p>
  2289. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">DEBUG</span> <span class="o">=</span> <span class="kc">True</span>
  2290. <span class="n">SECRET_KEY</span> <span class="o">=</span> <span class="s1">&#39;development key&#39;</span>
  2291. <span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">from_object</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span>
  2292. </pre></div>
  2293. </div>
  2294. <p>In both cases (loading from any Python file or loading from modules),
  2295. only uppercase keys are added to the config. This makes it possible to use
  2296. lowercase values in the config file for temporary values that are not added
  2297. to the config or to define the config keys in the same file that implements
  2298. the application.</p>
  2299. <p>Probably the most interesting way to load configurations is from an
  2300. environment variable pointing to a file:</p>
  2301. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">from_envvar</span><span class="p">(</span><span class="s1">&#39;YOURAPPLICATION_SETTINGS&#39;</span><span class="p">)</span>
  2302. </pre></div>
  2303. </div>
  2304. <p>In this case before launching the application you have to set this
  2305. environment variable to the file you want to use. On Linux and OS X
  2306. use the export statement:</p>
  2307. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">export</span> <span class="n">YOURAPPLICATION_SETTINGS</span><span class="o">=</span><span class="s1">&#39;/path/to/config/file&#39;</span>
  2308. </pre></div>
  2309. </div>
  2310. <p>On windows use <cite>set</cite> instead.</p>
  2311. <table class="docutils field-list" frame="void" rules="none">
  2312. <col class="field-name" />
  2313. <col class="field-body" />
  2314. <tbody valign="top">
  2315. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  2316. <li><strong>root_path</strong> &#8211; path to which files are read relative from. When the
  2317. config object is created by the application, this is
  2318. the application&#8217;s <code class="xref py py-attr docutils literal"><span class="pre">root_path</span></code>.</li>
  2319. <li><strong>defaults</strong> &#8211; an optional dictionary of default values</li>
  2320. </ul>
  2321. </td>
  2322. </tr>
  2323. </tbody>
  2324. </table>
  2325. <dl class="method">
  2326. <dt id="flask.config.Config.from_envvar">
  2327. <code class="descname">from_envvar</code><span class="sig-paren">(</span><em>variable_name</em>, <em>silent=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/config.html#Config.from_envvar"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.config.Config.from_envvar" title="Permalink to this definition">¶</a></dt>
  2328. <dd><p>Loads a configuration from an environment variable pointing to
  2329. a configuration file. This is basically just a shortcut with nicer
  2330. error messages for this line of code:</p>
  2331. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">from_pyfile</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;YOURAPPLICATION_SETTINGS&#39;</span><span class="p">])</span>
  2332. </pre></div>
  2333. </div>
  2334. <table class="docutils field-list" frame="void" rules="none">
  2335. <col class="field-name" />
  2336. <col class="field-body" />
  2337. <tbody valign="top">
  2338. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  2339. <li><strong>variable_name</strong> &#8211; name of the environment variable</li>
  2340. <li><strong>silent</strong> &#8211; set to <code class="docutils literal"><span class="pre">True</span></code> if you want silent failure for missing
  2341. files.</li>
  2342. </ul>
  2343. </td>
  2344. </tr>
  2345. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">bool. <code class="docutils literal"><span class="pre">True</span></code> if able to load config, <code class="docutils literal"><span class="pre">False</span></code> otherwise.</p>
  2346. </td>
  2347. </tr>
  2348. </tbody>
  2349. </table>
  2350. </dd></dl>
  2351. <dl class="method">
  2352. <dt id="flask.config.Config.from_json">
  2353. <code class="descname">from_json</code><span class="sig-paren">(</span><em>filename</em>, <em>silent=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/config.html#Config.from_json"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.config.Config.from_json" title="Permalink to this definition">¶</a></dt>
  2354. <dd><p>Updates the values in the config from a JSON file. This function
  2355. behaves as if the JSON object was a dictionary and passed to the
  2356. <a class="reference internal" href="#flask.config.Config.from_mapping" title="flask.config.Config.from_mapping"><code class="xref py py-meth docutils literal"><span class="pre">from_mapping()</span></code></a> function.</p>
  2357. <table class="docutils field-list" frame="void" rules="none">
  2358. <col class="field-name" />
  2359. <col class="field-body" />
  2360. <tbody valign="top">
  2361. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  2362. <li><strong>filename</strong> &#8211; the filename of the JSON file. This can either be an
  2363. absolute filename or a filename relative to the
  2364. root path.</li>
  2365. <li><strong>silent</strong> &#8211; set to <code class="docutils literal"><span class="pre">True</span></code> if you want silent failure for missing
  2366. files.</li>
  2367. </ul>
  2368. </td>
  2369. </tr>
  2370. </tbody>
  2371. </table>
  2372. <div class="versionadded">
  2373. <p><span class="versionmodified">New in version 0.11.</span></p>
  2374. </div>
  2375. </dd></dl>
  2376. <dl class="method">
  2377. <dt id="flask.config.Config.from_mapping">
  2378. <code class="descname">from_mapping</code><span class="sig-paren">(</span><em>*mapping</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/config.html#Config.from_mapping"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.config.Config.from_mapping" title="Permalink to this definition">¶</a></dt>
  2379. <dd><p>Updates the config like <code class="xref py py-meth docutils literal"><span class="pre">update()</span></code> ignoring items with non-upper
  2380. keys.</p>
  2381. <div class="versionadded">
  2382. <p><span class="versionmodified">New in version 0.11.</span></p>
  2383. </div>
  2384. </dd></dl>
  2385. <dl class="method">
  2386. <dt id="flask.config.Config.from_object">
  2387. <code class="descname">from_object</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/config.html#Config.from_object"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.config.Config.from_object" title="Permalink to this definition">¶</a></dt>
  2388. <dd><p>Updates the values from the given object. An object can be of one
  2389. of the following two types:</p>
  2390. <ul class="simple">
  2391. <li>a string: in this case the object with that name will be imported</li>
  2392. <li>an actual object reference: that object is used directly</li>
  2393. </ul>
  2394. <p>Objects are usually either modules or classes.</p>
  2395. <p>Just the uppercase variables in that object are stored in the config.
  2396. Example usage:</p>
  2397. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">from_object</span><span class="p">(</span><span class="s1">&#39;yourapplication.default_config&#39;</span><span class="p">)</span>
  2398. <span class="kn">from</span> <span class="nn">yourapplication</span> <span class="k">import</span> <span class="n">default_config</span>
  2399. <span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">from_object</span><span class="p">(</span><span class="n">default_config</span><span class="p">)</span>
  2400. </pre></div>
  2401. </div>
  2402. <p>You should not use this function to load the actual configuration but
  2403. rather configuration defaults. The actual config should be loaded
  2404. with <a class="reference internal" href="#flask.config.Config.from_pyfile" title="flask.config.Config.from_pyfile"><code class="xref py py-meth docutils literal"><span class="pre">from_pyfile()</span></code></a> and ideally from a location not within the
  2405. package because the package might be installed system wide.</p>
  2406. <table class="docutils field-list" frame="void" rules="none">
  2407. <col class="field-name" />
  2408. <col class="field-body" />
  2409. <tbody valign="top">
  2410. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>obj</strong> &#8211; an import name or object</td>
  2411. </tr>
  2412. </tbody>
  2413. </table>
  2414. </dd></dl>
  2415. <dl class="method">
  2416. <dt id="flask.config.Config.from_pyfile">
  2417. <code class="descname">from_pyfile</code><span class="sig-paren">(</span><em>filename</em>, <em>silent=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/config.html#Config.from_pyfile"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.config.Config.from_pyfile" title="Permalink to this definition">¶</a></dt>
  2418. <dd><p>Updates the values in the config from a Python file. This function
  2419. behaves as if the file was imported as module with the
  2420. <a class="reference internal" href="#flask.config.Config.from_object" title="flask.config.Config.from_object"><code class="xref py py-meth docutils literal"><span class="pre">from_object()</span></code></a> function.</p>
  2421. <table class="docutils field-list" frame="void" rules="none">
  2422. <col class="field-name" />
  2423. <col class="field-body" />
  2424. <tbody valign="top">
  2425. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  2426. <li><strong>filename</strong> &#8211; the filename of the config. This can either be an
  2427. absolute filename or a filename relative to the
  2428. root path.</li>
  2429. <li><strong>silent</strong> &#8211; set to <code class="docutils literal"><span class="pre">True</span></code> if you want silent failure for missing
  2430. files.</li>
  2431. </ul>
  2432. </td>
  2433. </tr>
  2434. </tbody>
  2435. </table>
  2436. <div class="versionadded">
  2437. <p><span class="versionmodified">New in version 0.7: </span><cite>silent</cite> parameter.</p>
  2438. </div>
  2439. </dd></dl>
  2440. <dl class="method">
  2441. <dt id="flask.config.Config.get_namespace">
  2442. <code class="descname">get_namespace</code><span class="sig-paren">(</span><em>namespace</em>, <em>lowercase=True</em>, <em>trim_namespace=True</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/config.html#Config.get_namespace"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.config.Config.get_namespace" title="Permalink to this definition">¶</a></dt>
  2443. <dd><p>Returns a dictionary containing a subset of configuration options
  2444. that match the specified namespace/prefix. Example usage:</p>
  2445. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;IMAGE_STORE_TYPE&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;fs&#39;</span>
  2446. <span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;IMAGE_STORE_PATH&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;/var/app/images&#39;</span>
  2447. <span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;IMAGE_STORE_BASE_URL&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;http://img.website.com&#39;</span>
  2448. <span class="n">image_store_config</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">get_namespace</span><span class="p">(</span><span class="s1">&#39;IMAGE_STORE_&#39;</span><span class="p">)</span>
  2449. </pre></div>
  2450. </div>
  2451. <p>The resulting dictionary <cite>image_store_config</cite> would look like:</p>
  2452. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="p">{</span>
  2453. <span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="s1">&#39;fs&#39;</span><span class="p">,</span>
  2454. <span class="s1">&#39;path&#39;</span><span class="p">:</span> <span class="s1">&#39;/var/app/images&#39;</span><span class="p">,</span>
  2455. <span class="s1">&#39;base_url&#39;</span><span class="p">:</span> <span class="s1">&#39;http://img.website.com&#39;</span>
  2456. <span class="p">}</span>
  2457. </pre></div>
  2458. </div>
  2459. <p>This is often useful when configuration options map directly to
  2460. keyword arguments in functions or class constructors.</p>
  2461. <table class="docutils field-list" frame="void" rules="none">
  2462. <col class="field-name" />
  2463. <col class="field-body" />
  2464. <tbody valign="top">
  2465. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  2466. <li><strong>namespace</strong> &#8211; a configuration namespace</li>
  2467. <li><strong>lowercase</strong> &#8211; a flag indicating if the keys of the resulting
  2468. dictionary should be lowercase</li>
  2469. <li><strong>trim_namespace</strong> &#8211; a flag indicating if the keys of the resulting
  2470. dictionary should not include the namespace</li>
  2471. </ul>
  2472. </td>
  2473. </tr>
  2474. </tbody>
  2475. </table>
  2476. <div class="versionadded">
  2477. <p><span class="versionmodified">New in version 0.11.</span></p>
  2478. </div>
  2479. </dd></dl>
  2480. </dd></dl>
  2481. <dl class="class">
  2482. <dt id="flask.config.ConfigAttribute">
  2483. <em class="property">class </em><code class="descclassname">flask.config.</code><code class="descname">ConfigAttribute</code><span class="sig-paren">(</span><em>name</em>, <em>get_converter=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/config.html#ConfigAttribute"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.config.ConfigAttribute" title="Permalink to this definition">¶</a></dt>
  2484. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
  2485. <p>Makes an attribute forward to the config</p>
  2486. </dd></dl>
  2487. </div>
  2488. </div>
  2489. <div class="section" id="module-flask.ctx">
  2490. <span id="flask-ctx-module"></span><h2>flask.ctx module<a class="headerlink" href="#module-flask.ctx" title="Permalink to this headline">¶</a></h2>
  2491. <div class="section" id="flask-ctx">
  2492. <h3>flask.ctx<a class="headerlink" href="#flask-ctx" title="Permalink to this headline">¶</a></h3>
  2493. <p>Implements the objects required to keep the context.</p>
  2494. <table class="docutils field-list" frame="void" rules="none">
  2495. <col class="field-name" />
  2496. <col class="field-body" />
  2497. <tbody valign="top">
  2498. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  2499. <li>2015 by Armin Ronacher.</li>
  2500. </ol>
  2501. </td>
  2502. </tr>
  2503. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  2504. </td>
  2505. </tr>
  2506. </tbody>
  2507. </table>
  2508. <dl class="class">
  2509. <dt id="flask.ctx.AppContext">
  2510. <em class="property">class </em><code class="descclassname">flask.ctx.</code><code class="descname">AppContext</code><span class="sig-paren">(</span><em>app</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/ctx.html#AppContext"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.ctx.AppContext" title="Permalink to this definition">¶</a></dt>
  2511. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
  2512. <p>The application context binds an application object implicitly
  2513. to the current thread or greenlet, similar to how the
  2514. <a class="reference internal" href="#flask.ctx.RequestContext" title="flask.ctx.RequestContext"><code class="xref py py-class docutils literal"><span class="pre">RequestContext</span></code></a> binds request information. The application
  2515. context is also implicitly created if a request context is created
  2516. but the application is not on top of the individual application
  2517. context.</p>
  2518. <dl class="method">
  2519. <dt id="flask.ctx.AppContext.pop">
  2520. <code class="descname">pop</code><span class="sig-paren">(</span><em>exc=&lt;object object at 0x000001E1FDEFF780&gt;</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/ctx.html#AppContext.pop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.ctx.AppContext.pop" title="Permalink to this definition">¶</a></dt>
  2521. <dd><p>Pops the app context.</p>
  2522. </dd></dl>
  2523. <dl class="method">
  2524. <dt id="flask.ctx.AppContext.push">
  2525. <code class="descname">push</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/ctx.html#AppContext.push"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.ctx.AppContext.push" title="Permalink to this definition">¶</a></dt>
  2526. <dd><p>Binds the app context to the current context.</p>
  2527. </dd></dl>
  2528. </dd></dl>
  2529. <dl class="class">
  2530. <dt id="flask.ctx.RequestContext">
  2531. <em class="property">class </em><code class="descclassname">flask.ctx.</code><code class="descname">RequestContext</code><span class="sig-paren">(</span><em>app</em>, <em>environ</em>, <em>request=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/ctx.html#RequestContext"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.ctx.RequestContext" title="Permalink to this definition">¶</a></dt>
  2532. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
  2533. <p>The request context contains all request relevant information. It is
  2534. created at the beginning of the request and pushed to the
  2535. <cite>_request_ctx_stack</cite> and removed at the end of it. It will create the
  2536. URL adapter and request object for the WSGI environment provided.</p>
  2537. <p>Do not attempt to use this class directly, instead use
  2538. <code class="xref py py-meth docutils literal"><span class="pre">test_request_context()</span></code> and
  2539. <code class="xref py py-meth docutils literal"><span class="pre">request_context()</span></code> to create this object.</p>
  2540. <p>When the request context is popped, it will evaluate all the
  2541. functions registered on the application for teardown execution
  2542. (<code class="xref py py-meth docutils literal"><span class="pre">teardown_request()</span></code>).</p>
  2543. <p>The request context is automatically popped at the end of the request
  2544. for you. In debug mode the request context is kept around if
  2545. exceptions happen so that interactive debuggers have a chance to
  2546. introspect the data. With 0.4 this can also be forced for requests
  2547. that did not fail and outside of <code class="docutils literal"><span class="pre">DEBUG</span></code> mode. By setting
  2548. <code class="docutils literal"><span class="pre">'flask._preserve_context'</span></code> to <code class="docutils literal"><span class="pre">True</span></code> on the WSGI environment the
  2549. context will not pop itself at the end of the request. This is used by
  2550. the <code class="xref py py-meth docutils literal"><span class="pre">test_client()</span></code> for example to implement the
  2551. deferred cleanup functionality.</p>
  2552. <p>You might find this helpful for unittests where you need the
  2553. information from the context local around for a little longer. Make
  2554. sure to properly <code class="xref py py-meth docutils literal"><span class="pre">pop()</span></code> the stack yourself in
  2555. that situation, otherwise your unittests will leak memory.</p>
  2556. <dl class="method">
  2557. <dt id="flask.ctx.RequestContext.auto_pop">
  2558. <code class="descname">auto_pop</code><span class="sig-paren">(</span><em>exc</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/ctx.html#RequestContext.auto_pop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.ctx.RequestContext.auto_pop" title="Permalink to this definition">¶</a></dt>
  2559. <dd></dd></dl>
  2560. <dl class="method">
  2561. <dt id="flask.ctx.RequestContext.copy">
  2562. <code class="descname">copy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/ctx.html#RequestContext.copy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.ctx.RequestContext.copy" title="Permalink to this definition">¶</a></dt>
  2563. <dd><p>Creates a copy of this request context with the same request object.
  2564. This can be used to move a request context to a different greenlet.
  2565. Because the actual request object is the same this cannot be used to
  2566. move a request context to a different thread unless access to the
  2567. request object is locked.</p>
  2568. <div class="versionadded">
  2569. <p><span class="versionmodified">New in version 0.10.</span></p>
  2570. </div>
  2571. </dd></dl>
  2572. <dl class="attribute">
  2573. <dt id="flask.ctx.RequestContext.g">
  2574. <code class="descname">g</code><a class="headerlink" href="#flask.ctx.RequestContext.g" title="Permalink to this definition">¶</a></dt>
  2575. <dd></dd></dl>
  2576. <dl class="method">
  2577. <dt id="flask.ctx.RequestContext.match_request">
  2578. <code class="descname">match_request</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/ctx.html#RequestContext.match_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.ctx.RequestContext.match_request" title="Permalink to this definition">¶</a></dt>
  2579. <dd><p>Can be overridden by a subclass to hook into the matching
  2580. of the request.</p>
  2581. </dd></dl>
  2582. <dl class="method">
  2583. <dt id="flask.ctx.RequestContext.pop">
  2584. <code class="descname">pop</code><span class="sig-paren">(</span><em>exc=&lt;object object at 0x000001E1FDEFF780&gt;</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/ctx.html#RequestContext.pop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.ctx.RequestContext.pop" title="Permalink to this definition">¶</a></dt>
  2585. <dd><p>Pops the request context and unbinds it by doing that. This will
  2586. also trigger the execution of functions registered by the
  2587. <code class="xref py py-meth docutils literal"><span class="pre">teardown_request()</span></code> decorator.</p>
  2588. <div class="versionchanged">
  2589. <p><span class="versionmodified">Changed in version 0.9: </span>Added the <cite>exc</cite> argument.</p>
  2590. </div>
  2591. </dd></dl>
  2592. <dl class="method">
  2593. <dt id="flask.ctx.RequestContext.push">
  2594. <code class="descname">push</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/ctx.html#RequestContext.push"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.ctx.RequestContext.push" title="Permalink to this definition">¶</a></dt>
  2595. <dd><p>Binds the request context to the current context.</p>
  2596. </dd></dl>
  2597. </dd></dl>
  2598. <dl class="function">
  2599. <dt id="flask.ctx.after_this_request">
  2600. <code class="descclassname">flask.ctx.</code><code class="descname">after_this_request</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/ctx.html#after_this_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.ctx.after_this_request" title="Permalink to this definition">¶</a></dt>
  2601. <dd><p>Executes a function after this request. This is useful to modify
  2602. response objects. The function is passed the response object and has
  2603. to return the same or a new one.</p>
  2604. <p>Example:</p>
  2605. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>
  2606. <span class="k">def</span> <span class="nf">index</span><span class="p">():</span>
  2607. <span class="nd">@after_this_request</span>
  2608. <span class="k">def</span> <span class="nf">add_header</span><span class="p">(</span><span class="n">response</span><span class="p">):</span>
  2609. <span class="n">response</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s1">&#39;X-Foo&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;Parachute&#39;</span>
  2610. <span class="k">return</span> <span class="n">response</span>
  2611. <span class="k">return</span> <span class="s1">&#39;Hello World!&#39;</span>
  2612. </pre></div>
  2613. </div>
  2614. <p>This is more useful if a function other than the view function wants to
  2615. modify a response. For instance think of a decorator that wants to add
  2616. some headers without converting the return value into a response object.</p>
  2617. <div class="versionadded">
  2618. <p><span class="versionmodified">New in version 0.9.</span></p>
  2619. </div>
  2620. </dd></dl>
  2621. <dl class="function">
  2622. <dt id="flask.ctx.copy_current_request_context">
  2623. <code class="descclassname">flask.ctx.</code><code class="descname">copy_current_request_context</code><span class="sig-paren">(</span><em>f</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/ctx.html#copy_current_request_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.ctx.copy_current_request_context" title="Permalink to this definition">¶</a></dt>
  2624. <dd><p>A helper function that decorates a function to retain the current
  2625. request context. This is useful when working with greenlets. The moment
  2626. the function is decorated a copy of the request context is created and
  2627. then pushed when the function is called.</p>
  2628. <p>Example:</p>
  2629. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">gevent</span>
  2630. <span class="kn">from</span> <span class="nn">flask</span> <span class="k">import</span> <span class="n">copy_current_request_context</span>
  2631. <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>
  2632. <span class="k">def</span> <span class="nf">index</span><span class="p">():</span>
  2633. <span class="nd">@copy_current_request_context</span>
  2634. <span class="k">def</span> <span class="nf">do_some_work</span><span class="p">():</span>
  2635. <span class="c1"># do some work here, it can access flask.request like you</span>
  2636. <span class="c1"># would otherwise in the view function.</span>
  2637. <span class="o">...</span>
  2638. <span class="n">gevent</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="n">do_some_work</span><span class="p">)</span>
  2639. <span class="k">return</span> <span class="s1">&#39;Regular response&#39;</span>
  2640. </pre></div>
  2641. </div>
  2642. <div class="versionadded">
  2643. <p><span class="versionmodified">New in version 0.10.</span></p>
  2644. </div>
  2645. </dd></dl>
  2646. <dl class="function">
  2647. <dt id="flask.ctx.has_app_context">
  2648. <code class="descclassname">flask.ctx.</code><code class="descname">has_app_context</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/ctx.html#has_app_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.ctx.has_app_context" title="Permalink to this definition">¶</a></dt>
  2649. <dd><p>Works like <a class="reference internal" href="#flask.ctx.has_request_context" title="flask.ctx.has_request_context"><code class="xref py py-func docutils literal"><span class="pre">has_request_context()</span></code></a> but for the application
  2650. context. You can also just do a boolean check on the
  2651. <code class="xref py py-data docutils literal"><span class="pre">current_app</span></code> object instead.</p>
  2652. <div class="versionadded">
  2653. <p><span class="versionmodified">New in version 0.9.</span></p>
  2654. </div>
  2655. </dd></dl>
  2656. <dl class="function">
  2657. <dt id="flask.ctx.has_request_context">
  2658. <code class="descclassname">flask.ctx.</code><code class="descname">has_request_context</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/ctx.html#has_request_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.ctx.has_request_context" title="Permalink to this definition">¶</a></dt>
  2659. <dd><p>If you have code that wants to test if a request context is there or
  2660. not this function can be used. For instance, you may want to take advantage
  2661. of request information if the request object is available, but fail
  2662. silently if it is unavailable.</p>
  2663. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">User</span><span class="p">(</span><span class="n">db</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
  2664. <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">username</span><span class="p">,</span> <span class="n">remote_addr</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
  2665. <span class="bp">self</span><span class="o">.</span><span class="n">username</span> <span class="o">=</span> <span class="n">username</span>
  2666. <span class="k">if</span> <span class="n">remote_addr</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">has_request_context</span><span class="p">():</span>
  2667. <span class="n">remote_addr</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">remote_addr</span>
  2668. <span class="bp">self</span><span class="o">.</span><span class="n">remote_addr</span> <span class="o">=</span> <span class="n">remote_addr</span>
  2669. </pre></div>
  2670. </div>
  2671. <p>Alternatively you can also just test any of the context bound objects
  2672. (such as <code class="xref py py-class docutils literal"><span class="pre">request</span></code> or <code class="xref py py-class docutils literal"><span class="pre">g</span></code> for truthness):</p>
  2673. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">User</span><span class="p">(</span><span class="n">db</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
  2674. <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">username</span><span class="p">,</span> <span class="n">remote_addr</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
  2675. <span class="bp">self</span><span class="o">.</span><span class="n">username</span> <span class="o">=</span> <span class="n">username</span>
  2676. <span class="k">if</span> <span class="n">remote_addr</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">request</span><span class="p">:</span>
  2677. <span class="n">remote_addr</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">remote_addr</span>
  2678. <span class="bp">self</span><span class="o">.</span><span class="n">remote_addr</span> <span class="o">=</span> <span class="n">remote_addr</span>
  2679. </pre></div>
  2680. </div>
  2681. <div class="versionadded">
  2682. <p><span class="versionmodified">New in version 0.7.</span></p>
  2683. </div>
  2684. </dd></dl>
  2685. </div>
  2686. </div>
  2687. <div class="section" id="module-flask.debughelpers">
  2688. <span id="flask-debughelpers-module"></span><h2>flask.debughelpers module<a class="headerlink" href="#module-flask.debughelpers" title="Permalink to this headline">¶</a></h2>
  2689. <div class="section" id="flask-debughelpers">
  2690. <h3>flask.debughelpers<a class="headerlink" href="#flask-debughelpers" title="Permalink to this headline">¶</a></h3>
  2691. <p>Various helpers to make the development experience better.</p>
  2692. <table class="docutils field-list" frame="void" rules="none">
  2693. <col class="field-name" />
  2694. <col class="field-body" />
  2695. <tbody valign="top">
  2696. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  2697. <li>2015 by Armin Ronacher.</li>
  2698. </ol>
  2699. </td>
  2700. </tr>
  2701. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  2702. </td>
  2703. </tr>
  2704. </tbody>
  2705. </table>
  2706. <dl class="exception">
  2707. <dt id="flask.debughelpers.DebugFilesKeyError">
  2708. <em class="property">exception </em><code class="descclassname">flask.debughelpers.</code><code class="descname">DebugFilesKeyError</code><span class="sig-paren">(</span><em>request</em>, <em>key</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/debughelpers.html#DebugFilesKeyError"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.debughelpers.DebugFilesKeyError" title="Permalink to this definition">¶</a></dt>
  2709. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">KeyError</span></code>, <code class="xref py py-class docutils literal"><span class="pre">AssertionError</span></code></p>
  2710. <p>Raised from request.files during debugging. The idea is that it can
  2711. provide a better error message than just a generic KeyError/BadRequest.</p>
  2712. </dd></dl>
  2713. <dl class="exception">
  2714. <dt id="flask.debughelpers.FormDataRoutingRedirect">
  2715. <em class="property">exception </em><code class="descclassname">flask.debughelpers.</code><code class="descname">FormDataRoutingRedirect</code><span class="sig-paren">(</span><em>request</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/debughelpers.html#FormDataRoutingRedirect"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.debughelpers.FormDataRoutingRedirect" title="Permalink to this definition">¶</a></dt>
  2716. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">AssertionError</span></code></p>
  2717. <p>This exception is raised by Flask in debug mode if it detects a
  2718. redirect caused by the routing system when the request method is not
  2719. GET, HEAD or OPTIONS. Reasoning: form data will be dropped.</p>
  2720. </dd></dl>
  2721. <dl class="exception">
  2722. <dt id="flask.debughelpers.UnexpectedUnicodeError">
  2723. <em class="property">exception </em><code class="descclassname">flask.debughelpers.</code><code class="descname">UnexpectedUnicodeError</code><a class="reference internal" href="../_modules/flask/debughelpers.html#UnexpectedUnicodeError"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.debughelpers.UnexpectedUnicodeError" title="Permalink to this definition">¶</a></dt>
  2724. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">AssertionError</span></code>, <code class="xref py py-class docutils literal"><span class="pre">UnicodeError</span></code></p>
  2725. <p>Raised in places where we want some better error reporting for
  2726. unexpected unicode or binary data.</p>
  2727. </dd></dl>
  2728. <dl class="function">
  2729. <dt id="flask.debughelpers.attach_enctype_error_multidict">
  2730. <code class="descclassname">flask.debughelpers.</code><code class="descname">attach_enctype_error_multidict</code><span class="sig-paren">(</span><em>request</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/debughelpers.html#attach_enctype_error_multidict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.debughelpers.attach_enctype_error_multidict" title="Permalink to this definition">¶</a></dt>
  2731. <dd><p>Since Flask 0.8 we&#8217;re monkeypatching the files object in case a
  2732. request is detected that does not use multipart form data but the files
  2733. object is accessed.</p>
  2734. </dd></dl>
  2735. <dl class="function">
  2736. <dt id="flask.debughelpers.explain_template_loading_attempts">
  2737. <code class="descclassname">flask.debughelpers.</code><code class="descname">explain_template_loading_attempts</code><span class="sig-paren">(</span><em>app</em>, <em>template</em>, <em>attempts</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/debughelpers.html#explain_template_loading_attempts"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.debughelpers.explain_template_loading_attempts" title="Permalink to this definition">¶</a></dt>
  2738. <dd><p>This should help developers understand what failed</p>
  2739. </dd></dl>
  2740. </div>
  2741. </div>
  2742. <div class="section" id="module-flask.exthook">
  2743. <span id="flask-exthook-module"></span><h2>flask.exthook module<a class="headerlink" href="#module-flask.exthook" title="Permalink to this headline">¶</a></h2>
  2744. <div class="section" id="flask-exthook">
  2745. <h3>flask.exthook<a class="headerlink" href="#flask-exthook" title="Permalink to this headline">¶</a></h3>
  2746. <p>Redirect imports for extensions. This module basically makes it possible
  2747. for us to transition from flaskext.foo to flask_foo without having to
  2748. force all extensions to upgrade at the same time.</p>
  2749. <p>When a user does <code class="docutils literal"><span class="pre">from</span> <span class="pre">flask.ext.foo</span> <span class="pre">import</span> <span class="pre">bar</span></code> it will attempt to
  2750. import <code class="docutils literal"><span class="pre">from</span> <span class="pre">flask_foo</span> <span class="pre">import</span> <span class="pre">bar</span></code> first and when that fails it will
  2751. try to import <code class="docutils literal"><span class="pre">from</span> <span class="pre">flaskext.foo</span> <span class="pre">import</span> <span class="pre">bar</span></code>.</p>
  2752. <p>We&#8217;re switching from namespace packages because it was just too painful for
  2753. everybody involved.</p>
  2754. <p>This is used by <cite>flask.ext</cite>.</p>
  2755. <table class="docutils field-list" frame="void" rules="none">
  2756. <col class="field-name" />
  2757. <col class="field-body" />
  2758. <tbody valign="top">
  2759. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  2760. <li>2015 by Armin Ronacher.</li>
  2761. </ol>
  2762. </td>
  2763. </tr>
  2764. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  2765. </td>
  2766. </tr>
  2767. </tbody>
  2768. </table>
  2769. <dl class="exception">
  2770. <dt id="flask.exthook.ExtDeprecationWarning">
  2771. <em class="property">exception </em><code class="descclassname">flask.exthook.</code><code class="descname">ExtDeprecationWarning</code><a class="reference internal" href="../_modules/flask/exthook.html#ExtDeprecationWarning"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.exthook.ExtDeprecationWarning" title="Permalink to this definition">¶</a></dt>
  2772. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">DeprecationWarning</span></code></p>
  2773. </dd></dl>
  2774. <dl class="class">
  2775. <dt id="flask.exthook.ExtensionImporter">
  2776. <em class="property">class </em><code class="descclassname">flask.exthook.</code><code class="descname">ExtensionImporter</code><span class="sig-paren">(</span><em>module_choices</em>, <em>wrapper_module</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/exthook.html#ExtensionImporter"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.exthook.ExtensionImporter" title="Permalink to this definition">¶</a></dt>
  2777. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
  2778. <p>This importer redirects imports from this submodule to other locations.
  2779. This makes it possible to transition from the old flaskext.name to the
  2780. newer flask_name without people having a hard time.</p>
  2781. <dl class="method">
  2782. <dt id="flask.exthook.ExtensionImporter.find_module">
  2783. <code class="descname">find_module</code><span class="sig-paren">(</span><em>fullname</em>, <em>path=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/exthook.html#ExtensionImporter.find_module"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.exthook.ExtensionImporter.find_module" title="Permalink to this definition">¶</a></dt>
  2784. <dd></dd></dl>
  2785. <dl class="method">
  2786. <dt id="flask.exthook.ExtensionImporter.install">
  2787. <code class="descname">install</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/exthook.html#ExtensionImporter.install"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.exthook.ExtensionImporter.install" title="Permalink to this definition">¶</a></dt>
  2788. <dd></dd></dl>
  2789. <dl class="method">
  2790. <dt id="flask.exthook.ExtensionImporter.is_important_frame">
  2791. <code class="descname">is_important_frame</code><span class="sig-paren">(</span><em>important_module</em>, <em>tb</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/exthook.html#ExtensionImporter.is_important_frame"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.exthook.ExtensionImporter.is_important_frame" title="Permalink to this definition">¶</a></dt>
  2792. <dd><p>Checks a single frame if it&#8217;s important.</p>
  2793. </dd></dl>
  2794. <dl class="method">
  2795. <dt id="flask.exthook.ExtensionImporter.is_important_traceback">
  2796. <code class="descname">is_important_traceback</code><span class="sig-paren">(</span><em>important_module</em>, <em>tb</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/exthook.html#ExtensionImporter.is_important_traceback"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.exthook.ExtensionImporter.is_important_traceback" title="Permalink to this definition">¶</a></dt>
  2797. <dd><p>Walks a traceback&#8217;s frames and checks if any of the frames
  2798. originated in the given important module. If that is the case then we
  2799. were able to import the module itself but apparently something went
  2800. wrong when the module was imported. (Eg: import of an import failed).</p>
  2801. </dd></dl>
  2802. <dl class="method">
  2803. <dt id="flask.exthook.ExtensionImporter.load_module">
  2804. <code class="descname">load_module</code><span class="sig-paren">(</span><em>fullname</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/exthook.html#ExtensionImporter.load_module"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.exthook.ExtensionImporter.load_module" title="Permalink to this definition">¶</a></dt>
  2805. <dd></dd></dl>
  2806. </dd></dl>
  2807. </div>
  2808. </div>
  2809. <div class="section" id="module-flask.globals">
  2810. <span id="flask-globals-module"></span><h2>flask.globals module<a class="headerlink" href="#module-flask.globals" title="Permalink to this headline">¶</a></h2>
  2811. <div class="section" id="flask-globals">
  2812. <h3>flask.globals<a class="headerlink" href="#flask-globals" title="Permalink to this headline">¶</a></h3>
  2813. <p>Defines all the global objects that are proxies to the current
  2814. active context.</p>
  2815. <table class="docutils field-list" frame="void" rules="none">
  2816. <col class="field-name" />
  2817. <col class="field-body" />
  2818. <tbody valign="top">
  2819. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  2820. <li>2015 by Armin Ronacher.</li>
  2821. </ol>
  2822. </td>
  2823. </tr>
  2824. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  2825. </td>
  2826. </tr>
  2827. </tbody>
  2828. </table>
  2829. </div>
  2830. </div>
  2831. <div class="section" id="module-flask.helpers">
  2832. <span id="flask-helpers-module"></span><h2>flask.helpers module<a class="headerlink" href="#module-flask.helpers" title="Permalink to this headline">¶</a></h2>
  2833. <div class="section" id="flask-helpers">
  2834. <h3>flask.helpers<a class="headerlink" href="#flask-helpers" title="Permalink to this headline">¶</a></h3>
  2835. <p>Implements various helpers.</p>
  2836. <table class="docutils field-list" frame="void" rules="none">
  2837. <col class="field-name" />
  2838. <col class="field-body" />
  2839. <tbody valign="top">
  2840. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  2841. <li>2015 by Armin Ronacher.</li>
  2842. </ol>
  2843. </td>
  2844. </tr>
  2845. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  2846. </td>
  2847. </tr>
  2848. </tbody>
  2849. </table>
  2850. <dl class="function">
  2851. <dt id="flask.helpers.find_package">
  2852. <code class="descclassname">flask.helpers.</code><code class="descname">find_package</code><span class="sig-paren">(</span><em>import_name</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/helpers.html#find_package"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.helpers.find_package" title="Permalink to this definition">¶</a></dt>
  2853. <dd><p>Finds a package and returns the prefix (or None if the package is
  2854. not installed) as well as the folder that contains the package or
  2855. module as a tuple. The package path returned is the module that would
  2856. have to be added to the pythonpath in order to make it possible to
  2857. import the module. The prefix is the path below which a UNIX like
  2858. folder structure exists (lib, share etc.).</p>
  2859. </dd></dl>
  2860. <dl class="function">
  2861. <dt id="flask.helpers.flash">
  2862. <code class="descclassname">flask.helpers.</code><code class="descname">flash</code><span class="sig-paren">(</span><em>message</em>, <em>category='message'</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/helpers.html#flash"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.helpers.flash" title="Permalink to this definition">¶</a></dt>
  2863. <dd><p>Flashes a message to the next request. In order to remove the
  2864. flashed message from the session and to display it to the user,
  2865. the template has to call <a class="reference internal" href="#flask.helpers.get_flashed_messages" title="flask.helpers.get_flashed_messages"><code class="xref py py-func docutils literal"><span class="pre">get_flashed_messages()</span></code></a>.</p>
  2866. <div class="versionchanged">
  2867. <p><span class="versionmodified">Changed in version 0.3: </span><cite>category</cite> parameter added.</p>
  2868. </div>
  2869. <table class="docutils field-list" frame="void" rules="none">
  2870. <col class="field-name" />
  2871. <col class="field-body" />
  2872. <tbody valign="top">
  2873. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  2874. <li><strong>message</strong> &#8211; the message to be flashed.</li>
  2875. <li><strong>category</strong> &#8211; the category for the message. The following values
  2876. are recommended: <code class="docutils literal"><span class="pre">'message'</span></code> for any kind of message,
  2877. <code class="docutils literal"><span class="pre">'error'</span></code> for errors, <code class="docutils literal"><span class="pre">'info'</span></code> for information
  2878. messages and <code class="docutils literal"><span class="pre">'warning'</span></code> for warnings. However any
  2879. kind of string can be used as category.</li>
  2880. </ul>
  2881. </td>
  2882. </tr>
  2883. </tbody>
  2884. </table>
  2885. </dd></dl>
  2886. <dl class="function">
  2887. <dt id="flask.helpers.get_debug_flag">
  2888. <code class="descclassname">flask.helpers.</code><code class="descname">get_debug_flag</code><span class="sig-paren">(</span><em>default=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/helpers.html#get_debug_flag"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.helpers.get_debug_flag" title="Permalink to this definition">¶</a></dt>
  2889. <dd></dd></dl>
  2890. <dl class="function">
  2891. <dt id="flask.helpers.get_flashed_messages">
  2892. <code class="descclassname">flask.helpers.</code><code class="descname">get_flashed_messages</code><span class="sig-paren">(</span><em>with_categories=False</em>, <em>category_filter=[]</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/helpers.html#get_flashed_messages"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.helpers.get_flashed_messages" title="Permalink to this definition">¶</a></dt>
  2893. <dd><p>Pulls all flashed messages from the session and returns them.
  2894. Further calls in the same request to the function will return
  2895. the same messages. By default just the messages are returned,
  2896. but when <cite>with_categories</cite> is set to <code class="docutils literal"><span class="pre">True</span></code>, the return value will
  2897. be a list of tuples in the form <code class="docutils literal"><span class="pre">(category,</span> <span class="pre">message)</span></code> instead.</p>
  2898. <p>Filter the flashed messages to one or more categories by providing those
  2899. categories in <cite>category_filter</cite>. This allows rendering categories in
  2900. separate html blocks. The <cite>with_categories</cite> and <cite>category_filter</cite>
  2901. arguments are distinct:</p>
  2902. <ul class="simple">
  2903. <li><cite>with_categories</cite> controls whether categories are returned with message
  2904. text (<code class="docutils literal"><span class="pre">True</span></code> gives a tuple, where <code class="docutils literal"><span class="pre">False</span></code> gives just the message text).</li>
  2905. <li><cite>category_filter</cite> filters the messages down to only those matching the
  2906. provided categories.</li>
  2907. </ul>
  2908. <p>See <span class="xref std std-ref">message-flashing-pattern</span> for examples.</p>
  2909. <div class="versionchanged">
  2910. <p><span class="versionmodified">Changed in version 0.3: </span><cite>with_categories</cite> parameter added.</p>
  2911. </div>
  2912. <div class="versionchanged">
  2913. <p><span class="versionmodified">Changed in version 0.9: </span><cite>category_filter</cite> parameter added.</p>
  2914. </div>
  2915. <table class="docutils field-list" frame="void" rules="none">
  2916. <col class="field-name" />
  2917. <col class="field-body" />
  2918. <tbody valign="top">
  2919. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  2920. <li><strong>with_categories</strong> &#8211; set to <code class="docutils literal"><span class="pre">True</span></code> to also receive categories.</li>
  2921. <li><strong>category_filter</strong> &#8211; whitelist of categories to limit return values</li>
  2922. </ul>
  2923. </td>
  2924. </tr>
  2925. </tbody>
  2926. </table>
  2927. </dd></dl>
  2928. <dl class="function">
  2929. <dt id="flask.helpers.get_root_path">
  2930. <code class="descclassname">flask.helpers.</code><code class="descname">get_root_path</code><span class="sig-paren">(</span><em>import_name</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/helpers.html#get_root_path"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.helpers.get_root_path" title="Permalink to this definition">¶</a></dt>
  2931. <dd><p>Returns the path to a package or cwd if that cannot be found. This
  2932. returns the path of a package or the folder that contains a module.</p>
  2933. <p>Not to be confused with the package path returned by <a class="reference internal" href="#flask.helpers.find_package" title="flask.helpers.find_package"><code class="xref py py-func docutils literal"><span class="pre">find_package()</span></code></a>.</p>
  2934. </dd></dl>
  2935. <dl class="function">
  2936. <dt id="flask.helpers.get_template_attribute">
  2937. <code class="descclassname">flask.helpers.</code><code class="descname">get_template_attribute</code><span class="sig-paren">(</span><em>template_name</em>, <em>attribute</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/helpers.html#get_template_attribute"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.helpers.get_template_attribute" title="Permalink to this definition">¶</a></dt>
  2938. <dd><p>Loads a macro (or variable) a template exports. This can be used to
  2939. invoke a macro from within Python code. If you for example have a
  2940. template named <code class="file docutils literal"><span class="pre">_cider.html</span></code> with the following contents:</p>
  2941. <div class="highlight-html+jinja"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">macro</span> <span class="nv">hello</span><span class="o">(</span><span class="nv">name</span><span class="o">)</span> <span class="cp">%}</span>Hello <span class="cp">{{</span> <span class="nv">name</span> <span class="cp">}}</span>!<span class="cp">{%</span> <span class="k">endmacro</span> <span class="cp">%}</span>
  2942. </pre></div>
  2943. </div>
  2944. <p>You can access this from Python code like this:</p>
  2945. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">hello</span> <span class="o">=</span> <span class="n">get_template_attribute</span><span class="p">(</span><span class="s1">&#39;_cider.html&#39;</span><span class="p">,</span> <span class="s1">&#39;hello&#39;</span><span class="p">)</span>
  2946. <span class="k">return</span> <span class="n">hello</span><span class="p">(</span><span class="s1">&#39;World&#39;</span><span class="p">)</span>
  2947. </pre></div>
  2948. </div>
  2949. <div class="versionadded">
  2950. <p><span class="versionmodified">New in version 0.2.</span></p>
  2951. </div>
  2952. <table class="docutils field-list" frame="void" rules="none">
  2953. <col class="field-name" />
  2954. <col class="field-body" />
  2955. <tbody valign="top">
  2956. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  2957. <li><strong>template_name</strong> &#8211; the name of the template</li>
  2958. <li><strong>attribute</strong> &#8211; the name of the variable of macro to access</li>
  2959. </ul>
  2960. </td>
  2961. </tr>
  2962. </tbody>
  2963. </table>
  2964. </dd></dl>
  2965. <dl class="class">
  2966. <dt id="flask.helpers.locked_cached_property">
  2967. <em class="property">class </em><code class="descclassname">flask.helpers.</code><code class="descname">locked_cached_property</code><span class="sig-paren">(</span><em>func</em>, <em>name=None</em>, <em>doc=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/helpers.html#locked_cached_property"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.helpers.locked_cached_property" title="Permalink to this definition">¶</a></dt>
  2968. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
  2969. <p>A decorator that converts a function into a lazy property. The
  2970. function wrapped is called the first time to retrieve the result
  2971. and then that calculated result is used the next time you access
  2972. the value. Works like the one in Werkzeug but has a lock for
  2973. thread safety.</p>
  2974. </dd></dl>
  2975. <dl class="function">
  2976. <dt id="flask.helpers.make_response">
  2977. <code class="descclassname">flask.helpers.</code><code class="descname">make_response</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/helpers.html#make_response"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.helpers.make_response" title="Permalink to this definition">¶</a></dt>
  2978. <dd><p>Sometimes it is necessary to set additional headers in a view. Because
  2979. views do not have to return response objects but can return a value that
  2980. is converted into a response object by Flask itself, it becomes tricky to
  2981. add headers to it. This function can be called instead of using a return
  2982. and you will get a response object which you can use to attach headers.</p>
  2983. <p>If view looked like this and you want to add a new header:</p>
  2984. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">index</span><span class="p">():</span>
  2985. <span class="k">return</span> <span class="n">render_template</span><span class="p">(</span><span class="s1">&#39;index.html&#39;</span><span class="p">,</span> <span class="n">foo</span><span class="o">=</span><span class="mi">42</span><span class="p">)</span>
  2986. </pre></div>
  2987. </div>
  2988. <p>You can now do something like this:</p>
  2989. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">index</span><span class="p">():</span>
  2990. <span class="n">response</span> <span class="o">=</span> <span class="n">make_response</span><span class="p">(</span><span class="n">render_template</span><span class="p">(</span><span class="s1">&#39;index.html&#39;</span><span class="p">,</span> <span class="n">foo</span><span class="o">=</span><span class="mi">42</span><span class="p">))</span>
  2991. <span class="n">response</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s1">&#39;X-Parachutes&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;parachutes are cool&#39;</span>
  2992. <span class="k">return</span> <span class="n">response</span>
  2993. </pre></div>
  2994. </div>
  2995. <p>This function accepts the very same arguments you can return from a
  2996. view function. This for example creates a response with a 404 error
  2997. code:</p>
  2998. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">response</span> <span class="o">=</span> <span class="n">make_response</span><span class="p">(</span><span class="n">render_template</span><span class="p">(</span><span class="s1">&#39;not_found.html&#39;</span><span class="p">),</span> <span class="mi">404</span><span class="p">)</span>
  2999. </pre></div>
  3000. </div>
  3001. <p>The other use case of this function is to force the return value of a
  3002. view function into a response which is helpful with view
  3003. decorators:</p>
  3004. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">response</span> <span class="o">=</span> <span class="n">make_response</span><span class="p">(</span><span class="n">view_function</span><span class="p">())</span>
  3005. <span class="n">response</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s1">&#39;X-Parachutes&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;parachutes are cool&#39;</span>
  3006. </pre></div>
  3007. </div>
  3008. <p>Internally this function does the following things:</p>
  3009. <ul class="simple">
  3010. <li>if no arguments are passed, it creates a new response argument</li>
  3011. <li>if one argument is passed, <code class="xref py py-meth docutils literal"><span class="pre">flask.Flask.make_response()</span></code>
  3012. is invoked with it.</li>
  3013. <li>if more than one argument is passed, the arguments are passed
  3014. to the <code class="xref py py-meth docutils literal"><span class="pre">flask.Flask.make_response()</span></code> function as tuple.</li>
  3015. </ul>
  3016. <div class="versionadded">
  3017. <p><span class="versionmodified">New in version 0.6.</span></p>
  3018. </div>
  3019. </dd></dl>
  3020. <dl class="function">
  3021. <dt id="flask.helpers.safe_join">
  3022. <code class="descclassname">flask.helpers.</code><code class="descname">safe_join</code><span class="sig-paren">(</span><em>directory</em>, <em>filename</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/helpers.html#safe_join"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.helpers.safe_join" title="Permalink to this definition">¶</a></dt>
  3023. <dd><p>Safely join <cite>directory</cite> and <cite>filename</cite>.</p>
  3024. <p>Example usage:</p>
  3025. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/wiki/&lt;path:filename&gt;&#39;</span><span class="p">)</span>
  3026. <span class="k">def</span> <span class="nf">wiki_page</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
  3027. <span class="n">filename</span> <span class="o">=</span> <span class="n">safe_join</span><span class="p">(</span><span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;WIKI_FOLDER&#39;</span><span class="p">],</span> <span class="n">filename</span><span class="p">)</span>
  3028. <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;rb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fd</span><span class="p">:</span>
  3029. <span class="n">content</span> <span class="o">=</span> <span class="n">fd</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> <span class="c1"># Read and process the file content...</span>
  3030. </pre></div>
  3031. </div>
  3032. <table class="docutils field-list" frame="void" rules="none">
  3033. <col class="field-name" />
  3034. <col class="field-body" />
  3035. <tbody valign="top">
  3036. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  3037. <li><strong>directory</strong> &#8211; the base directory.</li>
  3038. <li><strong>filename</strong> &#8211; the untrusted filename relative to that directory.</li>
  3039. </ul>
  3040. </td>
  3041. </tr>
  3042. <tr class="field-even field"><th class="field-name">Raises:</th><td class="field-body"><p class="first last"><code class="xref py py-class docutils literal"><span class="pre">NotFound</span></code> if the resulting path
  3043. would fall out of <cite>directory</cite>.</p>
  3044. </td>
  3045. </tr>
  3046. </tbody>
  3047. </table>
  3048. </dd></dl>
  3049. <dl class="function">
  3050. <dt id="flask.helpers.send_file">
  3051. <code class="descclassname">flask.helpers.</code><code class="descname">send_file</code><span class="sig-paren">(</span><em>filename_or_fp</em>, <em>mimetype=None</em>, <em>as_attachment=False</em>, <em>attachment_filename=None</em>, <em>add_etags=True</em>, <em>cache_timeout=None</em>, <em>conditional=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/helpers.html#send_file"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.helpers.send_file" title="Permalink to this definition">¶</a></dt>
  3052. <dd><p>Sends the contents of a file to the client. This will use the
  3053. most efficient method available and configured. By default it will
  3054. try to use the WSGI server&#8217;s file_wrapper support. Alternatively
  3055. you can set the application&#8217;s <code class="xref py py-attr docutils literal"><span class="pre">use_x_sendfile</span></code> attribute
  3056. to <code class="docutils literal"><span class="pre">True</span></code> to directly emit an <code class="docutils literal"><span class="pre">X-Sendfile</span></code> header. This however
  3057. requires support of the underlying webserver for <code class="docutils literal"><span class="pre">X-Sendfile</span></code>.</p>
  3058. <p>By default it will try to guess the mimetype for you, but you can
  3059. also explicitly provide one. For extra security you probably want
  3060. to send certain files as attachment (HTML for instance). The mimetype
  3061. guessing requires a <cite>filename</cite> or an <cite>attachment_filename</cite> to be
  3062. provided.</p>
  3063. <p>Please never pass filenames to this function from user sources;
  3064. you should use <a class="reference internal" href="#flask.helpers.send_from_directory" title="flask.helpers.send_from_directory"><code class="xref py py-func docutils literal"><span class="pre">send_from_directory()</span></code></a> instead.</p>
  3065. <div class="versionadded">
  3066. <p><span class="versionmodified">New in version 0.2.</span></p>
  3067. </div>
  3068. <div class="versionadded">
  3069. <p><span class="versionmodified">New in version 0.5: </span>The <cite>add_etags</cite>, <cite>cache_timeout</cite> and <cite>conditional</cite> parameters were
  3070. added. The default behavior is now to attach etags.</p>
  3071. </div>
  3072. <div class="versionchanged">
  3073. <p><span class="versionmodified">Changed in version 0.7: </span>mimetype guessing and etag support for file objects was
  3074. deprecated because it was unreliable. Pass a filename if you are
  3075. able to, otherwise attach an etag yourself. This functionality
  3076. will be removed in Flask 1.0</p>
  3077. </div>
  3078. <div class="versionchanged">
  3079. <p><span class="versionmodified">Changed in version 0.9: </span>cache_timeout pulls its default from application config, when None.</p>
  3080. </div>
  3081. <table class="docutils field-list" frame="void" rules="none">
  3082. <col class="field-name" />
  3083. <col class="field-body" />
  3084. <tbody valign="top">
  3085. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  3086. <li><strong>filename_or_fp</strong> &#8211; the filename of the file to send in <cite>latin-1</cite>.
  3087. This is relative to the <code class="xref py py-attr docutils literal"><span class="pre">root_path</span></code>
  3088. if a relative path is specified.
  3089. Alternatively a file object might be provided in
  3090. which case <code class="docutils literal"><span class="pre">X-Sendfile</span></code> might not work and fall
  3091. back to the traditional method. Make sure that the
  3092. file pointer is positioned at the start of data to
  3093. send before calling <a class="reference internal" href="#flask.helpers.send_file" title="flask.helpers.send_file"><code class="xref py py-func docutils literal"><span class="pre">send_file()</span></code></a>.</li>
  3094. <li><strong>mimetype</strong> &#8211; the mimetype of the file if provided, otherwise
  3095. auto detection happens.</li>
  3096. <li><strong>as_attachment</strong> &#8211; set to <code class="docutils literal"><span class="pre">True</span></code> if you want to send this file with
  3097. a <code class="docutils literal"><span class="pre">Content-Disposition:</span> <span class="pre">attachment</span></code> header.</li>
  3098. <li><strong>attachment_filename</strong> &#8211; the filename for the attachment if it
  3099. differs from the file&#8217;s filename.</li>
  3100. <li><strong>add_etags</strong> &#8211; set to <code class="docutils literal"><span class="pre">False</span></code> to disable attaching of etags.</li>
  3101. <li><strong>conditional</strong> &#8211; set to <code class="docutils literal"><span class="pre">True</span></code> to enable conditional responses.</li>
  3102. <li><strong>cache_timeout</strong> &#8211; the timeout in seconds for the headers. When <code class="docutils literal"><span class="pre">None</span></code>
  3103. (default), this value is set by
  3104. <code class="xref py py-meth docutils literal"><span class="pre">get_send_file_max_age()</span></code> of
  3105. <code class="xref py py-data docutils literal"><span class="pre">current_app</span></code>.</li>
  3106. </ul>
  3107. </td>
  3108. </tr>
  3109. </tbody>
  3110. </table>
  3111. </dd></dl>
  3112. <dl class="function">
  3113. <dt id="flask.helpers.send_from_directory">
  3114. <code class="descclassname">flask.helpers.</code><code class="descname">send_from_directory</code><span class="sig-paren">(</span><em>directory</em>, <em>filename</em>, <em>**options</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/helpers.html#send_from_directory"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.helpers.send_from_directory" title="Permalink to this definition">¶</a></dt>
  3115. <dd><p>Send a file from a given directory with <a class="reference internal" href="#flask.helpers.send_file" title="flask.helpers.send_file"><code class="xref py py-func docutils literal"><span class="pre">send_file()</span></code></a>. This
  3116. is a secure way to quickly expose static files from an upload folder
  3117. or something similar.</p>
  3118. <p>Example usage:</p>
  3119. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/uploads/&lt;path:filename&gt;&#39;</span><span class="p">)</span>
  3120. <span class="k">def</span> <span class="nf">download_file</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
  3121. <span class="k">return</span> <span class="n">send_from_directory</span><span class="p">(</span><span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;UPLOAD_FOLDER&#39;</span><span class="p">],</span>
  3122. <span class="n">filename</span><span class="p">,</span> <span class="n">as_attachment</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
  3123. </pre></div>
  3124. </div>
  3125. <div class="admonition-sending-files-and-performance admonition">
  3126. <p class="first admonition-title">Sending files and Performance</p>
  3127. <p class="last">It is strongly recommended to activate either <code class="docutils literal"><span class="pre">X-Sendfile</span></code> support in
  3128. your webserver or (if no authentication happens) to tell the webserver
  3129. to serve files for the given path on its own without calling into the
  3130. web application for improved performance.</p>
  3131. </div>
  3132. <div class="versionadded">
  3133. <p><span class="versionmodified">New in version 0.5.</span></p>
  3134. </div>
  3135. <table class="docutils field-list" frame="void" rules="none">
  3136. <col class="field-name" />
  3137. <col class="field-body" />
  3138. <tbody valign="top">
  3139. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  3140. <li><strong>directory</strong> &#8211; the directory where all the files are stored.</li>
  3141. <li><strong>filename</strong> &#8211; the filename relative to that directory to
  3142. download.</li>
  3143. <li><strong>options</strong> &#8211; optional keyword arguments that are directly
  3144. forwarded to <a class="reference internal" href="#flask.helpers.send_file" title="flask.helpers.send_file"><code class="xref py py-func docutils literal"><span class="pre">send_file()</span></code></a>.</li>
  3145. </ul>
  3146. </td>
  3147. </tr>
  3148. </tbody>
  3149. </table>
  3150. </dd></dl>
  3151. <dl class="function">
  3152. <dt id="flask.helpers.stream_with_context">
  3153. <code class="descclassname">flask.helpers.</code><code class="descname">stream_with_context</code><span class="sig-paren">(</span><em>generator_or_function</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/helpers.html#stream_with_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.helpers.stream_with_context" title="Permalink to this definition">¶</a></dt>
  3154. <dd><p>Request contexts disappear when the response is started on the server.
  3155. This is done for efficiency reasons and to make it less likely to encounter
  3156. memory leaks with badly written WSGI middlewares. The downside is that if
  3157. you are using streamed responses, the generator cannot access request bound
  3158. information any more.</p>
  3159. <p>This function however can help you keep the context around for longer:</p>
  3160. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">flask</span> <span class="k">import</span> <span class="n">stream_with_context</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">Response</span>
  3161. <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/stream&#39;</span><span class="p">)</span>
  3162. <span class="k">def</span> <span class="nf">streamed_response</span><span class="p">():</span>
  3163. <span class="nd">@stream_with_context</span>
  3164. <span class="k">def</span> <span class="nf">generate</span><span class="p">():</span>
  3165. <span class="k">yield</span> <span class="s1">&#39;Hello &#39;</span>
  3166. <span class="k">yield</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">]</span>
  3167. <span class="k">yield</span> <span class="s1">&#39;!&#39;</span>
  3168. <span class="k">return</span> <span class="n">Response</span><span class="p">(</span><span class="n">generate</span><span class="p">())</span>
  3169. </pre></div>
  3170. </div>
  3171. <p>Alternatively it can also be used around a specific generator:</p>
  3172. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">flask</span> <span class="k">import</span> <span class="n">stream_with_context</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">Response</span>
  3173. <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/stream&#39;</span><span class="p">)</span>
  3174. <span class="k">def</span> <span class="nf">streamed_response</span><span class="p">():</span>
  3175. <span class="k">def</span> <span class="nf">generate</span><span class="p">():</span>
  3176. <span class="k">yield</span> <span class="s1">&#39;Hello &#39;</span>
  3177. <span class="k">yield</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">]</span>
  3178. <span class="k">yield</span> <span class="s1">&#39;!&#39;</span>
  3179. <span class="k">return</span> <span class="n">Response</span><span class="p">(</span><span class="n">stream_with_context</span><span class="p">(</span><span class="n">generate</span><span class="p">()))</span>
  3180. </pre></div>
  3181. </div>
  3182. <div class="versionadded">
  3183. <p><span class="versionmodified">New in version 0.9.</span></p>
  3184. </div>
  3185. </dd></dl>
  3186. <dl class="function">
  3187. <dt id="flask.helpers.total_seconds">
  3188. <code class="descclassname">flask.helpers.</code><code class="descname">total_seconds</code><span class="sig-paren">(</span><em>td</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/helpers.html#total_seconds"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.helpers.total_seconds" title="Permalink to this definition">¶</a></dt>
  3189. <dd><p>Returns the total seconds from a timedelta object.</p>
  3190. <table class="docutils field-list" frame="void" rules="none">
  3191. <col class="field-name" />
  3192. <col class="field-body" />
  3193. <tbody valign="top">
  3194. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>td</strong> (<em>timedelta</em>) &#8211; the timedelta to be converted in seconds</td>
  3195. </tr>
  3196. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">number of seconds</td>
  3197. </tr>
  3198. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">int</td>
  3199. </tr>
  3200. </tbody>
  3201. </table>
  3202. </dd></dl>
  3203. <dl class="function">
  3204. <dt id="flask.helpers.url_for">
  3205. <code class="descclassname">flask.helpers.</code><code class="descname">url_for</code><span class="sig-paren">(</span><em>endpoint</em>, <em>**values</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/helpers.html#url_for"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.helpers.url_for" title="Permalink to this definition">¶</a></dt>
  3206. <dd><p>Generates a URL to the given endpoint with the method provided.</p>
  3207. <p>Variable arguments that are unknown to the target endpoint are appended
  3208. to the generated URL as query arguments. If the value of a query argument
  3209. is <code class="docutils literal"><span class="pre">None</span></code>, the whole pair is skipped. In case blueprints are active
  3210. you can shortcut references to the same blueprint by prefixing the
  3211. local endpoint with a dot (<code class="docutils literal"><span class="pre">.</span></code>).</p>
  3212. <p>This will reference the index function local to the current blueprint:</p>
  3213. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">url_for</span><span class="p">(</span><span class="s1">&#39;.index&#39;</span><span class="p">)</span>
  3214. </pre></div>
  3215. </div>
  3216. <p>For more information, head over to the <span class="xref std std-ref">Quickstart</span>.</p>
  3217. <p>To integrate applications, <code class="xref py py-class docutils literal"><span class="pre">Flask</span></code> has a hook to intercept URL build
  3218. errors through <code class="xref py py-attr docutils literal"><span class="pre">Flask.url_build_error_handlers</span></code>. The <cite>url_for</cite>
  3219. function results in a <code class="xref py py-exc docutils literal"><span class="pre">BuildError</span></code> when the current
  3220. app does not have a URL for the given endpoint and values. When it does, the
  3221. <code class="xref py py-data docutils literal"><span class="pre">current_app</span></code> calls its <code class="xref py py-attr docutils literal"><span class="pre">url_build_error_handlers</span></code> if
  3222. it is not <code class="docutils literal"><span class="pre">None</span></code>, which can return a string to use as the result of
  3223. <cite>url_for</cite> (instead of <cite>url_for</cite>&#8216;s default to raise the
  3224. <code class="xref py py-exc docutils literal"><span class="pre">BuildError</span></code> exception) or re-raise the exception.
  3225. An example:</p>
  3226. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">external_url_handler</span><span class="p">(</span><span class="n">error</span><span class="p">,</span> <span class="n">endpoint</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span>
  3227. <span class="s2">&quot;Looks up an external URL when `url_for` cannot build a URL.&quot;</span>
  3228. <span class="c1"># This is an example of hooking the build_error_handler.</span>
  3229. <span class="c1"># Here, lookup_url is some utility function you&#39;ve built</span>
  3230. <span class="c1"># which looks up the endpoint in some external URL registry.</span>
  3231. <span class="n">url</span> <span class="o">=</span> <span class="n">lookup_url</span><span class="p">(</span><span class="n">endpoint</span><span class="p">,</span> <span class="o">**</span><span class="n">values</span><span class="p">)</span>
  3232. <span class="k">if</span> <span class="n">url</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
  3233. <span class="c1"># External lookup did not have a URL.</span>
  3234. <span class="c1"># Re-raise the BuildError, in context of original traceback.</span>
  3235. <span class="n">exc_type</span><span class="p">,</span> <span class="n">exc_value</span><span class="p">,</span> <span class="n">tb</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">exc_info</span><span class="p">()</span>
  3236. <span class="k">if</span> <span class="n">exc_value</span> <span class="ow">is</span> <span class="n">error</span><span class="p">:</span>
  3237. <span class="k">raise</span> <span class="n">exc_type</span><span class="p">,</span> <span class="n">exc_value</span><span class="p">,</span> <span class="n">tb</span>
  3238. <span class="k">else</span><span class="p">:</span>
  3239. <span class="k">raise</span> <span class="n">error</span>
  3240. <span class="c1"># url_for will use this result, instead of raising BuildError.</span>
  3241. <span class="k">return</span> <span class="n">url</span>
  3242. <span class="n">app</span><span class="o">.</span><span class="n">url_build_error_handlers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">external_url_handler</span><span class="p">)</span>
  3243. </pre></div>
  3244. </div>
  3245. <p>Here, <cite>error</cite> is the instance of <code class="xref py py-exc docutils literal"><span class="pre">BuildError</span></code>, and
  3246. <cite>endpoint</cite> and <cite>values</cite> are the arguments passed into <cite>url_for</cite>. Note
  3247. that this is for building URLs outside the current application, and not for
  3248. handling 404 NotFound errors.</p>
  3249. <div class="versionadded">
  3250. <p><span class="versionmodified">New in version 0.10: </span>The <cite>_scheme</cite> parameter was added.</p>
  3251. </div>
  3252. <div class="versionadded">
  3253. <p><span class="versionmodified">New in version 0.9: </span>The <cite>_anchor</cite> and <cite>_method</cite> parameters were added.</p>
  3254. </div>
  3255. <div class="versionadded">
  3256. <p><span class="versionmodified">New in version 0.9: </span>Calls <code class="xref py py-meth docutils literal"><span class="pre">Flask.handle_build_error()</span></code> on
  3257. <code class="xref py py-exc docutils literal"><span class="pre">BuildError</span></code>.</p>
  3258. </div>
  3259. <table class="docutils field-list" frame="void" rules="none">
  3260. <col class="field-name" />
  3261. <col class="field-body" />
  3262. <tbody valign="top">
  3263. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  3264. <li><strong>endpoint</strong> &#8211; the endpoint of the URL (name of the function)</li>
  3265. <li><strong>values</strong> &#8211; the variable arguments of the URL rule</li>
  3266. <li><strong>_external</strong> &#8211; if set to <code class="docutils literal"><span class="pre">True</span></code>, an absolute URL is generated. Server
  3267. address can be changed via <code class="docutils literal"><span class="pre">SERVER_NAME</span></code> configuration variable which
  3268. defaults to <cite>localhost</cite>.</li>
  3269. <li><strong>_scheme</strong> &#8211; a string specifying the desired URL scheme. The <cite>_external</cite>
  3270. parameter must be set to <code class="docutils literal"><span class="pre">True</span></code> or a <code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> is raised. The default
  3271. behavior uses the same scheme as the current request, or
  3272. <code class="docutils literal"><span class="pre">PREFERRED_URL_SCHEME</span></code> from the <span class="xref std std-ref">app configuration</span> if no
  3273. request context is available. As of Werkzeug 0.10, this also can be set
  3274. to an empty string to build protocol-relative URLs.</li>
  3275. <li><strong>_anchor</strong> &#8211; if provided this is added as anchor to the URL.</li>
  3276. <li><strong>_method</strong> &#8211; if provided this explicitly specifies an HTTP method.</li>
  3277. </ul>
  3278. </td>
  3279. </tr>
  3280. </tbody>
  3281. </table>
  3282. </dd></dl>
  3283. </div>
  3284. </div>
  3285. <div class="section" id="module-flask.json">
  3286. <span id="flask-json-module"></span><h2>flask.json module<a class="headerlink" href="#module-flask.json" title="Permalink to this headline">¶</a></h2>
  3287. <div class="section" id="flask-jsonimpl">
  3288. <h3>flask.jsonimpl<a class="headerlink" href="#flask-jsonimpl" title="Permalink to this headline">¶</a></h3>
  3289. <p>Implementation helpers for the JSON support in Flask.</p>
  3290. <table class="docutils field-list" frame="void" rules="none">
  3291. <col class="field-name" />
  3292. <col class="field-body" />
  3293. <tbody valign="top">
  3294. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  3295. <li>2015 by Armin Ronacher.</li>
  3296. </ol>
  3297. </td>
  3298. </tr>
  3299. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  3300. </td>
  3301. </tr>
  3302. </tbody>
  3303. </table>
  3304. <dl class="function">
  3305. <dt id="flask.json.dump">
  3306. <code class="descclassname">flask.json.</code><code class="descname">dump</code><span class="sig-paren">(</span><em>obj</em>, <em>fp</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/json.html#dump"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.json.dump" title="Permalink to this definition">¶</a></dt>
  3307. <dd><p>Like <a class="reference internal" href="#flask.json.dumps" title="flask.json.dumps"><code class="xref py py-func docutils literal"><span class="pre">dumps()</span></code></a> but writes into a file object.</p>
  3308. </dd></dl>
  3309. <dl class="function">
  3310. <dt id="flask.json.dumps">
  3311. <code class="descclassname">flask.json.</code><code class="descname">dumps</code><span class="sig-paren">(</span><em>obj</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/json.html#dumps"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.json.dumps" title="Permalink to this definition">¶</a></dt>
  3312. <dd><p>Serialize <code class="docutils literal"><span class="pre">obj</span></code> to a JSON formatted <code class="docutils literal"><span class="pre">str</span></code> by using the application&#8217;s
  3313. configured encoder (<code class="xref py py-attr docutils literal"><span class="pre">json_encoder</span></code>) if there is an
  3314. application on the stack.</p>
  3315. <p>This function can return <code class="docutils literal"><span class="pre">unicode</span></code> strings or ascii-only bytestrings by
  3316. default which coerce into unicode strings automatically. That behavior by
  3317. default is controlled by the <code class="docutils literal"><span class="pre">JSON_AS_ASCII</span></code> configuration variable
  3318. and can be overridden by the simplejson <code class="docutils literal"><span class="pre">ensure_ascii</span></code> parameter.</p>
  3319. </dd></dl>
  3320. <dl class="function">
  3321. <dt id="flask.json.load">
  3322. <code class="descclassname">flask.json.</code><code class="descname">load</code><span class="sig-paren">(</span><em>fp</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/json.html#load"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.json.load" title="Permalink to this definition">¶</a></dt>
  3323. <dd><p>Like <a class="reference internal" href="#flask.json.loads" title="flask.json.loads"><code class="xref py py-func docutils literal"><span class="pre">loads()</span></code></a> but reads from a file object.</p>
  3324. </dd></dl>
  3325. <dl class="function">
  3326. <dt id="flask.json.loads">
  3327. <code class="descclassname">flask.json.</code><code class="descname">loads</code><span class="sig-paren">(</span><em>s</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/json.html#loads"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.json.loads" title="Permalink to this definition">¶</a></dt>
  3328. <dd><p>Unserialize a JSON object from a string <code class="docutils literal"><span class="pre">s</span></code> by using the application&#8217;s
  3329. configured decoder (<code class="xref py py-attr docutils literal"><span class="pre">json_decoder</span></code>) if there is an
  3330. application on the stack.</p>
  3331. </dd></dl>
  3332. <dl class="function">
  3333. <dt id="flask.json.htmlsafe_dump">
  3334. <code class="descclassname">flask.json.</code><code class="descname">htmlsafe_dump</code><span class="sig-paren">(</span><em>obj</em>, <em>fp</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/json.html#htmlsafe_dump"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.json.htmlsafe_dump" title="Permalink to this definition">¶</a></dt>
  3335. <dd><p>Like <a class="reference internal" href="#flask.json.htmlsafe_dumps" title="flask.json.htmlsafe_dumps"><code class="xref py py-func docutils literal"><span class="pre">htmlsafe_dumps()</span></code></a> but writes into a file object.</p>
  3336. </dd></dl>
  3337. <dl class="function">
  3338. <dt id="flask.json.htmlsafe_dumps">
  3339. <code class="descclassname">flask.json.</code><code class="descname">htmlsafe_dumps</code><span class="sig-paren">(</span><em>obj</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/json.html#htmlsafe_dumps"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.json.htmlsafe_dumps" title="Permalink to this definition">¶</a></dt>
  3340. <dd><p>Works exactly like <a class="reference internal" href="#flask.json.dumps" title="flask.json.dumps"><code class="xref py py-func docutils literal"><span class="pre">dumps()</span></code></a> but is safe for use in <code class="docutils literal"><span class="pre">&lt;script&gt;</span></code>
  3341. tags. It accepts the same arguments and returns a JSON string. Note that
  3342. this is available in templates through the <code class="docutils literal"><span class="pre">|tojson</span></code> filter which will
  3343. also mark the result as safe. Due to how this function escapes certain
  3344. characters this is safe even if used outside of <code class="docutils literal"><span class="pre">&lt;script&gt;</span></code> tags.</p>
  3345. <p>The following characters are escaped in strings:</p>
  3346. <ul class="simple">
  3347. <li><code class="docutils literal"><span class="pre">&lt;</span></code></li>
  3348. <li><code class="docutils literal"><span class="pre">&gt;</span></code></li>
  3349. <li><code class="docutils literal"><span class="pre">&amp;</span></code></li>
  3350. <li><code class="docutils literal"><span class="pre">'</span></code></li>
  3351. </ul>
  3352. <p>This makes it safe to embed such strings in any place in HTML with the
  3353. notable exception of double quoted attributes. In that case single
  3354. quote your attributes or HTML escape it in addition.</p>
  3355. <div class="versionchanged">
  3356. <p><span class="versionmodified">Changed in version 0.10: </span>This function&#8217;s return value is now always safe for HTML usage, even
  3357. if outside of script tags or if used in XHTML. This rule does not
  3358. hold true when using this function in HTML attributes that are double
  3359. quoted. Always single quote attributes if you use the <code class="docutils literal"><span class="pre">|tojson</span></code>
  3360. filter. Alternatively use <code class="docutils literal"><span class="pre">|tojson|forceescape</span></code>.</p>
  3361. </div>
  3362. </dd></dl>
  3363. <dl class="class">
  3364. <dt id="flask.json.JSONDecoder">
  3365. <em class="property">class </em><code class="descclassname">flask.json.</code><code class="descname">JSONDecoder</code><span class="sig-paren">(</span><em>encoding=None</em>, <em>object_hook=None</em>, <em>parse_float=None</em>, <em>parse_int=None</em>, <em>parse_constant=None</em>, <em>strict=True</em>, <em>object_pairs_hook=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/json.html#JSONDecoder"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.json.JSONDecoder" title="Permalink to this definition">¶</a></dt>
  3366. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">simplejson.decoder.JSONDecoder</span></code></p>
  3367. <p>The default JSON decoder. This one does not change the behavior from
  3368. the default simplejson decoder. Consult the <code class="xref py py-mod docutils literal"><span class="pre">json</span></code> documentation
  3369. for more information. This decoder is not only used for the load
  3370. functions of this module but also <code class="xref py py-attr docutils literal"><span class="pre">Request</span></code>.</p>
  3371. </dd></dl>
  3372. <dl class="class">
  3373. <dt id="flask.json.JSONEncoder">
  3374. <em class="property">class </em><code class="descclassname">flask.json.</code><code class="descname">JSONEncoder</code><span class="sig-paren">(</span><em>skipkeys=False</em>, <em>ensure_ascii=True</em>, <em>check_circular=True</em>, <em>allow_nan=True</em>, <em>sort_keys=False</em>, <em>indent=None</em>, <em>separators=None</em>, <em>encoding='utf-8'</em>, <em>default=None</em>, <em>use_decimal=True</em>, <em>namedtuple_as_object=True</em>, <em>tuple_as_array=True</em>, <em>bigint_as_string=False</em>, <em>item_sort_key=None</em>, <em>for_json=False</em>, <em>ignore_nan=False</em>, <em>int_as_string_bitcount=None</em>, <em>iterable_as_array=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/json.html#JSONEncoder"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.json.JSONEncoder" title="Permalink to this definition">¶</a></dt>
  3375. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">simplejson.encoder.JSONEncoder</span></code></p>
  3376. <p>The default Flask JSON encoder. This one extends the default simplejson
  3377. encoder by also supporting <code class="docutils literal"><span class="pre">datetime</span></code> objects, <code class="docutils literal"><span class="pre">UUID</span></code> as well as
  3378. <code class="docutils literal"><span class="pre">Markup</span></code> objects which are serialized as RFC 822 datetime strings (same
  3379. as the HTTP date format). In order to support more data types override the
  3380. <a class="reference internal" href="#flask.json.JSONEncoder.default" title="flask.json.JSONEncoder.default"><code class="xref py py-meth docutils literal"><span class="pre">default()</span></code></a> method.</p>
  3381. <dl class="method">
  3382. <dt id="flask.json.JSONEncoder.default">
  3383. <code class="descname">default</code><span class="sig-paren">(</span><em>o</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/json.html#JSONEncoder.default"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.json.JSONEncoder.default" title="Permalink to this definition">¶</a></dt>
  3384. <dd><p>Implement this method in a subclass such that it returns a
  3385. serializable object for <code class="docutils literal"><span class="pre">o</span></code>, or calls the base implementation (to
  3386. raise a <code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code>).</p>
  3387. <p>For example, to support arbitrary iterators, you could implement
  3388. default like this:</p>
  3389. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">default</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">o</span><span class="p">):</span>
  3390. <span class="k">try</span><span class="p">:</span>
  3391. <span class="n">iterable</span> <span class="o">=</span> <span class="nb">iter</span><span class="p">(</span><span class="n">o</span><span class="p">)</span>
  3392. <span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span>
  3393. <span class="k">pass</span>
  3394. <span class="k">else</span><span class="p">:</span>
  3395. <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="n">iterable</span><span class="p">)</span>
  3396. <span class="k">return</span> <span class="n">JSONEncoder</span><span class="o">.</span><span class="n">default</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">o</span><span class="p">)</span>
  3397. </pre></div>
  3398. </div>
  3399. </dd></dl>
  3400. </dd></dl>
  3401. <dl class="function">
  3402. <dt id="flask.json.jsonify">
  3403. <code class="descclassname">flask.json.</code><code class="descname">jsonify</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/json.html#jsonify"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.json.jsonify" title="Permalink to this definition">¶</a></dt>
  3404. <dd><p>This function wraps <a class="reference internal" href="#flask.json.dumps" title="flask.json.dumps"><code class="xref py py-func docutils literal"><span class="pre">dumps()</span></code></a> to add a few enhancements that make
  3405. life easier. It turns the JSON output into a <code class="xref py py-class docutils literal"><span class="pre">Response</span></code>
  3406. object with the <em class="mimetype">application/json</em> mimetype. For convenience, it
  3407. also converts multiple arguments into an array or multiple keyword arguments
  3408. into a dict. This means that both <code class="docutils literal"><span class="pre">jsonify(1,2,3)</span></code> and
  3409. <code class="docutils literal"><span class="pre">jsonify([1,2,3])</span></code> serialize to <code class="docutils literal"><span class="pre">[1,2,3]</span></code>.</p>
  3410. <p>For clarity, the JSON serialization behavior has the following differences
  3411. from <a class="reference internal" href="#flask.json.dumps" title="flask.json.dumps"><code class="xref py py-func docutils literal"><span class="pre">dumps()</span></code></a>:</p>
  3412. <ol class="arabic simple">
  3413. <li>Single argument: Passed straight through to <a class="reference internal" href="#flask.json.dumps" title="flask.json.dumps"><code class="xref py py-func docutils literal"><span class="pre">dumps()</span></code></a>.</li>
  3414. <li>Multiple arguments: Converted to an array before being passed to
  3415. <a class="reference internal" href="#flask.json.dumps" title="flask.json.dumps"><code class="xref py py-func docutils literal"><span class="pre">dumps()</span></code></a>.</li>
  3416. <li>Multiple keyword arguments: Converted to a dict before being passed to
  3417. <a class="reference internal" href="#flask.json.dumps" title="flask.json.dumps"><code class="xref py py-func docutils literal"><span class="pre">dumps()</span></code></a>.</li>
  3418. <li>Both args and kwargs: Behavior undefined and will throw an exception.</li>
  3419. </ol>
  3420. <p>Example usage:</p>
  3421. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">flask</span> <span class="k">import</span> <span class="n">jsonify</span>
  3422. <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/_get_current_user&#39;</span><span class="p">)</span>
  3423. <span class="k">def</span> <span class="nf">get_current_user</span><span class="p">():</span>
  3424. <span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">username</span><span class="o">=</span><span class="n">g</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">username</span><span class="p">,</span>
  3425. <span class="n">email</span><span class="o">=</span><span class="n">g</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">email</span><span class="p">,</span>
  3426. <span class="nb">id</span><span class="o">=</span><span class="n">g</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>
  3427. </pre></div>
  3428. </div>
  3429. <p>This will send a JSON response like this to the browser:</p>
  3430. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="p">{</span>
  3431. <span class="s2">&quot;username&quot;</span><span class="p">:</span> <span class="s2">&quot;admin&quot;</span><span class="p">,</span>
  3432. <span class="s2">&quot;email&quot;</span><span class="p">:</span> <span class="s2">&quot;admin@localhost&quot;</span><span class="p">,</span>
  3433. <span class="s2">&quot;id&quot;</span><span class="p">:</span> <span class="mi">42</span>
  3434. <span class="p">}</span>
  3435. </pre></div>
  3436. </div>
  3437. <div class="versionchanged">
  3438. <p><span class="versionmodified">Changed in version 0.11: </span>Added support for serializing top-level arrays. This introduces a
  3439. security risk in ancient browsers. See <span class="xref std std-ref">json-security</span> for details.</p>
  3440. </div>
  3441. <p>This function&#8217;s response will be pretty printed if it was not requested
  3442. with <code class="docutils literal"><span class="pre">X-Requested-With:</span> <span class="pre">XMLHttpRequest</span></code> to simplify debugging unless
  3443. the <code class="docutils literal"><span class="pre">JSONIFY_PRETTYPRINT_REGULAR</span></code> config parameter is set to false.
  3444. Compressed (not pretty) formatting currently means no indents and no
  3445. spaces after separators.</p>
  3446. <div class="versionadded">
  3447. <p><span class="versionmodified">New in version 0.2.</span></p>
  3448. </div>
  3449. </dd></dl>
  3450. </div>
  3451. </div>
  3452. <div class="section" id="module-flask.logging">
  3453. <span id="flask-logging-module"></span><h2>flask.logging module<a class="headerlink" href="#module-flask.logging" title="Permalink to this headline">¶</a></h2>
  3454. <div class="section" id="flask-logging">
  3455. <h3>flask.logging<a class="headerlink" href="#flask-logging" title="Permalink to this headline">¶</a></h3>
  3456. <p>Implements the logging support for Flask.</p>
  3457. <table class="docutils field-list" frame="void" rules="none">
  3458. <col class="field-name" />
  3459. <col class="field-body" />
  3460. <tbody valign="top">
  3461. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  3462. <li>2015 by Armin Ronacher.</li>
  3463. </ol>
  3464. </td>
  3465. </tr>
  3466. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  3467. </td>
  3468. </tr>
  3469. </tbody>
  3470. </table>
  3471. <dl class="function">
  3472. <dt id="flask.logging.create_logger">
  3473. <code class="descclassname">flask.logging.</code><code class="descname">create_logger</code><span class="sig-paren">(</span><em>app</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/logging.html#create_logger"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.logging.create_logger" title="Permalink to this definition">¶</a></dt>
  3474. <dd><p>Creates a logger for the given application. This logger works
  3475. similar to a regular Python logger but changes the effective logging
  3476. level based on the application&#8217;s debug flag. Furthermore this
  3477. function also removes all attached handlers in case there was a
  3478. logger with the log name before.</p>
  3479. </dd></dl>
  3480. </div>
  3481. </div>
  3482. <div class="section" id="module-flask.sessions">
  3483. <span id="flask-sessions-module"></span><h2>flask.sessions module<a class="headerlink" href="#module-flask.sessions" title="Permalink to this headline">¶</a></h2>
  3484. <div class="section" id="flask-sessions">
  3485. <h3>flask.sessions<a class="headerlink" href="#flask-sessions" title="Permalink to this headline">¶</a></h3>
  3486. <p>Implements cookie based sessions based on itsdangerous.</p>
  3487. <table class="docutils field-list" frame="void" rules="none">
  3488. <col class="field-name" />
  3489. <col class="field-body" />
  3490. <tbody valign="top">
  3491. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  3492. <li>2015 by Armin Ronacher.</li>
  3493. </ol>
  3494. </td>
  3495. </tr>
  3496. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  3497. </td>
  3498. </tr>
  3499. </tbody>
  3500. </table>
  3501. <dl class="class">
  3502. <dt id="flask.sessions.NullSession">
  3503. <em class="property">class </em><code class="descclassname">flask.sessions.</code><code class="descname">NullSession</code><span class="sig-paren">(</span><em>initial=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#NullSession"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.NullSession" title="Permalink to this definition">¶</a></dt>
  3504. <dd><p>Bases: <a class="reference internal" href="#flask.sessions.SecureCookieSession" title="flask.sessions.SecureCookieSession"><code class="xref py py-class docutils literal"><span class="pre">flask.sessions.SecureCookieSession</span></code></a></p>
  3505. <p>Class used to generate nicer error messages if sessions are not
  3506. available. Will still allow read-only access to the empty session
  3507. but fail on setting.</p>
  3508. <dl class="method">
  3509. <dt id="flask.sessions.NullSession.clear">
  3510. <code class="descname">clear</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.NullSession.clear" title="Permalink to this definition">¶</a></dt>
  3511. <dd></dd></dl>
  3512. <dl class="method">
  3513. <dt id="flask.sessions.NullSession.pop">
  3514. <code class="descname">pop</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.NullSession.pop" title="Permalink to this definition">¶</a></dt>
  3515. <dd></dd></dl>
  3516. <dl class="method">
  3517. <dt id="flask.sessions.NullSession.popitem">
  3518. <code class="descname">popitem</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.NullSession.popitem" title="Permalink to this definition">¶</a></dt>
  3519. <dd></dd></dl>
  3520. <dl class="method">
  3521. <dt id="flask.sessions.NullSession.setdefault">
  3522. <code class="descname">setdefault</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.NullSession.setdefault" title="Permalink to this definition">¶</a></dt>
  3523. <dd></dd></dl>
  3524. <dl class="method">
  3525. <dt id="flask.sessions.NullSession.update">
  3526. <code class="descname">update</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.NullSession.update" title="Permalink to this definition">¶</a></dt>
  3527. <dd></dd></dl>
  3528. </dd></dl>
  3529. <dl class="class">
  3530. <dt id="flask.sessions.SecureCookieSession">
  3531. <em class="property">class </em><code class="descclassname">flask.sessions.</code><code class="descname">SecureCookieSession</code><span class="sig-paren">(</span><em>initial=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#SecureCookieSession"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SecureCookieSession" title="Permalink to this definition">¶</a></dt>
  3532. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">werkzeug.datastructures.CallbackDict</span></code>, <a class="reference internal" href="#flask.sessions.SessionMixin" title="flask.sessions.SessionMixin"><code class="xref py py-class docutils literal"><span class="pre">flask.sessions.SessionMixin</span></code></a></p>
  3533. <p>Base class for sessions based on signed cookies.</p>
  3534. </dd></dl>
  3535. <dl class="class">
  3536. <dt id="flask.sessions.SecureCookieSessionInterface">
  3537. <em class="property">class </em><code class="descclassname">flask.sessions.</code><code class="descname">SecureCookieSessionInterface</code><a class="reference internal" href="../_modules/flask/sessions.html#SecureCookieSessionInterface"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface" title="Permalink to this definition">¶</a></dt>
  3538. <dd><p>Bases: <a class="reference internal" href="#flask.sessions.SessionInterface" title="flask.sessions.SessionInterface"><code class="xref py py-class docutils literal"><span class="pre">flask.sessions.SessionInterface</span></code></a></p>
  3539. <p>The default session interface that stores sessions in signed cookies
  3540. through the <code class="xref py py-mod docutils literal"><span class="pre">itsdangerous</span></code> module.</p>
  3541. <dl class="staticmethod">
  3542. <dt id="flask.sessions.SecureCookieSessionInterface.digest_method">
  3543. <em class="property">static </em><code class="descname">digest_method</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.digest_method" title="Permalink to this definition">¶</a></dt>
  3544. <dd><p>the hash function to use for the signature. The default is sha1</p>
  3545. </dd></dl>
  3546. <dl class="method">
  3547. <dt id="flask.sessions.SecureCookieSessionInterface.get_signing_serializer">
  3548. <code class="descname">get_signing_serializer</code><span class="sig-paren">(</span><em>app</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#SecureCookieSessionInterface.get_signing_serializer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.get_signing_serializer" title="Permalink to this definition">¶</a></dt>
  3549. <dd></dd></dl>
  3550. <dl class="attribute">
  3551. <dt id="flask.sessions.SecureCookieSessionInterface.key_derivation">
  3552. <code class="descname">key_derivation</code><em class="property"> = 'hmac'</em><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.key_derivation" title="Permalink to this definition">¶</a></dt>
  3553. <dd><p>the name of the itsdangerous supported key derivation. The default
  3554. is hmac.</p>
  3555. </dd></dl>
  3556. <dl class="method">
  3557. <dt id="flask.sessions.SecureCookieSessionInterface.open_session">
  3558. <code class="descname">open_session</code><span class="sig-paren">(</span><em>app</em>, <em>request</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#SecureCookieSessionInterface.open_session"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.open_session" title="Permalink to this definition">¶</a></dt>
  3559. <dd></dd></dl>
  3560. <dl class="attribute">
  3561. <dt id="flask.sessions.SecureCookieSessionInterface.salt">
  3562. <code class="descname">salt</code><em class="property"> = 'cookie-session'</em><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.salt" title="Permalink to this definition">¶</a></dt>
  3563. <dd><p>the salt that should be applied on top of the secret key for the
  3564. signing of cookie based sessions.</p>
  3565. </dd></dl>
  3566. <dl class="method">
  3567. <dt id="flask.sessions.SecureCookieSessionInterface.save_session">
  3568. <code class="descname">save_session</code><span class="sig-paren">(</span><em>app</em>, <em>session</em>, <em>response</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#SecureCookieSessionInterface.save_session"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.save_session" title="Permalink to this definition">¶</a></dt>
  3569. <dd></dd></dl>
  3570. <dl class="attribute">
  3571. <dt id="flask.sessions.SecureCookieSessionInterface.serializer">
  3572. <code class="descname">serializer</code><em class="property"> = &lt;flask.sessions.TaggedJSONSerializer object at 0x000001E1821A4C18&gt;</em><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.serializer" title="Permalink to this definition">¶</a></dt>
  3573. <dd><p>A python serializer for the payload. The default is a compact
  3574. JSON derived serializer with support for some extra Python types
  3575. such as datetime objects or tuples.</p>
  3576. </dd></dl>
  3577. <dl class="attribute">
  3578. <dt id="flask.sessions.SecureCookieSessionInterface.session_class">
  3579. <code class="descname">session_class</code><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.session_class" title="Permalink to this definition">¶</a></dt>
  3580. <dd><p>alias of <a class="reference internal" href="#flask.sessions.SecureCookieSession" title="flask.sessions.SecureCookieSession"><code class="xref py py-class docutils literal"><span class="pre">SecureCookieSession</span></code></a></p>
  3581. </dd></dl>
  3582. </dd></dl>
  3583. <dl class="class">
  3584. <dt id="flask.sessions.SessionInterface">
  3585. <em class="property">class </em><code class="descclassname">flask.sessions.</code><code class="descname">SessionInterface</code><a class="reference internal" href="../_modules/flask/sessions.html#SessionInterface"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SessionInterface" title="Permalink to this definition">¶</a></dt>
  3586. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
  3587. <p>The basic interface you have to implement in order to replace the
  3588. default session interface which uses werkzeug&#8217;s securecookie
  3589. implementation. The only methods you have to implement are
  3590. <a class="reference internal" href="#flask.sessions.SessionInterface.open_session" title="flask.sessions.SessionInterface.open_session"><code class="xref py py-meth docutils literal"><span class="pre">open_session()</span></code></a> and <a class="reference internal" href="#flask.sessions.SessionInterface.save_session" title="flask.sessions.SessionInterface.save_session"><code class="xref py py-meth docutils literal"><span class="pre">save_session()</span></code></a>, the others have
  3591. useful defaults which you don&#8217;t need to change.</p>
  3592. <p>The session object returned by the <a class="reference internal" href="#flask.sessions.SessionInterface.open_session" title="flask.sessions.SessionInterface.open_session"><code class="xref py py-meth docutils literal"><span class="pre">open_session()</span></code></a> method has to
  3593. provide a dictionary like interface plus the properties and methods
  3594. from the <a class="reference internal" href="#flask.sessions.SessionMixin" title="flask.sessions.SessionMixin"><code class="xref py py-class docutils literal"><span class="pre">SessionMixin</span></code></a>. We recommend just subclassing a dict
  3595. and adding that mixin:</p>
  3596. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Session</span><span class="p">(</span><span class="nb">dict</span><span class="p">,</span> <span class="n">SessionMixin</span><span class="p">):</span>
  3597. <span class="k">pass</span>
  3598. </pre></div>
  3599. </div>
  3600. <p>If <a class="reference internal" href="#flask.sessions.SessionInterface.open_session" title="flask.sessions.SessionInterface.open_session"><code class="xref py py-meth docutils literal"><span class="pre">open_session()</span></code></a> returns <code class="docutils literal"><span class="pre">None</span></code> Flask will call into
  3601. <a class="reference internal" href="#flask.sessions.SessionInterface.make_null_session" title="flask.sessions.SessionInterface.make_null_session"><code class="xref py py-meth docutils literal"><span class="pre">make_null_session()</span></code></a> to create a session that acts as replacement
  3602. if the session support cannot work because some requirement is not
  3603. fulfilled. The default <a class="reference internal" href="#flask.sessions.NullSession" title="flask.sessions.NullSession"><code class="xref py py-class docutils literal"><span class="pre">NullSession</span></code></a> class that is created
  3604. will complain that the secret key was not set.</p>
  3605. <p>To replace the session interface on an application all you have to do
  3606. is to assign <code class="xref py py-attr docutils literal"><span class="pre">flask.Flask.session_interface</span></code>:</p>
  3607. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span>
  3608. <span class="n">app</span><span class="o">.</span><span class="n">session_interface</span> <span class="o">=</span> <span class="n">MySessionInterface</span><span class="p">()</span>
  3609. </pre></div>
  3610. </div>
  3611. <div class="versionadded">
  3612. <p><span class="versionmodified">New in version 0.8.</span></p>
  3613. </div>
  3614. <dl class="method">
  3615. <dt id="flask.sessions.SessionInterface.get_cookie_domain">
  3616. <code class="descname">get_cookie_domain</code><span class="sig-paren">(</span><em>app</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#SessionInterface.get_cookie_domain"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SessionInterface.get_cookie_domain" title="Permalink to this definition">¶</a></dt>
  3617. <dd><p>Helpful helper method that returns the cookie domain that should
  3618. be used for the session cookie if session cookies are used.</p>
  3619. </dd></dl>
  3620. <dl class="method">
  3621. <dt id="flask.sessions.SessionInterface.get_cookie_httponly">
  3622. <code class="descname">get_cookie_httponly</code><span class="sig-paren">(</span><em>app</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#SessionInterface.get_cookie_httponly"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SessionInterface.get_cookie_httponly" title="Permalink to this definition">¶</a></dt>
  3623. <dd><p>Returns True if the session cookie should be httponly. This
  3624. currently just returns the value of the <code class="docutils literal"><span class="pre">SESSION_COOKIE_HTTPONLY</span></code>
  3625. config var.</p>
  3626. </dd></dl>
  3627. <dl class="method">
  3628. <dt id="flask.sessions.SessionInterface.get_cookie_path">
  3629. <code class="descname">get_cookie_path</code><span class="sig-paren">(</span><em>app</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#SessionInterface.get_cookie_path"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SessionInterface.get_cookie_path" title="Permalink to this definition">¶</a></dt>
  3630. <dd><p>Returns the path for which the cookie should be valid. The
  3631. default implementation uses the value from the <code class="docutils literal"><span class="pre">SESSION_COOKIE_PATH</span></code>
  3632. config var if it&#8217;s set, and falls back to <code class="docutils literal"><span class="pre">APPLICATION_ROOT</span></code> or
  3633. uses <code class="docutils literal"><span class="pre">/</span></code> if it&#8217;s <code class="docutils literal"><span class="pre">None</span></code>.</p>
  3634. </dd></dl>
  3635. <dl class="method">
  3636. <dt id="flask.sessions.SessionInterface.get_cookie_secure">
  3637. <code class="descname">get_cookie_secure</code><span class="sig-paren">(</span><em>app</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#SessionInterface.get_cookie_secure"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SessionInterface.get_cookie_secure" title="Permalink to this definition">¶</a></dt>
  3638. <dd><p>Returns True if the cookie should be secure. This currently
  3639. just returns the value of the <code class="docutils literal"><span class="pre">SESSION_COOKIE_SECURE</span></code> setting.</p>
  3640. </dd></dl>
  3641. <dl class="method">
  3642. <dt id="flask.sessions.SessionInterface.get_expiration_time">
  3643. <code class="descname">get_expiration_time</code><span class="sig-paren">(</span><em>app</em>, <em>session</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#SessionInterface.get_expiration_time"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SessionInterface.get_expiration_time" title="Permalink to this definition">¶</a></dt>
  3644. <dd><p>A helper method that returns an expiration date for the session
  3645. or <code class="docutils literal"><span class="pre">None</span></code> if the session is linked to the browser session. The
  3646. default implementation returns now + the permanent session
  3647. lifetime configured on the application.</p>
  3648. </dd></dl>
  3649. <dl class="method">
  3650. <dt id="flask.sessions.SessionInterface.is_null_session">
  3651. <code class="descname">is_null_session</code><span class="sig-paren">(</span><em>obj</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#SessionInterface.is_null_session"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SessionInterface.is_null_session" title="Permalink to this definition">¶</a></dt>
  3652. <dd><p>Checks if a given object is a null session. Null sessions are
  3653. not asked to be saved.</p>
  3654. <p>This checks if the object is an instance of <a class="reference internal" href="#flask.sessions.SessionInterface.null_session_class" title="flask.sessions.SessionInterface.null_session_class"><code class="xref py py-attr docutils literal"><span class="pre">null_session_class</span></code></a>
  3655. by default.</p>
  3656. </dd></dl>
  3657. <dl class="method">
  3658. <dt id="flask.sessions.SessionInterface.make_null_session">
  3659. <code class="descname">make_null_session</code><span class="sig-paren">(</span><em>app</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#SessionInterface.make_null_session"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SessionInterface.make_null_session" title="Permalink to this definition">¶</a></dt>
  3660. <dd><p>Creates a null session which acts as a replacement object if the
  3661. real session support could not be loaded due to a configuration
  3662. error. This mainly aids the user experience because the job of the
  3663. null session is to still support lookup without complaining but
  3664. modifications are answered with a helpful error message of what
  3665. failed.</p>
  3666. <p>This creates an instance of <a class="reference internal" href="#flask.sessions.SessionInterface.null_session_class" title="flask.sessions.SessionInterface.null_session_class"><code class="xref py py-attr docutils literal"><span class="pre">null_session_class</span></code></a> by default.</p>
  3667. </dd></dl>
  3668. <dl class="attribute">
  3669. <dt id="flask.sessions.SessionInterface.null_session_class">
  3670. <code class="descname">null_session_class</code><a class="headerlink" href="#flask.sessions.SessionInterface.null_session_class" title="Permalink to this definition">¶</a></dt>
  3671. <dd><p><a class="reference internal" href="#flask.sessions.SessionInterface.make_null_session" title="flask.sessions.SessionInterface.make_null_session"><code class="xref py py-meth docutils literal"><span class="pre">make_null_session()</span></code></a> will look here for the class that should
  3672. be created when a null session is requested. Likewise the
  3673. <a class="reference internal" href="#flask.sessions.SessionInterface.is_null_session" title="flask.sessions.SessionInterface.is_null_session"><code class="xref py py-meth docutils literal"><span class="pre">is_null_session()</span></code></a> method will perform a typecheck against
  3674. this type.</p>
  3675. <p>alias of <a class="reference internal" href="#flask.sessions.NullSession" title="flask.sessions.NullSession"><code class="xref py py-class docutils literal"><span class="pre">NullSession</span></code></a></p>
  3676. </dd></dl>
  3677. <dl class="method">
  3678. <dt id="flask.sessions.SessionInterface.open_session">
  3679. <code class="descname">open_session</code><span class="sig-paren">(</span><em>app</em>, <em>request</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#SessionInterface.open_session"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SessionInterface.open_session" title="Permalink to this definition">¶</a></dt>
  3680. <dd><p>This method has to be implemented and must either return <code class="docutils literal"><span class="pre">None</span></code>
  3681. in case the loading failed because of a configuration error or an
  3682. instance of a session object which implements a dictionary like
  3683. interface + the methods and attributes on <a class="reference internal" href="#flask.sessions.SessionMixin" title="flask.sessions.SessionMixin"><code class="xref py py-class docutils literal"><span class="pre">SessionMixin</span></code></a>.</p>
  3684. </dd></dl>
  3685. <dl class="attribute">
  3686. <dt id="flask.sessions.SessionInterface.pickle_based">
  3687. <code class="descname">pickle_based</code><em class="property"> = False</em><a class="headerlink" href="#flask.sessions.SessionInterface.pickle_based" title="Permalink to this definition">¶</a></dt>
  3688. <dd><p>A flag that indicates if the session interface is pickle based.
  3689. This can be used by flask extensions to make a decision in regards
  3690. to how to deal with the session object.</p>
  3691. <div class="versionadded">
  3692. <p><span class="versionmodified">New in version 0.10.</span></p>
  3693. </div>
  3694. </dd></dl>
  3695. <dl class="method">
  3696. <dt id="flask.sessions.SessionInterface.save_session">
  3697. <code class="descname">save_session</code><span class="sig-paren">(</span><em>app</em>, <em>session</em>, <em>response</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#SessionInterface.save_session"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SessionInterface.save_session" title="Permalink to this definition">¶</a></dt>
  3698. <dd><p>This is called for actual sessions returned by <a class="reference internal" href="#flask.sessions.SessionInterface.open_session" title="flask.sessions.SessionInterface.open_session"><code class="xref py py-meth docutils literal"><span class="pre">open_session()</span></code></a>
  3699. at the end of the request. This is still called during a request
  3700. context so if you absolutely need access to the request you can do
  3701. that.</p>
  3702. </dd></dl>
  3703. <dl class="method">
  3704. <dt id="flask.sessions.SessionInterface.should_set_cookie">
  3705. <code class="descname">should_set_cookie</code><span class="sig-paren">(</span><em>app</em>, <em>session</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#SessionInterface.should_set_cookie"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SessionInterface.should_set_cookie" title="Permalink to this definition">¶</a></dt>
  3706. <dd><p>Indicates whether a cookie should be set now or not. This is
  3707. used by session backends to figure out if they should emit a
  3708. set-cookie header or not. The default behavior is controlled by
  3709. the <code class="docutils literal"><span class="pre">SESSION_REFRESH_EACH_REQUEST</span></code> config variable. If
  3710. it&#8217;s set to <code class="docutils literal"><span class="pre">False</span></code> then a cookie is only set if the session is
  3711. modified, if set to <code class="docutils literal"><span class="pre">True</span></code> it&#8217;s always set if the session is
  3712. permanent.</p>
  3713. <p>This check is usually skipped if sessions get deleted.</p>
  3714. <div class="versionadded">
  3715. <p><span class="versionmodified">New in version 0.11.</span></p>
  3716. </div>
  3717. </dd></dl>
  3718. </dd></dl>
  3719. <dl class="class">
  3720. <dt id="flask.sessions.SessionMixin">
  3721. <em class="property">class </em><code class="descclassname">flask.sessions.</code><code class="descname">SessionMixin</code><a class="reference internal" href="../_modules/flask/sessions.html#SessionMixin"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.SessionMixin" title="Permalink to this definition">¶</a></dt>
  3722. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
  3723. <p>Expands a basic dictionary with an accessors that are expected
  3724. by Flask extensions and users for the session.</p>
  3725. <dl class="attribute">
  3726. <dt id="flask.sessions.SessionMixin.modified">
  3727. <code class="descname">modified</code><em class="property"> = True</em><a class="headerlink" href="#flask.sessions.SessionMixin.modified" title="Permalink to this definition">¶</a></dt>
  3728. <dd><p>for some backends this will always be <code class="docutils literal"><span class="pre">True</span></code>, but some backends will
  3729. default this to false and detect changes in the dictionary for as
  3730. long as changes do not happen on mutable structures in the session.
  3731. The default mixin implementation just hardcodes <code class="docutils literal"><span class="pre">True</span></code> in.</p>
  3732. </dd></dl>
  3733. <dl class="attribute">
  3734. <dt id="flask.sessions.SessionMixin.new">
  3735. <code class="descname">new</code><em class="property"> = False</em><a class="headerlink" href="#flask.sessions.SessionMixin.new" title="Permalink to this definition">¶</a></dt>
  3736. <dd><p>some session backends can tell you if a session is new, but that is
  3737. not necessarily guaranteed. Use with caution. The default mixin
  3738. implementation just hardcodes <code class="docutils literal"><span class="pre">False</span></code> in.</p>
  3739. </dd></dl>
  3740. <dl class="attribute">
  3741. <dt id="flask.sessions.SessionMixin.permanent">
  3742. <code class="descname">permanent</code><a class="headerlink" href="#flask.sessions.SessionMixin.permanent" title="Permalink to this definition">¶</a></dt>
  3743. <dd><p>this reflects the <code class="docutils literal"><span class="pre">'_permanent'</span></code> key in the dict.</p>
  3744. </dd></dl>
  3745. </dd></dl>
  3746. <dl class="class">
  3747. <dt id="flask.sessions.TaggedJSONSerializer">
  3748. <em class="property">class </em><code class="descclassname">flask.sessions.</code><code class="descname">TaggedJSONSerializer</code><a class="reference internal" href="../_modules/flask/sessions.html#TaggedJSONSerializer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.TaggedJSONSerializer" title="Permalink to this definition">¶</a></dt>
  3749. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
  3750. <p>A customized JSON serializer that supports a few extra types that
  3751. we take for granted when serializing (tuples, markup objects, datetime).</p>
  3752. <dl class="method">
  3753. <dt id="flask.sessions.TaggedJSONSerializer.dumps">
  3754. <code class="descname">dumps</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#TaggedJSONSerializer.dumps"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.TaggedJSONSerializer.dumps" title="Permalink to this definition">¶</a></dt>
  3755. <dd></dd></dl>
  3756. <dl class="method">
  3757. <dt id="flask.sessions.TaggedJSONSerializer.loads">
  3758. <code class="descname">loads</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/sessions.html#TaggedJSONSerializer.loads"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.sessions.TaggedJSONSerializer.loads" title="Permalink to this definition">¶</a></dt>
  3759. <dd></dd></dl>
  3760. </dd></dl>
  3761. </div>
  3762. </div>
  3763. <div class="section" id="module-flask.signals">
  3764. <span id="flask-signals-module"></span><h2>flask.signals module<a class="headerlink" href="#module-flask.signals" title="Permalink to this headline">¶</a></h2>
  3765. <div class="section" id="flask-signals">
  3766. <h3>flask.signals<a class="headerlink" href="#flask-signals" title="Permalink to this headline">¶</a></h3>
  3767. <p>Implements signals based on blinker if available, otherwise
  3768. falls silently back to a noop.</p>
  3769. <table class="docutils field-list" frame="void" rules="none">
  3770. <col class="field-name" />
  3771. <col class="field-body" />
  3772. <tbody valign="top">
  3773. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  3774. <li>2015 by Armin Ronacher.</li>
  3775. </ol>
  3776. </td>
  3777. </tr>
  3778. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  3779. </td>
  3780. </tr>
  3781. </tbody>
  3782. </table>
  3783. <dl class="class">
  3784. <dt id="flask.signals.Namespace">
  3785. <em class="property">class </em><code class="descclassname">flask.signals.</code><code class="descname">Namespace</code><a class="reference internal" href="../_modules/flask/signals.html#Namespace"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.signals.Namespace" title="Permalink to this definition">¶</a></dt>
  3786. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
  3787. <dl class="method">
  3788. <dt id="flask.signals.Namespace.signal">
  3789. <code class="descname">signal</code><span class="sig-paren">(</span><em>name</em>, <em>doc=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/signals.html#Namespace.signal"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.signals.Namespace.signal" title="Permalink to this definition">¶</a></dt>
  3790. <dd></dd></dl>
  3791. </dd></dl>
  3792. </div>
  3793. </div>
  3794. <div class="section" id="module-flask.templating">
  3795. <span id="flask-templating-module"></span><h2>flask.templating module<a class="headerlink" href="#module-flask.templating" title="Permalink to this headline">¶</a></h2>
  3796. <div class="section" id="flask-templating">
  3797. <h3>flask.templating<a class="headerlink" href="#flask-templating" title="Permalink to this headline">¶</a></h3>
  3798. <p>Implements the bridge to Jinja2.</p>
  3799. <table class="docutils field-list" frame="void" rules="none">
  3800. <col class="field-name" />
  3801. <col class="field-body" />
  3802. <tbody valign="top">
  3803. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  3804. <li>2015 by Armin Ronacher.</li>
  3805. </ol>
  3806. </td>
  3807. </tr>
  3808. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  3809. </td>
  3810. </tr>
  3811. </tbody>
  3812. </table>
  3813. <dl class="class">
  3814. <dt id="flask.templating.DispatchingJinjaLoader">
  3815. <em class="property">class </em><code class="descclassname">flask.templating.</code><code class="descname">DispatchingJinjaLoader</code><span class="sig-paren">(</span><em>app</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/templating.html#DispatchingJinjaLoader"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.templating.DispatchingJinjaLoader" title="Permalink to this definition">¶</a></dt>
  3816. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">jinja2.loaders.BaseLoader</span></code></p>
  3817. <p>A loader that looks for templates in the application and all
  3818. the blueprint folders.</p>
  3819. <dl class="method">
  3820. <dt id="flask.templating.DispatchingJinjaLoader.get_source">
  3821. <code class="descname">get_source</code><span class="sig-paren">(</span><em>environment</em>, <em>template</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/templating.html#DispatchingJinjaLoader.get_source"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.templating.DispatchingJinjaLoader.get_source" title="Permalink to this definition">¶</a></dt>
  3822. <dd></dd></dl>
  3823. <dl class="method">
  3824. <dt id="flask.templating.DispatchingJinjaLoader.list_templates">
  3825. <code class="descname">list_templates</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/templating.html#DispatchingJinjaLoader.list_templates"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.templating.DispatchingJinjaLoader.list_templates" title="Permalink to this definition">¶</a></dt>
  3826. <dd></dd></dl>
  3827. </dd></dl>
  3828. <dl class="class">
  3829. <dt id="flask.templating.Environment">
  3830. <em class="property">class </em><code class="descclassname">flask.templating.</code><code class="descname">Environment</code><span class="sig-paren">(</span><em>app</em>, <em>**options</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/templating.html#Environment"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.templating.Environment" title="Permalink to this definition">¶</a></dt>
  3831. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">jinja2.environment.Environment</span></code></p>
  3832. <p>Works like a regular Jinja2 environment but has some additional
  3833. knowledge of how Flask&#8217;s blueprint works so that it can prepend the
  3834. name of the blueprint to referenced templates if necessary.</p>
  3835. </dd></dl>
  3836. <dl class="function">
  3837. <dt id="flask.templating.render_template">
  3838. <code class="descclassname">flask.templating.</code><code class="descname">render_template</code><span class="sig-paren">(</span><em>template_name_or_list</em>, <em>**context</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/templating.html#render_template"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.templating.render_template" title="Permalink to this definition">¶</a></dt>
  3839. <dd><p>Renders a template from the template folder with the given
  3840. context.</p>
  3841. <table class="docutils field-list" frame="void" rules="none">
  3842. <col class="field-name" />
  3843. <col class="field-body" />
  3844. <tbody valign="top">
  3845. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  3846. <li><strong>template_name_or_list</strong> &#8211; the name of the template to be
  3847. rendered, or an iterable with template names
  3848. the first one existing will be rendered</li>
  3849. <li><strong>context</strong> &#8211; the variables that should be available in the
  3850. context of the template.</li>
  3851. </ul>
  3852. </td>
  3853. </tr>
  3854. </tbody>
  3855. </table>
  3856. </dd></dl>
  3857. <dl class="function">
  3858. <dt id="flask.templating.render_template_string">
  3859. <code class="descclassname">flask.templating.</code><code class="descname">render_template_string</code><span class="sig-paren">(</span><em>source</em>, <em>**context</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/templating.html#render_template_string"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.templating.render_template_string" title="Permalink to this definition">¶</a></dt>
  3860. <dd><p>Renders a template from the given template source string
  3861. with the given context. Template variables will be autoescaped.</p>
  3862. <table class="docutils field-list" frame="void" rules="none">
  3863. <col class="field-name" />
  3864. <col class="field-body" />
  3865. <tbody valign="top">
  3866. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  3867. <li><strong>source</strong> &#8211; the source code of the template to be
  3868. rendered</li>
  3869. <li><strong>context</strong> &#8211; the variables that should be available in the
  3870. context of the template.</li>
  3871. </ul>
  3872. </td>
  3873. </tr>
  3874. </tbody>
  3875. </table>
  3876. </dd></dl>
  3877. </div>
  3878. </div>
  3879. <div class="section" id="module-flask.testing">
  3880. <span id="flask-testing-module"></span><h2>flask.testing module<a class="headerlink" href="#module-flask.testing" title="Permalink to this headline">¶</a></h2>
  3881. <div class="section" id="flask-testing">
  3882. <h3>flask.testing<a class="headerlink" href="#flask-testing" title="Permalink to this headline">¶</a></h3>
  3883. <p>Implements test support helpers. This module is lazily imported
  3884. and usually not used in production environments.</p>
  3885. <table class="docutils field-list" frame="void" rules="none">
  3886. <col class="field-name" />
  3887. <col class="field-body" />
  3888. <tbody valign="top">
  3889. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  3890. <li>2015 by Armin Ronacher.</li>
  3891. </ol>
  3892. </td>
  3893. </tr>
  3894. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  3895. </td>
  3896. </tr>
  3897. </tbody>
  3898. </table>
  3899. <dl class="class">
  3900. <dt id="flask.testing.FlaskClient">
  3901. <em class="property">class </em><code class="descclassname">flask.testing.</code><code class="descname">FlaskClient</code><span class="sig-paren">(</span><em>application</em>, <em>response_wrapper=None</em>, <em>use_cookies=True</em>, <em>allow_subdomain_redirects=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/testing.html#FlaskClient"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.testing.FlaskClient" title="Permalink to this definition">¶</a></dt>
  3902. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">werkzeug.test.Client</span></code></p>
  3903. <p>Works like a regular Werkzeug test client but has some knowledge about
  3904. how Flask works to defer the cleanup of the request context stack to the
  3905. end of a <code class="docutils literal"><span class="pre">with</span></code> body when used in a <code class="docutils literal"><span class="pre">with</span></code> statement. For general
  3906. information about how to use this class refer to
  3907. <code class="xref py py-class docutils literal"><span class="pre">werkzeug.test.Client</span></code>.</p>
  3908. <p>Basic usage is outlined in the <span class="xref std std-ref">testing</span> chapter.</p>
  3909. <dl class="method">
  3910. <dt id="flask.testing.FlaskClient.open">
  3911. <code class="descname">open</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/testing.html#FlaskClient.open"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.testing.FlaskClient.open" title="Permalink to this definition">¶</a></dt>
  3912. <dd></dd></dl>
  3913. <dl class="attribute">
  3914. <dt id="flask.testing.FlaskClient.preserve_context">
  3915. <code class="descname">preserve_context</code><em class="property"> = False</em><a class="headerlink" href="#flask.testing.FlaskClient.preserve_context" title="Permalink to this definition">¶</a></dt>
  3916. <dd></dd></dl>
  3917. <dl class="method">
  3918. <dt id="flask.testing.FlaskClient.session_transaction">
  3919. <code class="descname">session_transaction</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/testing.html#FlaskClient.session_transaction"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.testing.FlaskClient.session_transaction" title="Permalink to this definition">¶</a></dt>
  3920. <dd><p>When used in combination with a <code class="docutils literal"><span class="pre">with</span></code> statement this opens a
  3921. session transaction. This can be used to modify the session that
  3922. the test client uses. Once the <code class="docutils literal"><span class="pre">with</span></code> block is left the session is
  3923. stored back.</p>
  3924. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">client</span><span class="o">.</span><span class="n">session_transaction</span><span class="p">()</span> <span class="k">as</span> <span class="n">session</span><span class="p">:</span>
  3925. <span class="n">session</span><span class="p">[</span><span class="s1">&#39;value&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">42</span>
  3926. </pre></div>
  3927. </div>
  3928. <p>Internally this is implemented by going through a temporary test
  3929. request context and since session handling could depend on
  3930. request variables this function accepts the same arguments as
  3931. <code class="xref py py-meth docutils literal"><span class="pre">test_request_context()</span></code> which are directly
  3932. passed through.</p>
  3933. </dd></dl>
  3934. </dd></dl>
  3935. <dl class="function">
  3936. <dt id="flask.testing.make_test_environ_builder">
  3937. <code class="descclassname">flask.testing.</code><code class="descname">make_test_environ_builder</code><span class="sig-paren">(</span><em>app</em>, <em>path='/'</em>, <em>base_url=None</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/testing.html#make_test_environ_builder"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.testing.make_test_environ_builder" title="Permalink to this definition">¶</a></dt>
  3938. <dd><p>Creates a new test builder with some application defaults thrown in.</p>
  3939. </dd></dl>
  3940. </div>
  3941. </div>
  3942. <div class="section" id="module-flask.views">
  3943. <span id="flask-views-module"></span><h2>flask.views module<a class="headerlink" href="#module-flask.views" title="Permalink to this headline">¶</a></h2>
  3944. <div class="section" id="flask-views">
  3945. <h3>flask.views<a class="headerlink" href="#flask-views" title="Permalink to this headline">¶</a></h3>
  3946. <p>This module provides class-based views inspired by the ones in Django.</p>
  3947. <table class="docutils field-list" frame="void" rules="none">
  3948. <col class="field-name" />
  3949. <col class="field-body" />
  3950. <tbody valign="top">
  3951. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  3952. <li>2015 by Armin Ronacher.</li>
  3953. </ol>
  3954. </td>
  3955. </tr>
  3956. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  3957. </td>
  3958. </tr>
  3959. </tbody>
  3960. </table>
  3961. <dl class="class">
  3962. <dt id="flask.views.MethodView">
  3963. <em class="property">class </em><code class="descclassname">flask.views.</code><code class="descname">MethodView</code><a class="reference internal" href="../_modules/flask/views.html#MethodView"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.views.MethodView" title="Permalink to this definition">¶</a></dt>
  3964. <dd><p>Bases: <a class="reference internal" href="#flask.views.View" title="flask.views.View"><code class="xref py py-class docutils literal"><span class="pre">flask.views.View</span></code></a></p>
  3965. <p>Like a regular class-based view but that dispatches requests to
  3966. particular methods. For instance if you implement a method called
  3967. <code class="xref py py-meth docutils literal"><span class="pre">get()</span></code> it means you will response to <code class="docutils literal"><span class="pre">'GET'</span></code> requests and
  3968. the <a class="reference internal" href="#flask.views.MethodView.dispatch_request" title="flask.views.MethodView.dispatch_request"><code class="xref py py-meth docutils literal"><span class="pre">dispatch_request()</span></code></a> implementation will automatically
  3969. forward your request to that. Also <code class="xref py py-attr docutils literal"><span class="pre">options</span></code> is set for you
  3970. automatically:</p>
  3971. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">CounterAPI</span><span class="p">(</span><span class="n">MethodView</span><span class="p">):</span>
  3972. <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  3973. <span class="k">return</span> <span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;counter&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
  3974. <span class="k">def</span> <span class="nf">post</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  3975. <span class="n">session</span><span class="p">[</span><span class="s1">&#39;counter&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;counter&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>
  3976. <span class="k">return</span> <span class="s1">&#39;OK&#39;</span>
  3977. <span class="n">app</span><span class="o">.</span><span class="n">add_url_rule</span><span class="p">(</span><span class="s1">&#39;/counter&#39;</span><span class="p">,</span> <span class="n">view_func</span><span class="o">=</span><span class="n">CounterAPI</span><span class="o">.</span><span class="n">as_view</span><span class="p">(</span><span class="s1">&#39;counter&#39;</span><span class="p">))</span>
  3978. </pre></div>
  3979. </div>
  3980. <dl class="method">
  3981. <dt id="flask.views.MethodView.dispatch_request">
  3982. <code class="descname">dispatch_request</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/views.html#MethodView.dispatch_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.views.MethodView.dispatch_request" title="Permalink to this definition">¶</a></dt>
  3983. <dd></dd></dl>
  3984. </dd></dl>
  3985. <dl class="class">
  3986. <dt id="flask.views.MethodViewType">
  3987. <em class="property">class </em><code class="descclassname">flask.views.</code><code class="descname">MethodViewType</code><a class="reference internal" href="../_modules/flask/views.html#MethodViewType"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.views.MethodViewType" title="Permalink to this definition">¶</a></dt>
  3988. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">type</span></code></p>
  3989. </dd></dl>
  3990. <dl class="class">
  3991. <dt id="flask.views.View">
  3992. <em class="property">class </em><code class="descclassname">flask.views.</code><code class="descname">View</code><a class="reference internal" href="../_modules/flask/views.html#View"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.views.View" title="Permalink to this definition">¶</a></dt>
  3993. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
  3994. <p>Alternative way to use view functions. A subclass has to implement
  3995. <a class="reference internal" href="#flask.views.View.dispatch_request" title="flask.views.View.dispatch_request"><code class="xref py py-meth docutils literal"><span class="pre">dispatch_request()</span></code></a> which is called with the view arguments from
  3996. the URL routing system. If <a class="reference internal" href="#flask.views.View.methods" title="flask.views.View.methods"><code class="xref py py-attr docutils literal"><span class="pre">methods</span></code></a> is provided the methods
  3997. do not have to be passed to the <code class="xref py py-meth docutils literal"><span class="pre">add_url_rule()</span></code>
  3998. method explicitly:</p>
  3999. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyView</span><span class="p">(</span><span class="n">View</span><span class="p">):</span>
  4000. <span class="n">methods</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;GET&#39;</span><span class="p">]</span>
  4001. <span class="k">def</span> <span class="nf">dispatch_request</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
  4002. <span class="k">return</span> <span class="s1">&#39;Hello </span><span class="si">%s</span><span class="s1">!&#39;</span> <span class="o">%</span> <span class="n">name</span>
  4003. <span class="n">app</span><span class="o">.</span><span class="n">add_url_rule</span><span class="p">(</span><span class="s1">&#39;/hello/&lt;name&gt;&#39;</span><span class="p">,</span> <span class="n">view_func</span><span class="o">=</span><span class="n">MyView</span><span class="o">.</span><span class="n">as_view</span><span class="p">(</span><span class="s1">&#39;myview&#39;</span><span class="p">))</span>
  4004. </pre></div>
  4005. </div>
  4006. <p>When you want to decorate a pluggable view you will have to either do that
  4007. when the view function is created (by wrapping the return value of
  4008. <a class="reference internal" href="#flask.views.View.as_view" title="flask.views.View.as_view"><code class="xref py py-meth docutils literal"><span class="pre">as_view()</span></code></a>) or you can use the <a class="reference internal" href="#flask.views.View.decorators" title="flask.views.View.decorators"><code class="xref py py-attr docutils literal"><span class="pre">decorators</span></code></a> attribute:</p>
  4009. <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">SecretView</span><span class="p">(</span><span class="n">View</span><span class="p">):</span>
  4010. <span class="n">methods</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;GET&#39;</span><span class="p">]</span>
  4011. <span class="n">decorators</span> <span class="o">=</span> <span class="p">[</span><span class="n">superuser_required</span><span class="p">]</span>
  4012. <span class="k">def</span> <span class="nf">dispatch_request</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  4013. <span class="o">...</span>
  4014. </pre></div>
  4015. </div>
  4016. <p>The decorators stored in the decorators list are applied one after another
  4017. when the view function is created. Note that you can <em>not</em> use the class
  4018. based decorators since those would decorate the view class and not the
  4019. generated view function!</p>
  4020. <dl class="classmethod">
  4021. <dt id="flask.views.View.as_view">
  4022. <em class="property">classmethod </em><code class="descname">as_view</code><span class="sig-paren">(</span><em>name</em>, <em>*class_args</em>, <em>**class_kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/views.html#View.as_view"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.views.View.as_view" title="Permalink to this definition">¶</a></dt>
  4023. <dd><p>Converts the class into an actual view function that can be used
  4024. with the routing system. Internally this generates a function on the
  4025. fly which will instantiate the <a class="reference internal" href="#flask.views.View" title="flask.views.View"><code class="xref py py-class docutils literal"><span class="pre">View</span></code></a> on each request and call
  4026. the <a class="reference internal" href="#flask.views.View.dispatch_request" title="flask.views.View.dispatch_request"><code class="xref py py-meth docutils literal"><span class="pre">dispatch_request()</span></code></a> method on it.</p>
  4027. <p>The arguments passed to <a class="reference internal" href="#flask.views.View.as_view" title="flask.views.View.as_view"><code class="xref py py-meth docutils literal"><span class="pre">as_view()</span></code></a> are forwarded to the
  4028. constructor of the class.</p>
  4029. </dd></dl>
  4030. <dl class="attribute">
  4031. <dt id="flask.views.View.decorators">
  4032. <code class="descname">decorators</code><em class="property"> = ()</em><a class="headerlink" href="#flask.views.View.decorators" title="Permalink to this definition">¶</a></dt>
  4033. <dd><p>The canonical way to decorate class-based views is to decorate the
  4034. return value of as_view(). However since this moves parts of the
  4035. logic from the class declaration to the place where it&#8217;s hooked
  4036. into the routing system.</p>
  4037. <p>You can place one or more decorators in this list and whenever the
  4038. view function is created the result is automatically decorated.</p>
  4039. <div class="versionadded">
  4040. <p><span class="versionmodified">New in version 0.8.</span></p>
  4041. </div>
  4042. </dd></dl>
  4043. <dl class="method">
  4044. <dt id="flask.views.View.dispatch_request">
  4045. <code class="descname">dispatch_request</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/views.html#View.dispatch_request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.views.View.dispatch_request" title="Permalink to this definition">¶</a></dt>
  4046. <dd><p>Subclasses have to override this method to implement the
  4047. actual view function code. This method is called with all
  4048. the arguments from the URL rule.</p>
  4049. </dd></dl>
  4050. <dl class="attribute">
  4051. <dt id="flask.views.View.methods">
  4052. <code class="descname">methods</code><em class="property"> = None</em><a class="headerlink" href="#flask.views.View.methods" title="Permalink to this definition">¶</a></dt>
  4053. <dd><p>A list of methods this view can handle.</p>
  4054. </dd></dl>
  4055. </dd></dl>
  4056. </div>
  4057. </div>
  4058. <div class="section" id="module-flask.wrappers">
  4059. <span id="flask-wrappers-module"></span><h2>flask.wrappers module<a class="headerlink" href="#module-flask.wrappers" title="Permalink to this headline">¶</a></h2>
  4060. <div class="section" id="flask-wrappers">
  4061. <h3>flask.wrappers<a class="headerlink" href="#flask-wrappers" title="Permalink to this headline">¶</a></h3>
  4062. <p>Implements the WSGI wrappers (request and response).</p>
  4063. <table class="docutils field-list" frame="void" rules="none">
  4064. <col class="field-name" />
  4065. <col class="field-body" />
  4066. <tbody valign="top">
  4067. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  4068. <li>2015 by Armin Ronacher.</li>
  4069. </ol>
  4070. </td>
  4071. </tr>
  4072. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  4073. </td>
  4074. </tr>
  4075. </tbody>
  4076. </table>
  4077. <dl class="class">
  4078. <dt id="flask.wrappers.Request">
  4079. <em class="property">class </em><code class="descclassname">flask.wrappers.</code><code class="descname">Request</code><span class="sig-paren">(</span><em>environ</em>, <em>populate_request=True</em>, <em>shallow=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/wrappers.html#Request"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.wrappers.Request" title="Permalink to this definition">¶</a></dt>
  4080. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">werkzeug.wrappers.Request</span></code></p>
  4081. <p>The request object used by default in Flask. Remembers the
  4082. matched endpoint and view arguments.</p>
  4083. <p>It is what ends up as <code class="xref py py-class docutils literal"><span class="pre">request</span></code>. If you want to replace
  4084. the request object used you can subclass this and set
  4085. <code class="xref py py-attr docutils literal"><span class="pre">request_class</span></code> to your subclass.</p>
  4086. <p>The request object is a <code class="xref py py-class docutils literal"><span class="pre">Request</span></code> subclass and
  4087. provides all of the attributes Werkzeug defines plus a few Flask
  4088. specific ones.</p>
  4089. <dl class="attribute">
  4090. <dt id="flask.wrappers.Request.blueprint">
  4091. <code class="descname">blueprint</code><a class="headerlink" href="#flask.wrappers.Request.blueprint" title="Permalink to this definition">¶</a></dt>
  4092. <dd><p>The name of the current blueprint</p>
  4093. </dd></dl>
  4094. <dl class="attribute">
  4095. <dt id="flask.wrappers.Request.endpoint">
  4096. <code class="descname">endpoint</code><a class="headerlink" href="#flask.wrappers.Request.endpoint" title="Permalink to this definition">¶</a></dt>
  4097. <dd><p>The endpoint that matched the request. This in combination with
  4098. <a class="reference internal" href="#flask.wrappers.Request.view_args" title="flask.wrappers.Request.view_args"><code class="xref py py-attr docutils literal"><span class="pre">view_args</span></code></a> can be used to reconstruct the same or a
  4099. modified URL. If an exception happened when matching, this will
  4100. be <code class="docutils literal"><span class="pre">None</span></code>.</p>
  4101. </dd></dl>
  4102. <dl class="method">
  4103. <dt id="flask.wrappers.Request.get_json">
  4104. <code class="descname">get_json</code><span class="sig-paren">(</span><em>force=False</em>, <em>silent=False</em>, <em>cache=True</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/wrappers.html#Request.get_json"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.wrappers.Request.get_json" title="Permalink to this definition">¶</a></dt>
  4105. <dd><p>Parses the incoming JSON request data and returns it. By default
  4106. this function will return <code class="docutils literal"><span class="pre">None</span></code> if the mimetype is not
  4107. <em class="mimetype">application/json</em> but this can be overridden by the
  4108. <code class="docutils literal"><span class="pre">force</span></code> parameter. If parsing fails the
  4109. <a class="reference internal" href="#flask.wrappers.Request.on_json_loading_failed" title="flask.wrappers.Request.on_json_loading_failed"><code class="xref py py-meth docutils literal"><span class="pre">on_json_loading_failed()</span></code></a> method on the request object will be
  4110. invoked.</p>
  4111. <table class="docutils field-list" frame="void" rules="none">
  4112. <col class="field-name" />
  4113. <col class="field-body" />
  4114. <tbody valign="top">
  4115. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  4116. <li><strong>force</strong> &#8211; if set to <code class="docutils literal"><span class="pre">True</span></code> the mimetype is ignored.</li>
  4117. <li><strong>silent</strong> &#8211; if set to <code class="docutils literal"><span class="pre">True</span></code> this method will fail silently
  4118. and return <code class="docutils literal"><span class="pre">None</span></code>.</li>
  4119. <li><strong>cache</strong> &#8211; if set to <code class="docutils literal"><span class="pre">True</span></code> the parsed JSON data is remembered
  4120. on the request.</li>
  4121. </ul>
  4122. </td>
  4123. </tr>
  4124. </tbody>
  4125. </table>
  4126. </dd></dl>
  4127. <dl class="attribute">
  4128. <dt id="flask.wrappers.Request.is_json">
  4129. <code class="descname">is_json</code><a class="headerlink" href="#flask.wrappers.Request.is_json" title="Permalink to this definition">¶</a></dt>
  4130. <dd><p>Indicates if this request is JSON or not. By default a request
  4131. is considered to include JSON data if the mimetype is
  4132. <em class="mimetype">application/json</em> or <em class="mimetype">application/*+json</em>.</p>
  4133. <div class="versionadded">
  4134. <p><span class="versionmodified">New in version 0.11.</span></p>
  4135. </div>
  4136. </dd></dl>
  4137. <dl class="attribute">
  4138. <dt id="flask.wrappers.Request.json">
  4139. <code class="descname">json</code><a class="headerlink" href="#flask.wrappers.Request.json" title="Permalink to this definition">¶</a></dt>
  4140. <dd><p>If the mimetype is <em class="mimetype">application/json</em> this will contain the
  4141. parsed JSON data. Otherwise this will be <code class="docutils literal"><span class="pre">None</span></code>.</p>
  4142. <p>The <a class="reference internal" href="#flask.wrappers.Request.get_json" title="flask.wrappers.Request.get_json"><code class="xref py py-meth docutils literal"><span class="pre">get_json()</span></code></a> method should be used instead.</p>
  4143. </dd></dl>
  4144. <dl class="attribute">
  4145. <dt id="flask.wrappers.Request.max_content_length">
  4146. <code class="descname">max_content_length</code><a class="headerlink" href="#flask.wrappers.Request.max_content_length" title="Permalink to this definition">¶</a></dt>
  4147. <dd><p>Read-only view of the <code class="docutils literal"><span class="pre">MAX_CONTENT_LENGTH</span></code> config key.</p>
  4148. </dd></dl>
  4149. <dl class="attribute">
  4150. <dt id="flask.wrappers.Request.module">
  4151. <code class="descname">module</code><a class="headerlink" href="#flask.wrappers.Request.module" title="Permalink to this definition">¶</a></dt>
  4152. <dd><p>The name of the current module if the request was dispatched
  4153. to an actual module. This is deprecated functionality, use blueprints
  4154. instead.</p>
  4155. </dd></dl>
  4156. <dl class="method">
  4157. <dt id="flask.wrappers.Request.on_json_loading_failed">
  4158. <code class="descname">on_json_loading_failed</code><span class="sig-paren">(</span><em>e</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/wrappers.html#Request.on_json_loading_failed"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.wrappers.Request.on_json_loading_failed" title="Permalink to this definition">¶</a></dt>
  4159. <dd><p>Called if decoding of the JSON data failed. The return value of
  4160. this method is used by <a class="reference internal" href="#flask.wrappers.Request.get_json" title="flask.wrappers.Request.get_json"><code class="xref py py-meth docutils literal"><span class="pre">get_json()</span></code></a> when an error occurred. The
  4161. default implementation just raises a <code class="xref py py-class docutils literal"><span class="pre">BadRequest</span></code> exception.</p>
  4162. <div class="versionchanged">
  4163. <p><span class="versionmodified">Changed in version 0.10: </span>Removed buggy previous behavior of generating a random JSON
  4164. response. If you want that behavior back you can trivially
  4165. add it by subclassing.</p>
  4166. </div>
  4167. <div class="versionadded">
  4168. <p><span class="versionmodified">New in version 0.8.</span></p>
  4169. </div>
  4170. </dd></dl>
  4171. <dl class="attribute">
  4172. <dt id="flask.wrappers.Request.routing_exception">
  4173. <code class="descname">routing_exception</code><em class="property"> = None</em><a class="headerlink" href="#flask.wrappers.Request.routing_exception" title="Permalink to this definition">¶</a></dt>
  4174. <dd><p>If matching the URL failed, this is the exception that will be
  4175. raised / was raised as part of the request handling. This is
  4176. usually a <code class="xref py py-exc docutils literal"><span class="pre">NotFound</span></code> exception or
  4177. something similar.</p>
  4178. </dd></dl>
  4179. <dl class="attribute">
  4180. <dt id="flask.wrappers.Request.url_rule">
  4181. <code class="descname">url_rule</code><em class="property"> = None</em><a class="headerlink" href="#flask.wrappers.Request.url_rule" title="Permalink to this definition">¶</a></dt>
  4182. <dd><p>The internal URL rule that matched the request. This can be
  4183. useful to inspect which methods are allowed for the URL from
  4184. a before/after handler (<code class="docutils literal"><span class="pre">request.url_rule.methods</span></code>) etc.</p>
  4185. <div class="versionadded">
  4186. <p><span class="versionmodified">New in version 0.6.</span></p>
  4187. </div>
  4188. </dd></dl>
  4189. <dl class="attribute">
  4190. <dt id="flask.wrappers.Request.view_args">
  4191. <code class="descname">view_args</code><em class="property"> = None</em><a class="headerlink" href="#flask.wrappers.Request.view_args" title="Permalink to this definition">¶</a></dt>
  4192. <dd><p>A dict of view arguments that matched the request. If an exception
  4193. happened when matching, this will be <code class="docutils literal"><span class="pre">None</span></code>.</p>
  4194. </dd></dl>
  4195. </dd></dl>
  4196. <dl class="class">
  4197. <dt id="flask.wrappers.Response">
  4198. <em class="property">class </em><code class="descclassname">flask.wrappers.</code><code class="descname">Response</code><span class="sig-paren">(</span><em>response=None</em>, <em>status=None</em>, <em>headers=None</em>, <em>mimetype=None</em>, <em>content_type=None</em>, <em>direct_passthrough=False</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/flask/wrappers.html#Response"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#flask.wrappers.Response" title="Permalink to this definition">¶</a></dt>
  4199. <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">werkzeug.wrappers.Response</span></code></p>
  4200. <p>The response object that is used by default in Flask. Works like the
  4201. response object from Werkzeug but is set to have an HTML mimetype by
  4202. default. Quite often you don&#8217;t have to create this object yourself because
  4203. <code class="xref py py-meth docutils literal"><span class="pre">make_response()</span></code> will take care of that for you.</p>
  4204. <p>If you want to replace the response object used you can subclass this and
  4205. set <code class="xref py py-attr docutils literal"><span class="pre">response_class</span></code> to your subclass.</p>
  4206. <dl class="attribute">
  4207. <dt id="flask.wrappers.Response.default_mimetype">
  4208. <code class="descname">default_mimetype</code><em class="property"> = 'text/html'</em><a class="headerlink" href="#flask.wrappers.Response.default_mimetype" title="Permalink to this definition">¶</a></dt>
  4209. <dd></dd></dl>
  4210. </dd></dl>
  4211. </div>
  4212. </div>
  4213. <div class="section" id="module-flask">
  4214. <span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-flask" title="Permalink to this headline">¶</a></h2>
  4215. <div class="section" id="flask">
  4216. <h3>flask<a class="headerlink" href="#flask" title="Permalink to this headline">¶</a></h3>
  4217. <p>A microframework based on Werkzeug. It&#8217;s extensively documented
  4218. and follows best practice patterns.</p>
  4219. <table class="docutils field-list" frame="void" rules="none">
  4220. <col class="field-name" />
  4221. <col class="field-body" />
  4222. <tbody valign="top">
  4223. <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
  4224. <li>2015 by Armin Ronacher.</li>
  4225. </ol>
  4226. </td>
  4227. </tr>
  4228. <tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first last">BSD, see LICENSE for more details.</p>
  4229. </td>
  4230. </tr>
  4231. </tbody>
  4232. </table>
  4233. </div>
  4234. </div>
  4235. </div>
  4236. </div>
  4237. </div>
  4238. </div>
  4239. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  4240. <div class="sphinxsidebarwrapper">
  4241. <h3><a href="../index.html">Table Of Contents</a></h3>
  4242. <ul>
  4243. <li><a class="reference internal" href="#">flask package</a><ul>
  4244. <li><a class="reference internal" href="#subpackages">Subpackages</a></li>
  4245. <li><a class="reference internal" href="#submodules">Submodules</a></li>
  4246. <li><a class="reference internal" href="#module-flask.app">flask.app module</a><ul>
  4247. <li><a class="reference internal" href="#flask-app">flask.app</a></li>
  4248. </ul>
  4249. </li>
  4250. <li><a class="reference internal" href="#module-flask.blueprints">flask.blueprints module</a><ul>
  4251. <li><a class="reference internal" href="#flask-blueprints">flask.blueprints</a></li>
  4252. </ul>
  4253. </li>
  4254. <li><a class="reference internal" href="#module-flask.cli">flask.cli module</a><ul>
  4255. <li><a class="reference internal" href="#flask-cli">flask.cli</a></li>
  4256. </ul>
  4257. </li>
  4258. <li><a class="reference internal" href="#module-flask.config">flask.config module</a><ul>
  4259. <li><a class="reference internal" href="#flask-config">flask.config</a></li>
  4260. </ul>
  4261. </li>
  4262. <li><a class="reference internal" href="#module-flask.ctx">flask.ctx module</a><ul>
  4263. <li><a class="reference internal" href="#flask-ctx">flask.ctx</a></li>
  4264. </ul>
  4265. </li>
  4266. <li><a class="reference internal" href="#module-flask.debughelpers">flask.debughelpers module</a><ul>
  4267. <li><a class="reference internal" href="#flask-debughelpers">flask.debughelpers</a></li>
  4268. </ul>
  4269. </li>
  4270. <li><a class="reference internal" href="#module-flask.exthook">flask.exthook module</a><ul>
  4271. <li><a class="reference internal" href="#flask-exthook">flask.exthook</a></li>
  4272. </ul>
  4273. </li>
  4274. <li><a class="reference internal" href="#module-flask.globals">flask.globals module</a><ul>
  4275. <li><a class="reference internal" href="#flask-globals">flask.globals</a></li>
  4276. </ul>
  4277. </li>
  4278. <li><a class="reference internal" href="#module-flask.helpers">flask.helpers module</a><ul>
  4279. <li><a class="reference internal" href="#flask-helpers">flask.helpers</a></li>
  4280. </ul>
  4281. </li>
  4282. <li><a class="reference internal" href="#module-flask.json">flask.json module</a><ul>
  4283. <li><a class="reference internal" href="#flask-jsonimpl">flask.jsonimpl</a></li>
  4284. </ul>
  4285. </li>
  4286. <li><a class="reference internal" href="#module-flask.logging">flask.logging module</a><ul>
  4287. <li><a class="reference internal" href="#flask-logging">flask.logging</a></li>
  4288. </ul>
  4289. </li>
  4290. <li><a class="reference internal" href="#module-flask.sessions">flask.sessions module</a><ul>
  4291. <li><a class="reference internal" href="#flask-sessions">flask.sessions</a></li>
  4292. </ul>
  4293. </li>
  4294. <li><a class="reference internal" href="#module-flask.signals">flask.signals module</a><ul>
  4295. <li><a class="reference internal" href="#flask-signals">flask.signals</a></li>
  4296. </ul>
  4297. </li>
  4298. <li><a class="reference internal" href="#module-flask.templating">flask.templating module</a><ul>
  4299. <li><a class="reference internal" href="#flask-templating">flask.templating</a></li>
  4300. </ul>
  4301. </li>
  4302. <li><a class="reference internal" href="#module-flask.testing">flask.testing module</a><ul>
  4303. <li><a class="reference internal" href="#flask-testing">flask.testing</a></li>
  4304. </ul>
  4305. </li>
  4306. <li><a class="reference internal" href="#module-flask.views">flask.views module</a><ul>
  4307. <li><a class="reference internal" href="#flask-views">flask.views</a></li>
  4308. </ul>
  4309. </li>
  4310. <li><a class="reference internal" href="#module-flask.wrappers">flask.wrappers module</a><ul>
  4311. <li><a class="reference internal" href="#flask-wrappers">flask.wrappers</a></li>
  4312. </ul>
  4313. </li>
  4314. <li><a class="reference internal" href="#module-flask">Module contents</a><ul>
  4315. <li><a class="reference internal" href="#flask">flask</a></li>
  4316. </ul>
  4317. </li>
  4318. </ul>
  4319. </li>
  4320. </ul>
  4321. <div class="relations">
  4322. <h3>Related Topics</h3>
  4323. <ul>
  4324. <li><a href="../index.html">Documentation overview</a><ul>
  4325. </ul></li>
  4326. </ul>
  4327. </div>
  4328. <div role="note" aria-label="source link">
  4329. <h3>This Page</h3>
  4330. <ul class="this-page-menu">
  4331. <li><a href="../_sources/flask/flask.txt"
  4332. rel="nofollow">Show Source</a></li>
  4333. </ul>
  4334. </div>
  4335. <div id="searchbox" style="display: none" role="search">
  4336. <h3>Quick search</h3>
  4337. <form class="search" action="../search.html" method="get">
  4338. <div><input type="text" name="q" /></div>
  4339. <div><input type="submit" value="Go" /></div>
  4340. <input type="hidden" name="check_keywords" value="yes" />
  4341. <input type="hidden" name="area" value="default" />
  4342. </form>
  4343. </div>
  4344. <script type="text/javascript">$('#searchbox').show(0);</script>
  4345. </div>
  4346. </div>
  4347. <div class="clearer"></div>
  4348. </div>
  4349. <div class="footer">
  4350. &copy;2016, Author.
  4351. |
  4352. Powered by <a href="http://sphinx-doc.org/">Sphinx 1.4.8</a>
  4353. &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.9</a>
  4354. |
  4355. <a href="../_sources/flask/flask.txt"
  4356. rel="nofollow">Page source</a>
  4357. </div>
  4358. </body>
  4359. </html>