| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-
- <title>flask package — proxypool documentation</title>
-
- <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
- <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
-
- <script type="text/javascript">
- var DOCUMENTATION_OPTIONS = {
- URL_ROOT: '../',
- VERSION: '',
- COLLAPSE_INDEX: false,
- FILE_SUFFIX: '.html',
- HAS_SOURCE: true
- };
- </script>
- <script type="text/javascript" src="../_static/jquery.js"></script>
- <script type="text/javascript" src="../_static/underscore.js"></script>
- <script type="text/javascript" src="../_static/doctools.js"></script>
- <link rel="index" title="Index" href="../genindex.html" />
- <link rel="search" title="Search" href="../search.html" />
- <link rel="top" title="proxypool documentation" href="../index.html" />
-
- <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
-
-
- <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
- </head>
- <body role="document">
-
- <div class="document">
- <div class="documentwrapper">
- <div class="bodywrapper">
- <div class="body" role="main">
-
- <div class="section" id="flask-package">
- <h1>flask package<a class="headerlink" href="#flask-package" title="Permalink to this headline">¶</a></h1>
- <div class="section" id="subpackages">
- <h2>Subpackages<a class="headerlink" href="#subpackages" title="Permalink to this headline">¶</a></h2>
- <div class="toctree-wrapper compound">
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="flask.ext.html">flask.ext package</a><ul>
- <li class="toctree-l2"><a class="reference internal" href="flask.ext.html#module-flask.ext">Module contents</a><ul>
- <li class="toctree-l3"><a class="reference internal" href="flask.ext.html#flask-ext">flask.ext</a></li>
- </ul>
- </li>
- </ul>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" id="submodules">
- <h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this headline">¶</a></h2>
- </div>
- <div class="section" id="module-flask.app">
- <span id="flask-app-module"></span><h2>flask.app module<a class="headerlink" href="#module-flask.app" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-app">
- <h3>flask.app<a class="headerlink" href="#flask-app" title="Permalink to this headline">¶</a></h3>
- <p>This module implements the central WSGI application object.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="class">
- <dt id="flask.app.Flask">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">flask.helpers._PackageBoundObject</span></code></p>
- <p>The flask object implements a WSGI application and acts as the central
- object. It is passed the name of the module or package of the
- application. Once it is created it will act as a central registry for
- the view functions, the URL rules, template configuration and much more.</p>
- <p>The name of the package is used to resolve resources from inside the
- package or the folder the module is contained in depending on if the
- package parameter resolves to an actual python package (a folder with
- 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>
- <p>For more information about resource loading, see <code class="xref py py-func docutils literal"><span class="pre">open_resource()</span></code>.</p>
- <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
- in the <code class="file docutils literal"><span class="pre">__init__.py</span></code> file of your package like this:</p>
- <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>
- <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>
- </pre></div>
- </div>
- <div class="admonition-about-the-first-parameter admonition">
- <p class="first admonition-title">About the First Parameter</p>
- <p>The idea of the first parameter is to give Flask an idea of what
- belongs to your application. This name is used to find resources
- on the filesystem, can be used by extensions to improve debugging
- information and a lot more.</p>
- <p>So it’s important what you provide there. If you are using a single
- module, <cite>__name__</cite> is always the correct value. If you however are
- using a package, it’s usually recommended to hardcode the name of
- your package there.</p>
- <p>For example if your application is defined in <code class="file docutils literal"><span class="pre">yourapplication/app.py</span></code>
- you should create it with one of the two versions below:</p>
- <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">'yourapplication'</span><span class="p">)</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="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">'.'</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
- </pre></div>
- </div>
- <p class="last">Why is that? The application will work even with <cite>__name__</cite>, thanks
- to how resources are looked up. However it will make debugging more
- painful. Certain extensions can make assumptions based on the
- import name of your application. For example the Flask-SQLAlchemy
- extension will look for the code in your application that triggered
- an SQL query in debug mode. If the import name is not properly set
- up, that debugging information is lost. (For example it would only
- pick up SQL queries in <cite>yourapplication.app</cite> and not
- <cite>yourapplication.views.frontend</cite>)</p>
- </div>
- <div class="versionadded">
- <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>
- parameters were added.</p>
- </div>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.8: </span>The <cite>instance_path</cite> and <cite>instance_relative_config</cite> parameters were
- added.</p>
- </div>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.11: </span>The <cite>root_path</cite> parameter was added.</p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>import_name</strong> – the name of the application package</li>
- <li><strong>static_url_path</strong> – can be used to specify a different path for the
- static files on the web. Defaults to the name
- of the <cite>static_folder</cite> folder.</li>
- <li><strong>static_folder</strong> – the folder with static files that should be served
- at <cite>static_url_path</cite>. Defaults to the <code class="docutils literal"><span class="pre">'static'</span></code>
- folder in the root path of the application.</li>
- <li><strong>template_folder</strong> – the folder that contains the templates that should
- be used by the application. Defaults to
- <code class="docutils literal"><span class="pre">'templates'</span></code> folder in the root path of the
- application.</li>
- <li><strong>instance_path</strong> – An alternative instance path for the application.
- By default the folder <code class="docutils literal"><span class="pre">'instance'</span></code> next to the
- package or module is assumed to be the instance
- path.</li>
- <li><strong>instance_relative_config</strong> – if set to <code class="docutils literal"><span class="pre">True</span></code> relative filenames
- for loading the config are assumed to
- be relative to the instance path instead
- of the application root.</li>
- <li><strong>root_path</strong> – Flask by default will automatically calculate the path
- to the root of the application. In certain situations
- this cannot be achieved (for instance if the package
- is a Python 3 namespace package) and needs to be
- manually defined.</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="method">
- <dt id="flask.app.Flask.add_template_filter">
- <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>
- <dd><p>Register a custom template filter. Works exactly like the
- <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>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> – the optional name of the filter, otherwise the
- function name will be used.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.add_template_global">
- <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>
- <dd><p>Register a custom template global function. Works exactly like the
- <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>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.10.</span></p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> – the optional name of the global function, otherwise the
- function name will be used.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.add_template_test">
- <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>
- <dd><p>Register a custom template test. Works exactly like the
- <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>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.10.</span></p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> – the optional name of the test, otherwise the
- function name will be used.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.add_url_rule">
- <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>
- <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>
- decorator. If a view_func is provided it will be registered with the
- endpoint.</p>
- <p>Basically this example:</p>
- <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">'/'</span><span class="p">)</span>
- <span class="k">def</span> <span class="nf">index</span><span class="p">():</span>
- <span class="k">pass</span>
- </pre></div>
- </div>
- <p>Is equivalent to the following:</p>
- <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">index</span><span class="p">():</span>
- <span class="k">pass</span>
- <span class="n">app</span><span class="o">.</span><span class="n">add_url_rule</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,</span> <span class="s1">'index'</span><span class="p">,</span> <span class="n">index</span><span class="p">)</span>
- </pre></div>
- </div>
- <p>If the view_func is not provided you will need to connect the endpoint
- to a view function like so:</p>
- <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">'index'</span><span class="p">]</span> <span class="o">=</span> <span class="n">index</span>
- </pre></div>
- </div>
- <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
- to customize the behavior via subclassing you only need to change
- this method.</p>
- <p>For more information refer to <span class="xref std std-ref">url-route-registrations</span>.</p>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.2: </span><cite>view_func</cite> parameter added.</p>
- </div>
- <div class="versionchanged">
- <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>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>rule</strong> – the URL rule as string</li>
- <li><strong>endpoint</strong> – the endpoint for the registered URL rule. Flask
- itself assumes the name of the view function as
- endpoint</li>
- <li><strong>view_func</strong> – the function to call when serving a request to the
- provided endpoint</li>
- <li><strong>options</strong> – the options to be forwarded to the underlying
- <code class="xref py py-class docutils literal"><span class="pre">Rule</span></code> object. A change
- to Werkzeug is handling of method options. methods
- is a list of methods this rule should be limited
- 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
- 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>).
- Starting with Flask 0.6, <code class="docutils literal"><span class="pre">OPTIONS</span></code> is implicitly
- added and handled by the standard request handling.</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.after_request">
- <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>
- <dd><p>Register a function to be run after each request.</p>
- <p>Your function must take one parameter, 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> and return a new response object or the
- 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>
- <p>As of Flask 0.7 this function might not be executed at the end of the
- request in case an unhandled exception occurred.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.after_request_funcs">
- <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>
- <dd><p>A dictionary with lists of functions that should be called after
- each request. The key of the dictionary is the name of the blueprint
- this function is active for, <code class="docutils literal"><span class="pre">None</span></code> for all requests. This can for
- example be used to close database connections. To register a function
- 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>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.app_context">
- <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>
- <dd><p>Binds the application only. For as long as the application is bound
- to the current context the <code class="xref py py-data docutils literal"><span class="pre">flask.current_app</span></code> points to that
- application. An application context is automatically created when a
- request context is pushed if necessary.</p>
- <p>Example usage:</p>
- <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>
- <span class="o">...</span>
- </pre></div>
- </div>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.9.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.app_ctx_globals_class">
- <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>
- <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>
- <p>Example use cases for a custom class:</p>
- <ol class="arabic simple">
- <li>Store arbitrary attributes on flask.g.</li>
- <li>Add a property for lazy per-request database connectors.</li>
- <li>Return None instead of AttributeError on unexpected attributes.</li>
- <li>Raise exception if an unexpected attr is set, a “controlled” flask.g.</li>
- </ol>
- <p>In Flask 0.9 this property was called <cite>request_globals_class</cite> but it
- 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
- flask.g object is now application context scoped.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.10.</span></p>
- </div>
- <p>alias of <code class="xref py py-class docutils literal"><span class="pre">_AppCtxGlobals</span></code></p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.auto_find_instance_path">
- <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>
- <dd><p>Tries to locate the instance path if it was not provided to the
- constructor of the application class. It will basically calculate
- the path to a folder named <code class="docutils literal"><span class="pre">instance</span></code> next to your main file or
- the package.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.8.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.before_first_request">
- <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>
- <dd><p>Registers a function to be run before the first request to this
- instance of the application.</p>
- <p>The function will be called without any arguments and its return
- value is ignored.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.8.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.before_first_request_funcs">
- <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>
- <dd><p>A lists of functions that should be called at the beginning of the
- first request to this instance. To register a function here, use
- 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>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.8.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.before_request">
- <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>
- <dd><p>Registers a function to run before each request.</p>
- <p>The function will be called without any arguments.
- If the function returns a non-None value, it’s handled as
- if it was the return value from the view and further
- request handling is stopped.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.before_request_funcs">
- <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>
- <dd><p>A dictionary with lists of functions that should be called at the
- beginning of the request. The key of the dictionary is the name of
- the blueprint this function is active for, <code class="docutils literal"><span class="pre">None</span></code> for all requests.
- This can for example be used to open database connections or
- getting hold of the currently logged in user. To register a
- 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>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.blueprints">
- <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>
- <dd><p>all the attached blueprints in a dictionary by name. Blueprints
- can be attached multiple times so this dictionary does not tell
- you how often they got attached.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.cli">
- <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>
- <dd><p>The click command line context for this application. Commands
- registered here show up in the <strong class="command">flask</strong> command once the
- application has been discovered. The default commands are
- provided by Flask itself and can be overridden.</p>
- <p>This is an instance of a <code class="xref py py-class docutils literal"><span class="pre">click.Group</span></code> object.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.config">
- <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>
- <dd><p>The configuration dictionary as <code class="xref py py-class docutils literal"><span class="pre">Config</span></code>. This behaves
- exactly like a regular dictionary but supports additional methods
- to load a config from files.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.config_class">
- <code class="descname">config_class</code><a class="headerlink" href="#flask.app.Flask.config_class" title="Permalink to this definition">¶</a></dt>
- <dd><p>The class that is used for the <code class="docutils literal"><span class="pre">config</span></code> attribute of this app.
- Defaults to <code class="xref py py-class docutils literal"><span class="pre">Config</span></code>.</p>
- <p>Example use cases for a custom class:</p>
- <ol class="arabic simple">
- <li>Default values for certain config options.</li>
- <li>Access to config values through attributes in addition to keys.</li>
- </ol>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.11.</span></p>
- </div>
- <p>alias of <code class="xref py py-class docutils literal"><span class="pre">Config</span></code></p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.context_processor">
- <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>
- <dd><p>Registers a template context processor function.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.create_global_jinja_loader">
- <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>
- <dd><p>Creates the loader for the Jinja2 environment. Can be used to
- override just the loader and keeping the rest unchanged. It’s
- discouraged to override this function. Instead one should override
- the <code class="xref py py-meth docutils literal"><span class="pre">jinja_loader()</span></code> function instead.</p>
- <p>The global loader dispatches between the loaders of the application
- and the individual blueprints.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.create_jinja_environment">
- <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>
- <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>
- 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
- the Jinja2 globals and filters after initialization. Override
- this function to customize the behavior.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.5.</span></p>
- </div>
- <div class="versionchanged">
- <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
- <code class="docutils literal"><span class="pre">TEMPLATES_AUTO_RELOAD</span></code> configuration option.</p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.create_url_adapter">
- <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>
- <dd><p>Creates a URL adapter for the given request. The URL adapter
- is created at a point where the request context is not yet set up
- so the request is passed explicitly.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.6.</span></p>
- </div>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.9: </span>This can now also be called without a request object when the
- URL adapter is created for the application context.</p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.debug">
- <code class="descname">debug</code><a class="headerlink" href="#flask.app.Flask.debug" title="Permalink to this definition">¶</a></dt>
- <dd><p>The debug flag. Set this to <code class="docutils literal"><span class="pre">True</span></code> to enable debugging of the
- application. In debug mode the debugger will kick in when an unhandled
- exception occurs and the integrated server will automatically reload
- the application if changes in the code are detected.</p>
- <p>This attribute can also be configured from the config with the <code class="docutils literal"><span class="pre">DEBUG</span></code>
- configuration key. Defaults to <code class="docutils literal"><span class="pre">False</span></code>.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.default_config">
- <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>
- <dd><p>Default configuration parameters.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.dispatch_request">
- <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>
- <dd><p>Does the request dispatching. Matches the URL and returns the
- return value of the view or error handler. This does not have to
- be a response object. In order to convert the return value to a
- 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>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.7: </span>This no longer does the exception handling, this code was
- 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>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.do_teardown_appcontext">
- <code class="descname">do_teardown_appcontext</code><span class="sig-paren">(</span><em>exc=<object object at 0x000001E1FDEFF7A0></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>
- <dd><p>Called when an application context is popped. This works pretty
- 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
- context.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.9.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.do_teardown_request">
- <code class="descname">do_teardown_request</code><span class="sig-paren">(</span><em>exc=<object object at 0x000001E1FDEFF7A0></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>
- <dd><p>Called after the actual request dispatching and will
- 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
- 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
- triggered when the request context is popped. That way we have a
- tighter control over certain resources under testing environments.</p>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.9: </span>Added the <cite>exc</cite> argument. Previously this was always using the
- current exception information.</p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.endpoint">
- <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>
- <dd><p>A decorator to register a function as an endpoint.
- Example:</p>
- <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">'example.endpoint'</span><span class="p">)</span>
- <span class="k">def</span> <span class="nf">example</span><span class="p">():</span>
- <span class="k">return</span> <span class="s2">"example"</span>
- </pre></div>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>endpoint</strong> – the name of the endpoint</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.error_handler_spec">
- <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>
- <dd><p>A dictionary of all registered error handlers. The key is <code class="docutils literal"><span class="pre">None</span></code>
- for error handlers active on the application, otherwise the key is
- the name of the blueprint. Each key points to another dictionary
- where the key is the status code of the http exception. The
- special key <code class="docutils literal"><span class="pre">None</span></code> points to a list of tuples where the first item
- is the class for the instance check and the second the error handler
- function.</p>
- <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>
- decorator.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.error_handlers">
- <code class="descname">error_handlers</code><a class="headerlink" href="#flask.app.Flask.error_handlers" title="Permalink to this definition">¶</a></dt>
- <dd></dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.errorhandler">
- <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>
- <dd><p>A decorator that is used to register a function give a given
- error code. Example:</p>
- <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>
- <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>
- <span class="k">return</span> <span class="s1">'This page does not exist'</span><span class="p">,</span> <span class="mi">404</span>
- </pre></div>
- </div>
- <p>You can also register handlers for arbitrary exceptions:</p>
- <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>
- <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>
- <span class="k">return</span> <span class="s1">'Database connection failed'</span><span class="p">,</span> <span class="mi">500</span>
- </pre></div>
- </div>
- <p>You can also register a function as error handler without using
- 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
- equivalent to the one above:</p>
- <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>
- <span class="k">return</span> <span class="s1">'This page does not exist'</span><span class="p">,</span> <span class="mi">404</span>
- <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>
- </pre></div>
- </div>
- <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>
- however is discouraged as it requires fiddling with nested dictionaries
- and the special case for arbitrary exception types.</p>
- <p>The first <code class="docutils literal"><span class="pre">None</span></code> refers to the active blueprint. If the error
- handler should be application wide <code class="docutils literal"><span class="pre">None</span></code> shall be used.</p>
- <div class="versionadded">
- <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
- <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
- handlers.</p>
- </div>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7: </span>One can now additionally also register custom exception types
- that do not necessarily have to be a subclass of the
- <code class="xref py py-class docutils literal"><span class="pre">HTTPException</span></code> class.</p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>code</strong> – the code as integer for the handler</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.extensions">
- <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>
- <dd><p>a place where extensions can store application specific state. For
- example this is where an extension could store database engines and
- similar things. For backwards compatibility extensions should register
- themselves like this:</p>
- <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">'extensions'</span><span class="p">):</span>
- <span class="n">app</span><span class="o">.</span><span class="n">extensions</span> <span class="o">=</span> <span class="p">{}</span>
- <span class="n">app</span><span class="o">.</span><span class="n">extensions</span><span class="p">[</span><span class="s1">'extensionname'</span><span class="p">]</span> <span class="o">=</span> <span class="n">SomeObject</span><span class="p">()</span>
- </pre></div>
- </div>
- <p>The key must match the name of the extension module. For example in
- case of a “Flask-Foo” extension in <cite>flask_foo</cite>, the key would be
- <code class="docutils literal"><span class="pre">'foo'</span></code>.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.full_dispatch_request">
- <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>
- <dd><p>Dispatches the request and on top of that performs request
- pre and postprocessing as well as HTTP exception catching and
- error handling.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.got_first_request">
- <code class="descname">got_first_request</code><a class="headerlink" href="#flask.app.Flask.got_first_request" title="Permalink to this definition">¶</a></dt>
- <dd><p>This attribute is set to <code class="docutils literal"><span class="pre">True</span></code> if the application started
- handling the first request.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.8.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.handle_exception">
- <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>
- <dd><p>Default exception handling that kicks in when an exception
- occurs that is not caught. In debug mode the exception will
- be re-raised immediately, otherwise it is logged and the handler
- for a 500 internal server error is used. If no such handler
- exists, a default 500 internal server error message is displayed.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.3.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.handle_http_exception">
- <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>
- <dd><p>Handles an HTTP exception. By default this will invoke the
- registered error handlers and fall back to returning the
- exception as response.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.3.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.handle_url_build_error">
- <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>
- <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>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.handle_user_exception">
- <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>
- <dd><p>This method is called whenever an exception occurs that should be
- handled. A special case are
- <code class="xref py py-class docutils literal"><span class="pre">HTTPException</span></code>s which are forwarded by
- 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
- function will either return a response value or reraise the
- exception with the same traceback.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.init_jinja_globals">
- <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>
- <dd><p>Deprecated. Used to initialize the Jinja2 globals.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.5.</span></p>
- </div>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.7: </span>This method is deprecated with 0.7. Override
- <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>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.inject_url_defaults">
- <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>
- <dd><p>Injects the URL defaults for the given endpoint directly into
- the values dictionary passed. This is used internally and
- automatically called on URL building.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.instance_path">
- <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>
- <dd><p>Holds the path to the instance folder.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.8.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.iter_blueprints">
- <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>
- <dd><p>Iterates over all blueprints by the order they were registered.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.11.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.jinja_env">
- <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>
- <dd><p>The Jinja2 environment used to load templates.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.jinja_environment">
- <code class="descname">jinja_environment</code><a class="headerlink" href="#flask.app.Flask.jinja_environment" title="Permalink to this definition">¶</a></dt>
- <dd><p>The class that is used for the Jinja environment.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.11.</span></p>
- </div>
- <p>alias of <code class="xref py py-class docutils literal"><span class="pre">Environment</span></code></p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.jinja_options">
- <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>
- <dd><p>Options that are passed directly to the Jinja2 environment.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.json_decoder">
- <code class="descname">json_decoder</code><a class="headerlink" href="#flask.app.Flask.json_decoder" title="Permalink to this definition">¶</a></dt>
- <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>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.10.</span></p>
- </div>
- <p>alias of <code class="xref py py-class docutils literal"><span class="pre">JSONDecoder</span></code></p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.json_encoder">
- <code class="descname">json_encoder</code><a class="headerlink" href="#flask.app.Flask.json_encoder" title="Permalink to this definition">¶</a></dt>
- <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>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.10.</span></p>
- </div>
- <p>alias of <code class="xref py py-class docutils literal"><span class="pre">JSONEncoder</span></code></p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.log_exception">
- <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>
- <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>
- if debugging is disabled and right before the handler is called.
- The default implementation logs the exception as error on the
- <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>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.8.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.logger">
- <code class="descname">logger</code><a class="headerlink" href="#flask.app.Flask.logger" title="Permalink to this definition">¶</a></dt>
- <dd><p>A <code class="xref py py-class docutils literal"><span class="pre">logging.Logger</span></code> object for this application. The
- default configuration is to log to stderr if the application is
- in debug mode. This logger can be used to (surprise) log messages.
- Here some examples:</p>
- <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">'A value for debugging'</span><span class="p">)</span>
- <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">'A warning occurred (</span><span class="si">%d</span><span class="s1"> apples)'</span><span class="p">,</span> <span class="mi">42</span><span class="p">)</span>
- <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">'An error occurred'</span><span class="p">)</span>
- </pre></div>
- </div>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.3.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.logger_name">
- <code class="descname">logger_name</code><a class="headerlink" href="#flask.app.Flask.logger_name" title="Permalink to this definition">¶</a></dt>
- <dd><p>The name of the logger to use. By default the logger name is the
- package name passed to the constructor.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.4.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.make_config">
- <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>
- <dd><p>Used to create the config attribute by the Flask constructor.
- The <cite>instance_relative</cite> parameter is passed in from the constructor
- of Flask (there named <cite>instance_relative_config</cite>) and indicates if
- the config should be relative to the instance path or the root path
- of the application.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.8.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.make_default_options_response">
- <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>
- <dd><p>This method is called to create the default <code class="docutils literal"><span class="pre">OPTIONS</span></code> response.
- This can be changed through subclassing to change the default
- behavior of <code class="docutils literal"><span class="pre">OPTIONS</span></code> responses.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.make_null_session">
- <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>
- <dd><p>Creates a new instance of a missing session. Instead of overriding
- 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>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.make_response">
- <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>
- <dd><p>Converts the return value from a view function to a real
- 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>
- <p>The following types are allowed for <cite>rv</cite>:</p>
- <table border="1" class="docutils">
- <colgroup>
- <col width="35%" />
- <col width="65%" />
- </colgroup>
- <tbody valign="top">
- <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>
- <td>the object is returned unchanged</td>
- </tr>
- <tr class="row-even"><td><code class="xref py py-class docutils literal"><span class="pre">str</span></code></td>
- <td>a response object is created with the
- string as body</td>
- </tr>
- <tr class="row-odd"><td><code class="xref py py-class docutils literal"><span class="pre">unicode</span></code></td>
- <td>a response object is created with the
- string encoded to utf-8 as body</td>
- </tr>
- <tr class="row-even"><td>a WSGI function</td>
- <td>the function is called as WSGI application
- and buffered as response object</td>
- </tr>
- <tr class="row-odd"><td><code class="xref py py-class docutils literal"><span class="pre">tuple</span></code></td>
- <td>A tuple in the form <code class="docutils literal"><span class="pre">(response,</span> <span class="pre">status,</span>
- <span class="pre">headers)</span></code> or <code class="docutils literal"><span class="pre">(response,</span> <span class="pre">headers)</span></code>
- where <cite>response</cite> is any of the
- types defined here, <cite>status</cite> is a string
- or an integer and <cite>headers</cite> is a list or
- a dictionary with header values.</td>
- </tr>
- </tbody>
- </table>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>rv</strong> – the return value from the view function</td>
- </tr>
- </tbody>
- </table>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.9: </span>Previously a tuple was interpreted as the arguments for the
- response object.</p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.make_shell_context">
- <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>
- <dd><p>Returns the shell context for an interactive shell for this
- application. This runs all the registered shell context
- processors.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.11.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.name">
- <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>
- <dd><p>The name of the application. This is usually the import name
- with the difference that it’s guessed from the run file if the
- import name is main. This name is used as a display name when
- Flask needs the name of the application. It can be set and overridden
- to change the value.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.8.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.open_instance_resource">
- <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>
- <dd><p>Opens a resource from the application’s instance folder
- (<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
- <code class="xref py py-meth docutils literal"><span class="pre">open_resource()</span></code>. Instance resources can also be opened for
- writing.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>resource</strong> – the name of the resource. To access resources within
- subfolders use forward slashes as separator.</li>
- <li><strong>mode</strong> – resource file opening mode, default is ‘rb’.</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.open_session">
- <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>
- <dd><p>Creates or opens a new session. Default implementation stores all
- session data in a signed cookie. This requires that the
- <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
- 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>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>request</strong> – 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>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.permanent_session_lifetime">
- <code class="descname">permanent_session_lifetime</code><a class="headerlink" href="#flask.app.Flask.permanent_session_lifetime" title="Permalink to this definition">¶</a></dt>
- <dd><p>A <code class="xref py py-class docutils literal"><span class="pre">timedelta</span></code> which is used to set the expiration
- date of a permanent session. The default is 31 days which makes a
- permanent session survive for roughly one month.</p>
- <p>This attribute can also be configured from the config with the
- <code class="docutils literal"><span class="pre">PERMANENT_SESSION_LIFETIME</span></code> configuration key. Defaults to
- <code class="docutils literal"><span class="pre">timedelta(days=31)</span></code></p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.preprocess_request">
- <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>
- <dd><p>Called before the actual request dispatching and will
- 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
- arguments.
- If any of these functions returns a value, it’s handled as
- if it was the return value from the view and further
- request handling is stopped.</p>
- <p>This also triggers the <code class="xref py py-meth docutils literal"><span class="pre">url_value_processor()</span></code> functions before
- 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>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.preserve_context_on_exception">
- <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>
- <dd><p>Returns the value of the <code class="docutils literal"><span class="pre">PRESERVE_CONTEXT_ON_EXCEPTION</span></code>
- configuration value in case it’s set, otherwise a sensible default
- is returned.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.process_response">
- <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>
- <dd><p>Can be overridden in order to modify the response object
- before it’s sent to the WSGI server. By default this will
- 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>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.5: </span>As of Flask 0.5 the functions registered for after request
- execution are called in reverse order of registration.</p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>response</strong> – 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>
- </tr>
- <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
- 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>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.propagate_exceptions">
- <code class="descname">propagate_exceptions</code><a class="headerlink" href="#flask.app.Flask.propagate_exceptions" title="Permalink to this definition">¶</a></dt>
- <dd><p>Returns the value of the <code class="docutils literal"><span class="pre">PROPAGATE_EXCEPTIONS</span></code> configuration
- value in case it’s set, otherwise a sensible default is returned.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.raise_routing_exception">
- <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>
- <dd><p>Exceptions that are recording during routing are reraised with
- this method. During debug we are not reraising redirect requests
- 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’re raising
- a different error instead to help debug situations.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Internal:</th><td class="field-body"></td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.register_blueprint">
- <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>
- <dd><p>Register a blueprint on the application. For information about
- blueprints head over to <span class="xref std std-ref">blueprints</span>.</p>
- <p>The blueprint name is passed in as the first argument.
- Options are passed as additional keyword arguments and forwarded to
- <cite>blueprints</cite> in an “options” dictionary.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>subdomain</strong> – set a subdomain for the blueprint</li>
- <li><strong>url_prefix</strong> – set the prefix for all URLs defined on the blueprint.
- <code class="docutils literal"><span class="pre">(url_prefix='/<lang</span> <span class="pre">code>')</span></code></li>
- <li><strong>url_defaults</strong> – a dictionary with URL defaults that is added to
- each and every URL defined with this blueprint</li>
- <li><strong>static_folder</strong> – add a static folder to urls in this blueprint</li>
- <li><strong>static_url_path</strong> – add a static url path to urls in this blueprint</li>
- <li><strong>template_folder</strong> – set an alternate template folder</li>
- <li><strong>root_path</strong> – set an alternate root path for this blueprint</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.register_error_handler">
- <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>
- <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>
- decorator that is more straightforward to use for non decorator
- usage.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.request_class">
- <code class="descname">request_class</code><a class="headerlink" href="#flask.app.Flask.request_class" title="Permalink to this definition">¶</a></dt>
- <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>
- for more information.</p>
- <p>alias of <code class="xref py py-class docutils literal"><span class="pre">Request</span></code></p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.request_context">
- <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>
- <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
- environment and binds it to the current context. This must be used in
- combination with the <code class="docutils literal"><span class="pre">with</span></code> statement because the request is only bound
- to the current context for the duration of the <code class="docutils literal"><span class="pre">with</span></code> block.</p>
- <p>Example usage:</p>
- <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>
- <span class="n">do_something_with</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
- </pre></div>
- </div>
- <p>The object returned can also be used without the <code class="docutils literal"><span class="pre">with</span></code> statement
- which is useful for working in the shell. The example above is
- doing exactly the same as this code:</p>
- <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>
- <span class="n">ctx</span><span class="o">.</span><span class="n">push</span><span class="p">()</span>
- <span class="k">try</span><span class="p">:</span>
- <span class="n">do_something_with</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
- <span class="k">finally</span><span class="p">:</span>
- <span class="n">ctx</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
- </pre></div>
- </div>
- <div class="versionchanged">
- <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
- is now passed the ctx object.</p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>environ</strong> – a WSGI environment</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.request_globals_class">
- <code class="descname">request_globals_class</code><a class="headerlink" href="#flask.app.Flask.request_globals_class" title="Permalink to this definition">¶</a></dt>
- <dd></dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.response_class">
- <code class="descname">response_class</code><a class="headerlink" href="#flask.app.Flask.response_class" title="Permalink to this definition">¶</a></dt>
- <dd><p>The class that is used for response objects. See
- <code class="xref py py-class docutils literal"><span class="pre">Response</span></code> for more information.</p>
- <p>alias of <code class="xref py py-class docutils literal"><span class="pre">Response</span></code></p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.route">
- <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>
- <dd><p>A decorator that is used to register a view function for a
- 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>
- but is intended for decorator usage:</p>
- <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">'/'</span><span class="p">)</span>
- <span class="k">def</span> <span class="nf">index</span><span class="p">():</span>
- <span class="k">return</span> <span class="s1">'Hello World'</span>
- </pre></div>
- </div>
- <p>For more information refer to <span class="xref std std-ref">url-route-registrations</span>.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>rule</strong> – the URL rule as string</li>
- <li><strong>endpoint</strong> – the endpoint for the registered URL rule. Flask
- itself assumes the name of the view function as
- endpoint</li>
- <li><strong>options</strong> – the options to be forwarded to the underlying
- <code class="xref py py-class docutils literal"><span class="pre">Rule</span></code> object. A change
- to Werkzeug is handling of method options. methods
- is a list of methods this rule should be limited
- 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
- 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>).
- Starting with Flask 0.6, <code class="docutils literal"><span class="pre">OPTIONS</span></code> is implicitly
- added and handled by the standard request handling.</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.run">
- <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>
- <dd><p>Runs the application on a local development server.</p>
- <p>Do not use <code class="docutils literal"><span class="pre">run()</span></code> in a production setting. It is not intended to
- meet security and performance requirements for a production server.
- Instead, see <span class="xref std std-ref">deployment</span> for WSGI server recommendations.</p>
- <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
- for code changes and show a debugger in case an exception happened.</p>
- <p>If you want to run the application in debug mode, but disable the
- code execution on the interactive debugger, you can pass
- <code class="docutils literal"><span class="pre">use_evalex=False</span></code> as parameter. This will keep the debugger’s
- traceback screen active, but disable code execution.</p>
- <p>It is not recommended to use this function for development with
- automatic reloading as this is badly supported. Instead you should
- be using the <strong class="command">flask</strong> command line script’s <code class="docutils literal"><span class="pre">run</span></code> support.</p>
- <div class="admonition-keep-in-mind admonition">
- <p class="first admonition-title">Keep in Mind</p>
- <p class="last">Flask will suppress any server error with a generic error page
- unless it is in debug mode. As such to enable just the
- interactive debugger without the code reloading, you have to
- 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>.
- 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
- won’t catch any exceptions because there won’t be any to
- catch.</p>
- </div>
- <div class="versionchanged">
- <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>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>host</strong> – the hostname to listen on. Set this to <code class="docutils literal"><span class="pre">'0.0.0.0'</span></code> to
- have the server available externally as well. Defaults to
- <code class="docutils literal"><span class="pre">'127.0.0.1'</span></code>.</li>
- <li><strong>port</strong> – the port of the webserver. Defaults to <code class="docutils literal"><span class="pre">5000</span></code> or the
- port defined in the <code class="docutils literal"><span class="pre">SERVER_NAME</span></code> config variable if
- present.</li>
- <li><strong>debug</strong> – if given, enable or disable debug mode.
- 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>
- <li><strong>options</strong> – the options to be forwarded to the underlying
- Werkzeug server. See
- <code class="xref py py-func docutils literal"><span class="pre">werkzeug.serving.run_simple()</span></code> for more
- information.</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.save_session">
- <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>
- <dd><p>Saves the session if it needs updates. For the default
- 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
- 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>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>session</strong> – the session to be saved (a
- <code class="xref py py-class docutils literal"><span class="pre">SecureCookie</span></code>
- object)</li>
- <li><strong>response</strong> – 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>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.secret_key">
- <code class="descname">secret_key</code><a class="headerlink" href="#flask.app.Flask.secret_key" title="Permalink to this definition">¶</a></dt>
- <dd><p>If a secret key is set, cryptographic components can use this to
- sign cookies and other things. Set this to a complex random value
- when you want to use the secure cookie for instance.</p>
- <p>This attribute can also be configured from the config with the
- <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>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.select_jinja_autoescape">
- <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>
- <dd><p>Returns <code class="docutils literal"><span class="pre">True</span></code> if autoescaping should be active for the given
- template name. If no template name is given, returns <cite>True</cite>.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.5.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.send_file_max_age_default">
- <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>
- <dd><p>A <code class="xref py py-class docutils literal"><span class="pre">timedelta</span></code> which is used as default cache_timeout
- for the <code class="xref py py-func docutils literal"><span class="pre">send_file()</span></code> functions. The default is 12 hours.</p>
- <p>This attribute can also be configured from the config with the
- <code class="docutils literal"><span class="pre">SEND_FILE_MAX_AGE_DEFAULT</span></code> configuration key. This configuration
- variable can also be set with an integer value used as seconds.
- Defaults to <code class="docutils literal"><span class="pre">timedelta(hours=12)</span></code></p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.session_cookie_name">
- <code class="descname">session_cookie_name</code><a class="headerlink" href="#flask.app.Flask.session_cookie_name" title="Permalink to this definition">¶</a></dt>
- <dd><p>The secure cookie uses this for the name of the session cookie.</p>
- <p>This attribute can also be configured from the config with the
- <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>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.session_interface">
- <code class="descname">session_interface</code><em class="property"> = <flask.sessions.SecureCookieSessionInterface object at 0x000001E1821AB278></em><a class="headerlink" href="#flask.app.Flask.session_interface" title="Permalink to this definition">¶</a></dt>
- <dd><p>the session interface to use. By default an instance of
- <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>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.8.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.shell_context_processor">
- <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>
- <dd><p>Registers a shell context processor function.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.11.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.shell_context_processors">
- <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>
- <dd><p>A list of shell context processor functions that should be run
- when a shell context is created.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.11.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.should_ignore_error">
- <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>
- <dd><p>This is called to figure out if an error should be ignored
- or not as far as the teardown system is concerned. If this
- function returns <code class="docutils literal"><span class="pre">True</span></code> then the teardown handlers will not be
- passed the error.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.10.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.teardown_appcontext">
- <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>
- <dd><p>Registers a function to be called when the application context
- ends. These functions are typically also called when the request
- context is popped.</p>
- <p>Example:</p>
- <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>
- <span class="n">ctx</span><span class="o">.</span><span class="n">push</span><span class="p">()</span>
- <span class="o">...</span>
- <span class="n">ctx</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
- </pre></div>
- </div>
- <p>When <code class="docutils literal"><span class="pre">ctx.pop()</span></code> is executed in the above example, the teardown
- functions are called just before the app context moves from the
- stack of active contexts. This becomes relevant if you are using
- such constructs in tests.</p>
- <p>Since a request context typically also manages an application
- context it would also be called when you pop a request context.</p>
- <p>When a teardown function was called because of an exception it will
- be passed an error object.</p>
- <p>The return values of teardown functions are ignored.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.9.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.teardown_appcontext_funcs">
- <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>
- <dd><p>A list of functions that are called when the application context
- is destroyed. Since the application context is also torn down
- if the request ends this is the place to store code that disconnects
- from databases.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.9.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.teardown_request">
- <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>
- <dd><p>Register a function to be run at the end of each request,
- regardless of whether there was an exception or not. These functions
- are executed when the request context is popped, even if not an
- actual request was performed.</p>
- <p>Example:</p>
- <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>
- <span class="n">ctx</span><span class="o">.</span><span class="n">push</span><span class="p">()</span>
- <span class="o">...</span>
- <span class="n">ctx</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
- </pre></div>
- </div>
- <p>When <code class="docutils literal"><span class="pre">ctx.pop()</span></code> is executed in the above example, the teardown
- functions are called just before the request context moves from the
- stack of active contexts. This becomes relevant if you are using
- such constructs in tests.</p>
- <p>Generally teardown functions must take every necessary step to avoid
- that they will fail. If they do execute code that might fail they
- will have to surround the execution of these code by try/except
- statements and log occurring errors.</p>
- <p>When a teardown function was called because of a exception it will
- be passed an error object.</p>
- <p>The return values of teardown functions are ignored.</p>
- <div class="admonition-debug-note admonition">
- <p class="first admonition-title">Debug Note</p>
- <p class="last">In debug mode Flask will not tear down a request on an exception
- immediately. Instead it will keep it alive so that the interactive
- debugger can still access it. This behavior can be controlled
- by the <code class="docutils literal"><span class="pre">PRESERVE_CONTEXT_ON_EXCEPTION</span></code> configuration variable.</p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.teardown_request_funcs">
- <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>
- <dd><p>A dictionary with lists of functions that are called after
- each request, even if an exception has occurred. The key of the
- dictionary is the name of the blueprint this function is active for,
- <code class="docutils literal"><span class="pre">None</span></code> for all requests. These functions are not allowed to modify
- the request, and their return values are ignored. If an exception
- occurred while processing the request, it gets passed to each
- teardown_request function. To register a function here, use the
- <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>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.template_context_processors">
- <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>
- <dd><p>A dictionary with list of functions that are called without argument
- to populate the template context. The key of the dictionary is the
- name of the blueprint this function is active for, <code class="docutils literal"><span class="pre">None</span></code> for all
- requests. Each returns a dictionary that the template context is
- updated with. To register a function here, use the
- <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>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.template_filter">
- <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>
- <dd><p>A decorator that is used to register custom template filter.
- You can specify a name for the filter, otherwise the function
- name will be used. Example:</p>
- <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>
- <span class="k">def</span> <span class="nf">reverse</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
- <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>
- </pre></div>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> – the optional name of the filter, otherwise the
- function name will be used.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.template_global">
- <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>
- <dd><p>A decorator that is used to register a custom template global function.
- You can specify a name for the global function, otherwise the function
- name will be used. Example:</p>
- <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>
- <span class="k">def</span> <span class="nf">double</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
- <span class="k">return</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">n</span>
- </pre></div>
- </div>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.10.</span></p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> – the optional name of the global function, otherwise the
- function name will be used.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.template_test">
- <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>
- <dd><p>A decorator that is used to register custom template test.
- You can specify a name for the test, otherwise the function
- name will be used. Example:</p>
- <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>
- <span class="k">def</span> <span class="nf">is_prime</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
- <span class="k">if</span> <span class="n">n</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
- <span class="k">return</span> <span class="kc">True</span>
- <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>
- <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>
- <span class="k">return</span> <span class="kc">False</span>
- <span class="k">return</span> <span class="kc">True</span>
- </pre></div>
- </div>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.10.</span></p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> – the optional name of the test, otherwise the
- function name will be used.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.test_client">
- <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>
- <dd><p>Creates a test client for this application. For information
- about unit testing head over to <span class="xref std std-ref">testing</span>.</p>
- <p>Note that if you are testing for assertions or exceptions in your
- 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
- exceptions to propagate to the test client. Otherwise, the exception
- will be handled by the application (not visible to the test client) and
- the only indication of an AssertionError or other exception will be a
- 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>
- attribute. For example:</p>
- <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>
- <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>
- </pre></div>
- </div>
- <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
- of the context until the end of the <code class="docutils literal"><span class="pre">with</span></code> block. This is useful if
- you want to access the context locals for testing:</p>
- <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>
- <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">'/?vodka=42'</span><span class="p">)</span>
- <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">'vodka'</span><span class="p">]</span> <span class="o">==</span> <span class="s1">'42'</span>
- </pre></div>
- </div>
- <p>Additionally, you may pass optional keyword arguments that will then
- be passed to the application’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.
- For example:</p>
- <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>
- <span class="k">class</span> <span class="nc">CustomClient</span><span class="p">(</span><span class="n">FlaskClient</span><span class="p">):</span>
- <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>
- <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>
- <span class="bp">self</span><span class="o">.</span><span class="n">_authentication</span> <span class="o">=</span> <span class="n">authentication</span>
- <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>
- <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">'Basic ....'</span><span class="p">)</span>
- </pre></div>
- </div>
- <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>
- <div class="versionchanged">
- <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>
- </div>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7: </span>The <cite>use_cookies</cite> parameter was added as well as the ability
- to override the client to be used by setting the
- <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>
- </div>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.11: </span>Added <cite>**kwargs</cite> to support passing additional keyword arguments to
- 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>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.test_client_class">
- <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>
- <dd><p>the test client that is used with when <cite>test_client</cite> is used.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.test_request_context">
- <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>
- <dd><p>Creates a WSGI environment from the given values (see
- <code class="xref py py-class docutils literal"><span class="pre">werkzeug.test.EnvironBuilder</span></code> for more information, this
- function accepts the same arguments).</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.testing">
- <code class="descname">testing</code><a class="headerlink" href="#flask.app.Flask.testing" title="Permalink to this definition">¶</a></dt>
- <dd><p>The testing flag. Set this to <code class="docutils literal"><span class="pre">True</span></code> to enable the test mode of
- Flask extensions (and in the future probably also Flask itself).
- For example this might activate unittest helpers that have an
- additional runtime cost which should not be enabled by default.</p>
- <p>If this is enabled and PROPAGATE_EXCEPTIONS is not changed from the
- default it’s implicitly enabled.</p>
- <p>This attribute can also be configured from the config with the
- <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>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.trap_http_exception">
- <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>
- <dd><p>Checks if an HTTP exception should be trapped or not. By default
- this will return <code class="docutils literal"><span class="pre">False</span></code> for all exceptions except for a bad request
- 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
- 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>
- <p>This is called for all HTTP exceptions raised by a view function.
- If it returns <code class="docutils literal"><span class="pre">True</span></code> for any exception the error handler for this
- exception is not called and it shows up as regular exception in the
- traceback. This is helpful for debugging implicitly raised HTTP
- exceptions.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.8.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.try_trigger_before_first_request_functions">
- <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>
- <dd><p>Called before each request and will ensure that it triggers
- 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
- application instance (which means process usually).</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Internal:</th><td class="field-body"></td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.update_template_context">
- <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>
- <dd><p>Update the template context with some commonly used variables.
- This injects request, session, config and g into the template
- context as well as everything template context processors want
- to inject. Note that the as of Flask 0.6, the original values
- in the context will not be overridden if a context processor
- decides to return a value with the same key.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>context</strong> – the context as a dictionary that is updated in place
- to add extra variables.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.url_build_error_handlers">
- <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>
- <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
- <code class="xref py py-exc docutils literal"><span class="pre">BuildError</span></code>. Each function registered here
- is called with <cite>error</cite>, <cite>endpoint</cite> and <cite>values</cite>. If a function
- 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
- tried.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.9.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.url_default_functions">
- <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>
- <dd><p>A dictionary with lists of functions that can be used as URL value
- preprocessors. The key <code class="docutils literal"><span class="pre">None</span></code> here is used for application wide
- callbacks, otherwise the key is the name of the blueprint.
- Each of these functions has the chance to modify the dictionary
- of URL values before they are used as the keyword arguments of the
- view function. For each function registered this one should also
- 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
- automatically again that were removed that way.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.url_defaults">
- <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>
- <dd><p>Callback function for URL defaults for all view functions of the
- application. It’s called with the endpoint and values and should
- update the values passed in place.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.url_map">
- <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>
- <dd><p>The <code class="xref py py-class docutils literal"><span class="pre">Map</span></code> for this instance. You can use
- this to change the routing converters after the class was created
- but before any routes are connected. Example:</p>
- <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>
- <span class="k">class</span> <span class="nc">ListConverter</span><span class="p">(</span><span class="n">BaseConverter</span><span class="p">):</span>
- <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>
- <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">','</span><span class="p">)</span>
- <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>
- <span class="k">return</span> <span class="s1">','</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>
- <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">values</span><span class="p">)</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>
- <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">'list'</span><span class="p">]</span> <span class="o">=</span> <span class="n">ListConverter</span>
- </pre></div>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.url_rule_class">
- <code class="descname">url_rule_class</code><a class="headerlink" href="#flask.app.Flask.url_rule_class" title="Permalink to this definition">¶</a></dt>
- <dd><p>The rule object to use for URL rules created. This is used by
- <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>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- <p>alias of <code class="xref py py-class docutils literal"><span class="pre">Rule</span></code></p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.url_value_preprocessor">
- <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>
- <dd><p>Registers a function as URL value preprocessor for all view
- functions of the application. It’s called before the view functions
- are called and can modify the url values provided.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.url_value_preprocessors">
- <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>
- <dd><p>A dictionary with lists of functions that can be used as URL
- value processor functions. Whenever a URL is built these functions
- are called to modify the dictionary of values in place. The key
- <code class="docutils literal"><span class="pre">None</span></code> here is used for application wide
- callbacks, otherwise the key is the name of the blueprint.
- Each of these functions has the chance to modify the dictionary</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.use_x_sendfile">
- <code class="descname">use_x_sendfile</code><a class="headerlink" href="#flask.app.Flask.use_x_sendfile" title="Permalink to this definition">¶</a></dt>
- <dd><p>Enable this if you want to use the X-Sendfile feature. Keep in
- mind that the server has to support this. This only affects files
- sent with the <code class="xref py py-func docutils literal"><span class="pre">send_file()</span></code> method.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.2.</span></p>
- </div>
- <p>This attribute can also be configured from the config with the
- <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>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.app.Flask.view_functions">
- <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>
- <dd><p>A dictionary of all view functions registered. The keys will
- be function names which are also used to generate URLs and
- the values are the function objects themselves.
- 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>
- </dd></dl>
- <dl class="method">
- <dt id="flask.app.Flask.wsgi_app">
- <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>
- <dd><p>The actual WSGI application. This is not implemented in
- <cite>__call__</cite> so that middlewares can be applied without losing a
- reference to the class. So instead of doing this:</p>
- <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>
- </pre></div>
- </div>
- <p>It’s a better idea to do this instead:</p>
- <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>
- </pre></div>
- </div>
- <p>Then you still have the original application object around and
- can continue to call methods on it.</p>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.7: </span>The behavior of the before and after request callbacks was changed
- under error conditions and a new callback was added that will
- always execute at the end of the request, independent on if an
- error occurred or not. See <span class="xref std std-ref">callbacks-and-errors</span>.</p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>environ</strong> – a WSGI environment</li>
- <li><strong>start_response</strong> – a callable accepting a status code,
- a list of headers and an optional
- exception context to start the response</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- </dd></dl>
- <dl class="function">
- <dt id="flask.app.setupmethod">
- <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>
- <dd><p>Wraps a method so that it performs a check in debug mode if the
- first request was already handled.</p>
- </dd></dl>
- </div>
- </div>
- <div class="section" id="module-flask.blueprints">
- <span id="flask-blueprints-module"></span><h2>flask.blueprints module<a class="headerlink" href="#module-flask.blueprints" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-blueprints">
- <h3>flask.blueprints<a class="headerlink" href="#flask-blueprints" title="Permalink to this headline">¶</a></h3>
- <p>Blueprints are the recommended way to implement larger or more
- pluggable applications in Flask 0.7 and later.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="class">
- <dt id="flask.blueprints.Blueprint">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">flask.helpers._PackageBoundObject</span></code></p>
- <p>Represents a blueprint. A blueprint is an object that records
- functions that will be called with the
- <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
- or other things on the main application. See <span class="xref std std-ref">blueprints</span> for more
- information.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.add_app_template_filter">
- <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>
- <dd><p>Register a custom template filter, available application wide. Like
- <code class="xref py py-meth docutils literal"><span class="pre">Flask.add_template_filter()</span></code> but for a blueprint. Works exactly
- 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>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> – the optional name of the filter, otherwise the
- function name will be used.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.add_app_template_global">
- <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>
- <dd><p>Register a custom template global, available application wide. Like
- <code class="xref py py-meth docutils literal"><span class="pre">Flask.add_template_global()</span></code> but for a blueprint. Works exactly
- 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>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.10.</span></p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> – the optional name of the global, otherwise the
- function name will be used.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.add_app_template_test">
- <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>
- <dd><p>Register a custom template test, available application wide. Like
- <code class="xref py py-meth docutils literal"><span class="pre">Flask.add_template_test()</span></code> but for a blueprint. Works exactly
- 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>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.10.</span></p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> – the optional name of the test, otherwise the
- function name will be used.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.add_url_rule">
- <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>
- <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
- 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>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.after_app_request">
- <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>
- <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
- is executed after each request, even if outside of the blueprint.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.after_request">
- <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>
- <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
- is only executed after each request that is handled by a function of
- that blueprint.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.app_context_processor">
- <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>
- <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
- function is executed each request, even if outside of the blueprint.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.app_errorhandler">
- <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>
- <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.errorhandler()</span></code> but for a blueprint. This
- handler is used for all requests, even if outside of the blueprint.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.app_template_filter">
- <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>
- <dd><p>Register a custom template filter, available application wide. Like
- <code class="xref py py-meth docutils literal"><span class="pre">Flask.template_filter()</span></code> but for a blueprint.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> – the optional name of the filter, otherwise the
- function name will be used.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.app_template_global">
- <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>
- <dd><p>Register a custom template global, available application wide. Like
- <code class="xref py py-meth docutils literal"><span class="pre">Flask.template_global()</span></code> but for a blueprint.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.10.</span></p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> – the optional name of the global, otherwise the
- function name will be used.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.app_template_test">
- <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>
- <dd><p>Register a custom template test, available application wide. Like
- <code class="xref py py-meth docutils literal"><span class="pre">Flask.template_test()</span></code> but for a blueprint.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.10.</span></p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> – the optional name of the test, otherwise the
- function name will be used.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.app_url_defaults">
- <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>
- <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>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.app_url_value_preprocessor">
- <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>
- <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>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.before_app_first_request">
- <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>
- <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.before_first_request()</span></code>. Such a function is
- executed before the first request to the application.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.before_app_request">
- <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>
- <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.before_request()</span></code>. Such a function is executed
- before each request, even if outside of a blueprint.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.before_request">
- <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>
- <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
- is only executed before each request that is handled by a function of
- that blueprint.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.context_processor">
- <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>
- <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.context_processor()</span></code> but for a blueprint. This
- function is only executed for requests handled by a blueprint.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.endpoint">
- <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>
- <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
- prefix the endpoint with the blueprint name, this has to be done
- explicitly by the user of this method. If the endpoint is prefixed
- with a <cite>.</cite> it will be registered to the current blueprint, otherwise
- it’s an application independent endpoint.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.errorhandler">
- <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>
- <dd><p>Registers an error handler that becomes active for this blueprint
- only. Please be aware that routing does not happen local to a
- blueprint so an error handler for 404 usually is not handled by
- a blueprint unless it is caused inside a view function. Another
- special case is the 500 internal server error which is always looked
- up from the application.</p>
- <p>Otherwise works as the <code class="xref py py-meth docutils literal"><span class="pre">errorhandler()</span></code> decorator
- of the <code class="xref py py-class docutils literal"><span class="pre">Flask</span></code> object.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.make_setup_state">
- <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>
- <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>
- object that is later passed to the register callback functions.
- Subclasses can override this to return a subclass of the setup state.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.record">
- <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>
- <dd><p>Registers a function that is called when the blueprint is
- registered on the application. This function is called with the
- 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>
- method.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.record_once">
- <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>
- <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
- function that will ensure the function is only called once. If the
- blueprint is registered a second time on the application, the
- function passed is not called.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.register">
- <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>
- <dd><p>Called by <code class="xref py py-meth docutils literal"><span class="pre">Flask.register_blueprint()</span></code> to register a blueprint
- on the application. This can be overridden to customize the register
- behavior. Keyword arguments from
- <code class="xref py py-func docutils literal"><span class="pre">register_blueprint()</span></code> are directly forwarded to this
- method in the <cite>options</cite> dictionary.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.register_error_handler">
- <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>
- <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
- function, akin to the <code class="xref py py-meth docutils literal"><span class="pre">register_error_handler()</span></code>
- application-wide function of the <code class="xref py py-class docutils literal"><span class="pre">Flask</span></code> object but
- for error handlers limited to this blueprint.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.11.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.route">
- <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>
- <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
- <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>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.teardown_app_request">
- <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>
- <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
- function is executed when tearing down each request, even if outside of
- the blueprint.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.teardown_request">
- <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>
- <dd><p>Like <code class="xref py py-meth docutils literal"><span class="pre">Flask.teardown_request()</span></code> but for a blueprint. This
- function is only executed when tearing down requests handled by a
- function of that blueprint. Teardown request functions are executed
- when the request context is popped, even when no actual request was
- performed.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.url_defaults">
- <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>
- <dd><p>Callback function for URL defaults for this blueprint. It’s called
- with the endpoint and values and should update the values passed
- in place.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.blueprints.Blueprint.url_value_preprocessor">
- <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>
- <dd><p>Registers a function as URL value preprocessor for this
- blueprint. It’s called before the view functions are called and
- can modify the url values provided.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.blueprints.Blueprint.warn_on_modifications">
- <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>
- <dd></dd></dl>
- </dd></dl>
- <dl class="class">
- <dt id="flask.blueprints.BlueprintSetupState">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
- <p>Temporary holder object for registering a blueprint with the
- application. An instance of this class is created by the
- <code class="xref py py-meth docutils literal"><span class="pre">make_setup_state()</span></code> method and later passed
- to all register callback functions.</p>
- <dl class="method">
- <dt id="flask.blueprints.BlueprintSetupState.add_url_rule">
- <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>
- <dd><p>A helper method to register a rule (and optionally a view function)
- to the application. The endpoint is automatically prefixed with the
- blueprint’s name.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.blueprints.BlueprintSetupState.app">
- <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>
- <dd><p>a reference to the current application</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.blueprints.BlueprintSetupState.blueprint">
- <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>
- <dd><p>a reference to the blueprint that created this setup state.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.blueprints.BlueprintSetupState.first_registration">
- <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>
- <dd><p>as blueprints can be registered multiple times with the
- application and not everything wants to be registered
- multiple times on it, this attribute can be used to figure
- out if the blueprint was registered in the past already.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.blueprints.BlueprintSetupState.options">
- <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>
- <dd><p>a dictionary with all options that were passed to the
- <code class="xref py py-meth docutils literal"><span class="pre">register_blueprint()</span></code> method.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.blueprints.BlueprintSetupState.subdomain">
- <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>
- <dd><p>The subdomain that the blueprint should be active for, <code class="docutils literal"><span class="pre">None</span></code>
- otherwise.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.blueprints.BlueprintSetupState.url_defaults">
- <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>
- <dd><p>A dictionary with URL defaults that is added to each and every
- URL that was defined with the blueprint.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.blueprints.BlueprintSetupState.url_prefix">
- <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>
- <dd><p>The prefix that should be used for all URLs defined on the
- blueprint.</p>
- </dd></dl>
- </dd></dl>
- </div>
- </div>
- <div class="section" id="module-flask.cli">
- <span id="flask-cli-module"></span><h2>flask.cli module<a class="headerlink" href="#module-flask.cli" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-cli">
- <h3>flask.cli<a class="headerlink" href="#flask-cli" title="Permalink to this headline">¶</a></h3>
- <p>A simple command line application to run flask apps.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="class">
- <dt id="flask.cli.AppGroup">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">click.core.Group</span></code></p>
- <p>This works similar to a regular click <code class="xref py py-class docutils literal"><span class="pre">Group</span></code> but it
- 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
- 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>
- <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>
- <dl class="method">
- <dt id="flask.cli.AppGroup.command">
- <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>
- <dd><p>This works exactly like the method of the same name on a regular
- <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>
- unless it’s disabled by passing <code class="docutils literal"><span class="pre">with_appcontext=False</span></code>.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.cli.AppGroup.group">
- <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>
- <dd><p>This works exactly like the method of the same name on a regular
- <code class="xref py py-class docutils literal"><span class="pre">click.Group</span></code> but it defaults the group class to
- <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>
- </dd></dl>
- </dd></dl>
- <dl class="class">
- <dt id="flask.cli.DispatchingApp">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
- <p>Special application that dispatches to a flask application which
- is imported by name in a background thread. If an error happens
- it is is recorded and shows as part of the WSGI handling which in case
- of the Werkzeug debugger means that it shows up in the browser.</p>
- </dd></dl>
- <dl class="class">
- <dt id="flask.cli.FlaskGroup">
- <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>
- <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>
- <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
- loading more commands from the configured Flask app. Normally a
- developer does not have to interface with this class but there are
- some very advanced use cases for which it makes sense to create an
- instance of this.</p>
- <p>For information as of why this is useful see <span class="xref std std-ref">custom-scripts</span>.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>add_default_commands</strong> – if this is True then the default run and
- shell commands wil be added.</li>
- <li><strong>create_app</strong> – an optional callback that is passed the script info
- and returns the loaded app.</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="method">
- <dt id="flask.cli.FlaskGroup.get_command">
- <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>
- <dd></dd></dl>
- <dl class="method">
- <dt id="flask.cli.FlaskGroup.list_commands">
- <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>
- <dd></dd></dl>
- <dl class="method">
- <dt id="flask.cli.FlaskGroup.main">
- <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>
- <dd></dd></dl>
- </dd></dl>
- <dl class="exception">
- <dt id="flask.cli.NoAppException">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">click.exceptions.UsageError</span></code></p>
- <p>Raised if an application cannot be found or loaded.</p>
- </dd></dl>
- <dl class="class">
- <dt id="flask.cli.ScriptInfo">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
- <p>Help object to deal with Flask applications. This is usually not
- necessary to interface with as it’s used internally in the dispatching
- to click. In future versions of Flask this object will most likely play
- a bigger role. Typically it’s created automatically by the
- <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
- onwards as click object.</p>
- <dl class="attribute">
- <dt id="flask.cli.ScriptInfo.app_import_path">
- <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>
- <dd><p>Optionally the import path for the Flask application.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.cli.ScriptInfo.create_app">
- <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>
- <dd><p>Optionally a function that is passed the script info to create
- the instance of the application.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.cli.ScriptInfo.data">
- <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>
- <dd><p>A dictionary with arbitrary data that can be associated with
- this script info.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.cli.ScriptInfo.load_app">
- <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>
- <dd><p>Loads the Flask app (if not yet loaded) and returns it. Calling
- this multiple times will just result in the already loaded app to
- be returned.</p>
- </dd></dl>
- </dd></dl>
- <dl class="function">
- <dt id="flask.cli.find_best_app">
- <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>
- <dd><p>Given a module instance this tries to find the best possible
- application in the module or raises an exception.</p>
- </dd></dl>
- <dl class="function">
- <dt id="flask.cli.find_default_import_path">
- <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>
- <dd></dd></dl>
- <dl class="function">
- <dt id="flask.cli.locate_app">
- <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>
- <dd><p>Attempts to locate the application.</p>
- </dd></dl>
- <dl class="function">
- <dt id="flask.cli.main">
- <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>
- <dd></dd></dl>
- <dl class="function">
- <dt id="flask.cli.prepare_exec_for_file">
- <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>
- <dd><p>Given a filename this will try to calculate the python path, add it
- to the search path and return the actual module name that is expected.</p>
- </dd></dl>
- <dl class="function">
- <dt id="flask.cli.with_appcontext">
- <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>
- <dd><p>Wraps a callback so that it’s guaranteed to be executed with the
- script’s application context. If callbacks are registered directly
- to the <code class="docutils literal"><span class="pre">app.cli</span></code> object then they are wrapped with this function
- by default unless it’s disabled.</p>
- </dd></dl>
- </div>
- </div>
- <div class="section" id="module-flask.config">
- <span id="flask-config-module"></span><h2>flask.config module<a class="headerlink" href="#module-flask.config" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-config">
- <h3>flask.config<a class="headerlink" href="#flask-config" title="Permalink to this headline">¶</a></h3>
- <p>Implements the configuration related objects.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="class">
- <dt id="flask.config.Config">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">dict</span></code></p>
- <p>Works exactly like a dict but provides ways to fill it from files
- or special dictionaries. There are two common patterns to populate the
- config.</p>
- <p>Either you can fill the config from a config file:</p>
- <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">'yourconfig.cfg'</span><span class="p">)</span>
- </pre></div>
- </div>
- <p>Or alternatively you can define the configuration options in the
- 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
- a module that should be loaded. It is also possible to tell it to
- use the same module and with that provide the configuration values
- just before the call:</p>
- <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">DEBUG</span> <span class="o">=</span> <span class="kc">True</span>
- <span class="n">SECRET_KEY</span> <span class="o">=</span> <span class="s1">'development key'</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="n">__name__</span><span class="p">)</span>
- </pre></div>
- </div>
- <p>In both cases (loading from any Python file or loading from modules),
- only uppercase keys are added to the config. This makes it possible to use
- lowercase values in the config file for temporary values that are not added
- to the config or to define the config keys in the same file that implements
- the application.</p>
- <p>Probably the most interesting way to load configurations is from an
- environment variable pointing to a file:</p>
- <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">'YOURAPPLICATION_SETTINGS'</span><span class="p">)</span>
- </pre></div>
- </div>
- <p>In this case before launching the application you have to set this
- environment variable to the file you want to use. On Linux and OS X
- use the export statement:</p>
- <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">'/path/to/config/file'</span>
- </pre></div>
- </div>
- <p>On windows use <cite>set</cite> instead.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>root_path</strong> – path to which files are read relative from. When the
- config object is created by the application, this is
- the application’s <code class="xref py py-attr docutils literal"><span class="pre">root_path</span></code>.</li>
- <li><strong>defaults</strong> – an optional dictionary of default values</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="method">
- <dt id="flask.config.Config.from_envvar">
- <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>
- <dd><p>Loads a configuration from an environment variable pointing to
- a configuration file. This is basically just a shortcut with nicer
- error messages for this line of code:</p>
- <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">'YOURAPPLICATION_SETTINGS'</span><span class="p">])</span>
- </pre></div>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>variable_name</strong> – name of the environment variable</li>
- <li><strong>silent</strong> – set to <code class="docutils literal"><span class="pre">True</span></code> if you want silent failure for missing
- files.</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.config.Config.from_json">
- <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>
- <dd><p>Updates the values in the config from a JSON file. This function
- behaves as if the JSON object was a dictionary and passed to the
- <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>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>filename</strong> – the filename of the JSON file. This can either be an
- absolute filename or a filename relative to the
- root path.</li>
- <li><strong>silent</strong> – set to <code class="docutils literal"><span class="pre">True</span></code> if you want silent failure for missing
- files.</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.11.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.config.Config.from_mapping">
- <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>
- <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
- keys.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.11.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.config.Config.from_object">
- <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>
- <dd><p>Updates the values from the given object. An object can be of one
- of the following two types:</p>
- <ul class="simple">
- <li>a string: in this case the object with that name will be imported</li>
- <li>an actual object reference: that object is used directly</li>
- </ul>
- <p>Objects are usually either modules or classes.</p>
- <p>Just the uppercase variables in that object are stored in the config.
- Example usage:</p>
- <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">'yourapplication.default_config'</span><span class="p">)</span>
- <span class="kn">from</span> <span class="nn">yourapplication</span> <span class="k">import</span> <span class="n">default_config</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="n">default_config</span><span class="p">)</span>
- </pre></div>
- </div>
- <p>You should not use this function to load the actual configuration but
- rather configuration defaults. The actual config should be loaded
- 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
- package because the package might be installed system wide.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>obj</strong> – an import name or object</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="flask.config.Config.from_pyfile">
- <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>
- <dd><p>Updates the values in the config from a Python file. This function
- behaves as if the file was imported as module with the
- <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>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>filename</strong> – the filename of the config. This can either be an
- absolute filename or a filename relative to the
- root path.</li>
- <li><strong>silent</strong> – set to <code class="docutils literal"><span class="pre">True</span></code> if you want silent failure for missing
- files.</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7: </span><cite>silent</cite> parameter.</p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.config.Config.get_namespace">
- <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>
- <dd><p>Returns a dictionary containing a subset of configuration options
- that match the specified namespace/prefix. Example usage:</p>
- <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">'IMAGE_STORE_TYPE'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'fs'</span>
- <span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s1">'IMAGE_STORE_PATH'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'/var/app/images'</span>
- <span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s1">'IMAGE_STORE_BASE_URL'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'http://img.website.com'</span>
- <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">'IMAGE_STORE_'</span><span class="p">)</span>
- </pre></div>
- </div>
- <p>The resulting dictionary <cite>image_store_config</cite> would look like:</p>
- <div class="highlight-default"><div class="highlight"><pre><span></span><span class="p">{</span>
- <span class="s1">'type'</span><span class="p">:</span> <span class="s1">'fs'</span><span class="p">,</span>
- <span class="s1">'path'</span><span class="p">:</span> <span class="s1">'/var/app/images'</span><span class="p">,</span>
- <span class="s1">'base_url'</span><span class="p">:</span> <span class="s1">'http://img.website.com'</span>
- <span class="p">}</span>
- </pre></div>
- </div>
- <p>This is often useful when configuration options map directly to
- keyword arguments in functions or class constructors.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>namespace</strong> – a configuration namespace</li>
- <li><strong>lowercase</strong> – a flag indicating if the keys of the resulting
- dictionary should be lowercase</li>
- <li><strong>trim_namespace</strong> – a flag indicating if the keys of the resulting
- dictionary should not include the namespace</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.11.</span></p>
- </div>
- </dd></dl>
- </dd></dl>
- <dl class="class">
- <dt id="flask.config.ConfigAttribute">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
- <p>Makes an attribute forward to the config</p>
- </dd></dl>
- </div>
- </div>
- <div class="section" id="module-flask.ctx">
- <span id="flask-ctx-module"></span><h2>flask.ctx module<a class="headerlink" href="#module-flask.ctx" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-ctx">
- <h3>flask.ctx<a class="headerlink" href="#flask-ctx" title="Permalink to this headline">¶</a></h3>
- <p>Implements the objects required to keep the context.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="class">
- <dt id="flask.ctx.AppContext">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
- <p>The application context binds an application object implicitly
- to the current thread or greenlet, similar to how the
- <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
- context is also implicitly created if a request context is created
- but the application is not on top of the individual application
- context.</p>
- <dl class="method">
- <dt id="flask.ctx.AppContext.pop">
- <code class="descname">pop</code><span class="sig-paren">(</span><em>exc=<object object at 0x000001E1FDEFF780></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>
- <dd><p>Pops the app context.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.ctx.AppContext.push">
- <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>
- <dd><p>Binds the app context to the current context.</p>
- </dd></dl>
- </dd></dl>
- <dl class="class">
- <dt id="flask.ctx.RequestContext">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
- <p>The request context contains all request relevant information. It is
- created at the beginning of the request and pushed to the
- <cite>_request_ctx_stack</cite> and removed at the end of it. It will create the
- URL adapter and request object for the WSGI environment provided.</p>
- <p>Do not attempt to use this class directly, instead use
- <code class="xref py py-meth docutils literal"><span class="pre">test_request_context()</span></code> and
- <code class="xref py py-meth docutils literal"><span class="pre">request_context()</span></code> to create this object.</p>
- <p>When the request context is popped, it will evaluate all the
- functions registered on the application for teardown execution
- (<code class="xref py py-meth docutils literal"><span class="pre">teardown_request()</span></code>).</p>
- <p>The request context is automatically popped at the end of the request
- for you. In debug mode the request context is kept around if
- exceptions happen so that interactive debuggers have a chance to
- introspect the data. With 0.4 this can also be forced for requests
- that did not fail and outside of <code class="docutils literal"><span class="pre">DEBUG</span></code> mode. By setting
- <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
- context will not pop itself at the end of the request. This is used by
- the <code class="xref py py-meth docutils literal"><span class="pre">test_client()</span></code> for example to implement the
- deferred cleanup functionality.</p>
- <p>You might find this helpful for unittests where you need the
- information from the context local around for a little longer. Make
- sure to properly <code class="xref py py-meth docutils literal"><span class="pre">pop()</span></code> the stack yourself in
- that situation, otherwise your unittests will leak memory.</p>
- <dl class="method">
- <dt id="flask.ctx.RequestContext.auto_pop">
- <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>
- <dd></dd></dl>
- <dl class="method">
- <dt id="flask.ctx.RequestContext.copy">
- <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>
- <dd><p>Creates a copy of this request context with the same request object.
- This can be used to move a request context to a different greenlet.
- Because the actual request object is the same this cannot be used to
- move a request context to a different thread unless access to the
- request object is locked.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.10.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.ctx.RequestContext.g">
- <code class="descname">g</code><a class="headerlink" href="#flask.ctx.RequestContext.g" title="Permalink to this definition">¶</a></dt>
- <dd></dd></dl>
- <dl class="method">
- <dt id="flask.ctx.RequestContext.match_request">
- <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>
- <dd><p>Can be overridden by a subclass to hook into the matching
- of the request.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.ctx.RequestContext.pop">
- <code class="descname">pop</code><span class="sig-paren">(</span><em>exc=<object object at 0x000001E1FDEFF780></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>
- <dd><p>Pops the request context and unbinds it by doing that. This will
- also trigger the execution of functions registered by the
- <code class="xref py py-meth docutils literal"><span class="pre">teardown_request()</span></code> decorator.</p>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.9: </span>Added the <cite>exc</cite> argument.</p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.ctx.RequestContext.push">
- <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>
- <dd><p>Binds the request context to the current context.</p>
- </dd></dl>
- </dd></dl>
- <dl class="function">
- <dt id="flask.ctx.after_this_request">
- <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>
- <dd><p>Executes a function after this request. This is useful to modify
- response objects. The function is passed the response object and has
- to return the same or a new one.</p>
- <p>Example:</p>
- <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">'/'</span><span class="p">)</span>
- <span class="k">def</span> <span class="nf">index</span><span class="p">():</span>
- <span class="nd">@after_this_request</span>
- <span class="k">def</span> <span class="nf">add_header</span><span class="p">(</span><span class="n">response</span><span class="p">):</span>
- <span class="n">response</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s1">'X-Foo'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'Parachute'</span>
- <span class="k">return</span> <span class="n">response</span>
- <span class="k">return</span> <span class="s1">'Hello World!'</span>
- </pre></div>
- </div>
- <p>This is more useful if a function other than the view function wants to
- modify a response. For instance think of a decorator that wants to add
- some headers without converting the return value into a response object.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.9.</span></p>
- </div>
- </dd></dl>
- <dl class="function">
- <dt id="flask.ctx.copy_current_request_context">
- <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>
- <dd><p>A helper function that decorates a function to retain the current
- request context. This is useful when working with greenlets. The moment
- the function is decorated a copy of the request context is created and
- then pushed when the function is called.</p>
- <p>Example:</p>
- <div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">gevent</span>
- <span class="kn">from</span> <span class="nn">flask</span> <span class="k">import</span> <span class="n">copy_current_request_context</span>
- <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">'/'</span><span class="p">)</span>
- <span class="k">def</span> <span class="nf">index</span><span class="p">():</span>
- <span class="nd">@copy_current_request_context</span>
- <span class="k">def</span> <span class="nf">do_some_work</span><span class="p">():</span>
- <span class="c1"># do some work here, it can access flask.request like you</span>
- <span class="c1"># would otherwise in the view function.</span>
- <span class="o">...</span>
- <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>
- <span class="k">return</span> <span class="s1">'Regular response'</span>
- </pre></div>
- </div>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.10.</span></p>
- </div>
- </dd></dl>
- <dl class="function">
- <dt id="flask.ctx.has_app_context">
- <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>
- <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
- context. You can also just do a boolean check on the
- <code class="xref py py-data docutils literal"><span class="pre">current_app</span></code> object instead.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.9.</span></p>
- </div>
- </dd></dl>
- <dl class="function">
- <dt id="flask.ctx.has_request_context">
- <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>
- <dd><p>If you have code that wants to test if a request context is there or
- not this function can be used. For instance, you may want to take advantage
- of request information if the request object is available, but fail
- silently if it is unavailable.</p>
- <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>
- <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>
- <span class="bp">self</span><span class="o">.</span><span class="n">username</span> <span class="o">=</span> <span class="n">username</span>
- <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>
- <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>
- <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>
- </pre></div>
- </div>
- <p>Alternatively you can also just test any of the context bound objects
- (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>
- <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>
- <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>
- <span class="bp">self</span><span class="o">.</span><span class="n">username</span> <span class="o">=</span> <span class="n">username</span>
- <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>
- <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>
- <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>
- </pre></div>
- </div>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.7.</span></p>
- </div>
- </dd></dl>
- </div>
- </div>
- <div class="section" id="module-flask.debughelpers">
- <span id="flask-debughelpers-module"></span><h2>flask.debughelpers module<a class="headerlink" href="#module-flask.debughelpers" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-debughelpers">
- <h3>flask.debughelpers<a class="headerlink" href="#flask-debughelpers" title="Permalink to this headline">¶</a></h3>
- <p>Various helpers to make the development experience better.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="exception">
- <dt id="flask.debughelpers.DebugFilesKeyError">
- <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>
- <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>
- <p>Raised from request.files during debugging. The idea is that it can
- provide a better error message than just a generic KeyError/BadRequest.</p>
- </dd></dl>
- <dl class="exception">
- <dt id="flask.debughelpers.FormDataRoutingRedirect">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">AssertionError</span></code></p>
- <p>This exception is raised by Flask in debug mode if it detects a
- redirect caused by the routing system when the request method is not
- GET, HEAD or OPTIONS. Reasoning: form data will be dropped.</p>
- </dd></dl>
- <dl class="exception">
- <dt id="flask.debughelpers.UnexpectedUnicodeError">
- <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>
- <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>
- <p>Raised in places where we want some better error reporting for
- unexpected unicode or binary data.</p>
- </dd></dl>
- <dl class="function">
- <dt id="flask.debughelpers.attach_enctype_error_multidict">
- <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>
- <dd><p>Since Flask 0.8 we’re monkeypatching the files object in case a
- request is detected that does not use multipart form data but the files
- object is accessed.</p>
- </dd></dl>
- <dl class="function">
- <dt id="flask.debughelpers.explain_template_loading_attempts">
- <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>
- <dd><p>This should help developers understand what failed</p>
- </dd></dl>
- </div>
- </div>
- <div class="section" id="module-flask.exthook">
- <span id="flask-exthook-module"></span><h2>flask.exthook module<a class="headerlink" href="#module-flask.exthook" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-exthook">
- <h3>flask.exthook<a class="headerlink" href="#flask-exthook" title="Permalink to this headline">¶</a></h3>
- <p>Redirect imports for extensions. This module basically makes it possible
- for us to transition from flaskext.foo to flask_foo without having to
- force all extensions to upgrade at the same time.</p>
- <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
- 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
- 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>
- <p>We’re switching from namespace packages because it was just too painful for
- everybody involved.</p>
- <p>This is used by <cite>flask.ext</cite>.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="exception">
- <dt id="flask.exthook.ExtDeprecationWarning">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">DeprecationWarning</span></code></p>
- </dd></dl>
- <dl class="class">
- <dt id="flask.exthook.ExtensionImporter">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
- <p>This importer redirects imports from this submodule to other locations.
- This makes it possible to transition from the old flaskext.name to the
- newer flask_name without people having a hard time.</p>
- <dl class="method">
- <dt id="flask.exthook.ExtensionImporter.find_module">
- <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>
- <dd></dd></dl>
- <dl class="method">
- <dt id="flask.exthook.ExtensionImporter.install">
- <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>
- <dd></dd></dl>
- <dl class="method">
- <dt id="flask.exthook.ExtensionImporter.is_important_frame">
- <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>
- <dd><p>Checks a single frame if it’s important.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.exthook.ExtensionImporter.is_important_traceback">
- <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>
- <dd><p>Walks a traceback’s frames and checks if any of the frames
- originated in the given important module. If that is the case then we
- were able to import the module itself but apparently something went
- wrong when the module was imported. (Eg: import of an import failed).</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.exthook.ExtensionImporter.load_module">
- <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>
- <dd></dd></dl>
- </dd></dl>
- </div>
- </div>
- <div class="section" id="module-flask.globals">
- <span id="flask-globals-module"></span><h2>flask.globals module<a class="headerlink" href="#module-flask.globals" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-globals">
- <h3>flask.globals<a class="headerlink" href="#flask-globals" title="Permalink to this headline">¶</a></h3>
- <p>Defines all the global objects that are proxies to the current
- active context.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- <div class="section" id="module-flask.helpers">
- <span id="flask-helpers-module"></span><h2>flask.helpers module<a class="headerlink" href="#module-flask.helpers" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-helpers">
- <h3>flask.helpers<a class="headerlink" href="#flask-helpers" title="Permalink to this headline">¶</a></h3>
- <p>Implements various helpers.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="function">
- <dt id="flask.helpers.find_package">
- <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>
- <dd><p>Finds a package and returns the prefix (or None if the package is
- not installed) as well as the folder that contains the package or
- module as a tuple. The package path returned is the module that would
- have to be added to the pythonpath in order to make it possible to
- import the module. The prefix is the path below which a UNIX like
- folder structure exists (lib, share etc.).</p>
- </dd></dl>
- <dl class="function">
- <dt id="flask.helpers.flash">
- <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>
- <dd><p>Flashes a message to the next request. In order to remove the
- flashed message from the session and to display it to the user,
- 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>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.3: </span><cite>category</cite> parameter added.</p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>message</strong> – the message to be flashed.</li>
- <li><strong>category</strong> – the category for the message. The following values
- are recommended: <code class="docutils literal"><span class="pre">'message'</span></code> for any kind of message,
- <code class="docutils literal"><span class="pre">'error'</span></code> for errors, <code class="docutils literal"><span class="pre">'info'</span></code> for information
- messages and <code class="docutils literal"><span class="pre">'warning'</span></code> for warnings. However any
- kind of string can be used as category.</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="flask.helpers.get_debug_flag">
- <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>
- <dd></dd></dl>
- <dl class="function">
- <dt id="flask.helpers.get_flashed_messages">
- <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>
- <dd><p>Pulls all flashed messages from the session and returns them.
- Further calls in the same request to the function will return
- the same messages. By default just the messages are returned,
- but when <cite>with_categories</cite> is set to <code class="docutils literal"><span class="pre">True</span></code>, the return value will
- 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>
- <p>Filter the flashed messages to one or more categories by providing those
- categories in <cite>category_filter</cite>. This allows rendering categories in
- separate html blocks. The <cite>with_categories</cite> and <cite>category_filter</cite>
- arguments are distinct:</p>
- <ul class="simple">
- <li><cite>with_categories</cite> controls whether categories are returned with message
- 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>
- <li><cite>category_filter</cite> filters the messages down to only those matching the
- provided categories.</li>
- </ul>
- <p>See <span class="xref std std-ref">message-flashing-pattern</span> for examples.</p>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.3: </span><cite>with_categories</cite> parameter added.</p>
- </div>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.9: </span><cite>category_filter</cite> parameter added.</p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>with_categories</strong> – set to <code class="docutils literal"><span class="pre">True</span></code> to also receive categories.</li>
- <li><strong>category_filter</strong> – whitelist of categories to limit return values</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="flask.helpers.get_root_path">
- <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>
- <dd><p>Returns the path to a package or cwd if that cannot be found. This
- returns the path of a package or the folder that contains a module.</p>
- <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>
- </dd></dl>
- <dl class="function">
- <dt id="flask.helpers.get_template_attribute">
- <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>
- <dd><p>Loads a macro (or variable) a template exports. This can be used to
- invoke a macro from within Python code. If you for example have a
- template named <code class="file docutils literal"><span class="pre">_cider.html</span></code> with the following contents:</p>
- <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>
- </pre></div>
- </div>
- <p>You can access this from Python code like this:</p>
- <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">'_cider.html'</span><span class="p">,</span> <span class="s1">'hello'</span><span class="p">)</span>
- <span class="k">return</span> <span class="n">hello</span><span class="p">(</span><span class="s1">'World'</span><span class="p">)</span>
- </pre></div>
- </div>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.2.</span></p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>template_name</strong> – the name of the template</li>
- <li><strong>attribute</strong> – the name of the variable of macro to access</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="class">
- <dt id="flask.helpers.locked_cached_property">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
- <p>A decorator that converts a function into a lazy property. The
- function wrapped is called the first time to retrieve the result
- and then that calculated result is used the next time you access
- the value. Works like the one in Werkzeug but has a lock for
- thread safety.</p>
- </dd></dl>
- <dl class="function">
- <dt id="flask.helpers.make_response">
- <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>
- <dd><p>Sometimes it is necessary to set additional headers in a view. Because
- views do not have to return response objects but can return a value that
- is converted into a response object by Flask itself, it becomes tricky to
- add headers to it. This function can be called instead of using a return
- and you will get a response object which you can use to attach headers.</p>
- <p>If view looked like this and you want to add a new header:</p>
- <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">index</span><span class="p">():</span>
- <span class="k">return</span> <span class="n">render_template</span><span class="p">(</span><span class="s1">'index.html'</span><span class="p">,</span> <span class="n">foo</span><span class="o">=</span><span class="mi">42</span><span class="p">)</span>
- </pre></div>
- </div>
- <p>You can now do something like this:</p>
- <div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">index</span><span class="p">():</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">'index.html'</span><span class="p">,</span> <span class="n">foo</span><span class="o">=</span><span class="mi">42</span><span class="p">))</span>
- <span class="n">response</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s1">'X-Parachutes'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'parachutes are cool'</span>
- <span class="k">return</span> <span class="n">response</span>
- </pre></div>
- </div>
- <p>This function accepts the very same arguments you can return from a
- view function. This for example creates a response with a 404 error
- code:</p>
- <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">'not_found.html'</span><span class="p">),</span> <span class="mi">404</span><span class="p">)</span>
- </pre></div>
- </div>
- <p>The other use case of this function is to force the return value of a
- view function into a response which is helpful with view
- decorators:</p>
- <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>
- <span class="n">response</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s1">'X-Parachutes'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'parachutes are cool'</span>
- </pre></div>
- </div>
- <p>Internally this function does the following things:</p>
- <ul class="simple">
- <li>if no arguments are passed, it creates a new response argument</li>
- <li>if one argument is passed, <code class="xref py py-meth docutils literal"><span class="pre">flask.Flask.make_response()</span></code>
- is invoked with it.</li>
- <li>if more than one argument is passed, the arguments are passed
- to the <code class="xref py py-meth docutils literal"><span class="pre">flask.Flask.make_response()</span></code> function as tuple.</li>
- </ul>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.6.</span></p>
- </div>
- </dd></dl>
- <dl class="function">
- <dt id="flask.helpers.safe_join">
- <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>
- <dd><p>Safely join <cite>directory</cite> and <cite>filename</cite>.</p>
- <p>Example usage:</p>
- <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">'/wiki/<path:filename>'</span><span class="p">)</span>
- <span class="k">def</span> <span class="nf">wiki_page</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
- <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">'WIKI_FOLDER'</span><span class="p">],</span> <span class="n">filename</span><span class="p">)</span>
- <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">'rb'</span><span class="p">)</span> <span class="k">as</span> <span class="n">fd</span><span class="p">:</span>
- <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>
- </pre></div>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>directory</strong> – the base directory.</li>
- <li><strong>filename</strong> – the untrusted filename relative to that directory.</li>
- </ul>
- </td>
- </tr>
- <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
- would fall out of <cite>directory</cite>.</p>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="flask.helpers.send_file">
- <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>
- <dd><p>Sends the contents of a file to the client. This will use the
- most efficient method available and configured. By default it will
- try to use the WSGI server’s file_wrapper support. Alternatively
- you can set the application’s <code class="xref py py-attr docutils literal"><span class="pre">use_x_sendfile</span></code> attribute
- 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
- requires support of the underlying webserver for <code class="docutils literal"><span class="pre">X-Sendfile</span></code>.</p>
- <p>By default it will try to guess the mimetype for you, but you can
- also explicitly provide one. For extra security you probably want
- to send certain files as attachment (HTML for instance). The mimetype
- guessing requires a <cite>filename</cite> or an <cite>attachment_filename</cite> to be
- provided.</p>
- <p>Please never pass filenames to this function from user sources;
- 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>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.2.</span></p>
- </div>
- <div class="versionadded">
- <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
- added. The default behavior is now to attach etags.</p>
- </div>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.7: </span>mimetype guessing and etag support for file objects was
- deprecated because it was unreliable. Pass a filename if you are
- able to, otherwise attach an etag yourself. This functionality
- will be removed in Flask 1.0</p>
- </div>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.9: </span>cache_timeout pulls its default from application config, when None.</p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>filename_or_fp</strong> – the filename of the file to send in <cite>latin-1</cite>.
- This is relative to the <code class="xref py py-attr docutils literal"><span class="pre">root_path</span></code>
- if a relative path is specified.
- Alternatively a file object might be provided in
- which case <code class="docutils literal"><span class="pre">X-Sendfile</span></code> might not work and fall
- back to the traditional method. Make sure that the
- file pointer is positioned at the start of data to
- 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>
- <li><strong>mimetype</strong> – the mimetype of the file if provided, otherwise
- auto detection happens.</li>
- <li><strong>as_attachment</strong> – set to <code class="docutils literal"><span class="pre">True</span></code> if you want to send this file with
- a <code class="docutils literal"><span class="pre">Content-Disposition:</span> <span class="pre">attachment</span></code> header.</li>
- <li><strong>attachment_filename</strong> – the filename for the attachment if it
- differs from the file’s filename.</li>
- <li><strong>add_etags</strong> – set to <code class="docutils literal"><span class="pre">False</span></code> to disable attaching of etags.</li>
- <li><strong>conditional</strong> – set to <code class="docutils literal"><span class="pre">True</span></code> to enable conditional responses.</li>
- <li><strong>cache_timeout</strong> – the timeout in seconds for the headers. When <code class="docutils literal"><span class="pre">None</span></code>
- (default), this value is set by
- <code class="xref py py-meth docutils literal"><span class="pre">get_send_file_max_age()</span></code> of
- <code class="xref py py-data docutils literal"><span class="pre">current_app</span></code>.</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="flask.helpers.send_from_directory">
- <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>
- <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
- is a secure way to quickly expose static files from an upload folder
- or something similar.</p>
- <p>Example usage:</p>
- <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">'/uploads/<path:filename>'</span><span class="p">)</span>
- <span class="k">def</span> <span class="nf">download_file</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
- <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">'UPLOAD_FOLDER'</span><span class="p">],</span>
- <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>
- </pre></div>
- </div>
- <div class="admonition-sending-files-and-performance admonition">
- <p class="first admonition-title">Sending files and Performance</p>
- <p class="last">It is strongly recommended to activate either <code class="docutils literal"><span class="pre">X-Sendfile</span></code> support in
- your webserver or (if no authentication happens) to tell the webserver
- to serve files for the given path on its own without calling into the
- web application for improved performance.</p>
- </div>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.5.</span></p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>directory</strong> – the directory where all the files are stored.</li>
- <li><strong>filename</strong> – the filename relative to that directory to
- download.</li>
- <li><strong>options</strong> – optional keyword arguments that are directly
- 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>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="flask.helpers.stream_with_context">
- <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>
- <dd><p>Request contexts disappear when the response is started on the server.
- This is done for efficiency reasons and to make it less likely to encounter
- memory leaks with badly written WSGI middlewares. The downside is that if
- you are using streamed responses, the generator cannot access request bound
- information any more.</p>
- <p>This function however can help you keep the context around for longer:</p>
- <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>
- <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">'/stream'</span><span class="p">)</span>
- <span class="k">def</span> <span class="nf">streamed_response</span><span class="p">():</span>
- <span class="nd">@stream_with_context</span>
- <span class="k">def</span> <span class="nf">generate</span><span class="p">():</span>
- <span class="k">yield</span> <span class="s1">'Hello '</span>
- <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">'name'</span><span class="p">]</span>
- <span class="k">yield</span> <span class="s1">'!'</span>
- <span class="k">return</span> <span class="n">Response</span><span class="p">(</span><span class="n">generate</span><span class="p">())</span>
- </pre></div>
- </div>
- <p>Alternatively it can also be used around a specific generator:</p>
- <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>
- <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">'/stream'</span><span class="p">)</span>
- <span class="k">def</span> <span class="nf">streamed_response</span><span class="p">():</span>
- <span class="k">def</span> <span class="nf">generate</span><span class="p">():</span>
- <span class="k">yield</span> <span class="s1">'Hello '</span>
- <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">'name'</span><span class="p">]</span>
- <span class="k">yield</span> <span class="s1">'!'</span>
- <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>
- </pre></div>
- </div>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.9.</span></p>
- </div>
- </dd></dl>
- <dl class="function">
- <dt id="flask.helpers.total_seconds">
- <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>
- <dd><p>Returns the total seconds from a timedelta object.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>td</strong> (<em>timedelta</em>) – the timedelta to be converted in seconds</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">number of seconds</td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">int</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="flask.helpers.url_for">
- <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>
- <dd><p>Generates a URL to the given endpoint with the method provided.</p>
- <p>Variable arguments that are unknown to the target endpoint are appended
- to the generated URL as query arguments. If the value of a query argument
- is <code class="docutils literal"><span class="pre">None</span></code>, the whole pair is skipped. In case blueprints are active
- you can shortcut references to the same blueprint by prefixing the
- local endpoint with a dot (<code class="docutils literal"><span class="pre">.</span></code>).</p>
- <p>This will reference the index function local to the current blueprint:</p>
- <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">url_for</span><span class="p">(</span><span class="s1">'.index'</span><span class="p">)</span>
- </pre></div>
- </div>
- <p>For more information, head over to the <span class="xref std std-ref">Quickstart</span>.</p>
- <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
- 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>
- function results in a <code class="xref py py-exc docutils literal"><span class="pre">BuildError</span></code> when the current
- app does not have a URL for the given endpoint and values. When it does, the
- <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
- it is not <code class="docutils literal"><span class="pre">None</span></code>, which can return a string to use as the result of
- <cite>url_for</cite> (instead of <cite>url_for</cite>‘s default to raise the
- <code class="xref py py-exc docutils literal"><span class="pre">BuildError</span></code> exception) or re-raise the exception.
- An example:</p>
- <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>
- <span class="s2">"Looks up an external URL when `url_for` cannot build a URL."</span>
- <span class="c1"># This is an example of hooking the build_error_handler.</span>
- <span class="c1"># Here, lookup_url is some utility function you've built</span>
- <span class="c1"># which looks up the endpoint in some external URL registry.</span>
- <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>
- <span class="k">if</span> <span class="n">url</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
- <span class="c1"># External lookup did not have a URL.</span>
- <span class="c1"># Re-raise the BuildError, in context of original traceback.</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> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">exc_info</span><span class="p">()</span>
- <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>
- <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>
- <span class="k">else</span><span class="p">:</span>
- <span class="k">raise</span> <span class="n">error</span>
- <span class="c1"># url_for will use this result, instead of raising BuildError.</span>
- <span class="k">return</span> <span class="n">url</span>
- <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>
- </pre></div>
- </div>
- <p>Here, <cite>error</cite> is the instance of <code class="xref py py-exc docutils literal"><span class="pre">BuildError</span></code>, and
- <cite>endpoint</cite> and <cite>values</cite> are the arguments passed into <cite>url_for</cite>. Note
- that this is for building URLs outside the current application, and not for
- handling 404 NotFound errors.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.10: </span>The <cite>_scheme</cite> parameter was added.</p>
- </div>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.9: </span>The <cite>_anchor</cite> and <cite>_method</cite> parameters were added.</p>
- </div>
- <div class="versionadded">
- <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
- <code class="xref py py-exc docutils literal"><span class="pre">BuildError</span></code>.</p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>endpoint</strong> – the endpoint of the URL (name of the function)</li>
- <li><strong>values</strong> – the variable arguments of the URL rule</li>
- <li><strong>_external</strong> – if set to <code class="docutils literal"><span class="pre">True</span></code>, an absolute URL is generated. Server
- address can be changed via <code class="docutils literal"><span class="pre">SERVER_NAME</span></code> configuration variable which
- defaults to <cite>localhost</cite>.</li>
- <li><strong>_scheme</strong> – a string specifying the desired URL scheme. The <cite>_external</cite>
- 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
- behavior uses the same scheme as the current request, or
- <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
- request context is available. As of Werkzeug 0.10, this also can be set
- to an empty string to build protocol-relative URLs.</li>
- <li><strong>_anchor</strong> – if provided this is added as anchor to the URL.</li>
- <li><strong>_method</strong> – if provided this explicitly specifies an HTTP method.</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- </div>
- </div>
- <div class="section" id="module-flask.json">
- <span id="flask-json-module"></span><h2>flask.json module<a class="headerlink" href="#module-flask.json" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-jsonimpl">
- <h3>flask.jsonimpl<a class="headerlink" href="#flask-jsonimpl" title="Permalink to this headline">¶</a></h3>
- <p>Implementation helpers for the JSON support in Flask.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="function">
- <dt id="flask.json.dump">
- <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>
- <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>
- </dd></dl>
- <dl class="function">
- <dt id="flask.json.dumps">
- <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>
- <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’s
- configured encoder (<code class="xref py py-attr docutils literal"><span class="pre">json_encoder</span></code>) if there is an
- application on the stack.</p>
- <p>This function can return <code class="docutils literal"><span class="pre">unicode</span></code> strings or ascii-only bytestrings by
- default which coerce into unicode strings automatically. That behavior by
- default is controlled by the <code class="docutils literal"><span class="pre">JSON_AS_ASCII</span></code> configuration variable
- and can be overridden by the simplejson <code class="docutils literal"><span class="pre">ensure_ascii</span></code> parameter.</p>
- </dd></dl>
- <dl class="function">
- <dt id="flask.json.load">
- <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>
- <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>
- </dd></dl>
- <dl class="function">
- <dt id="flask.json.loads">
- <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>
- <dd><p>Unserialize a JSON object from a string <code class="docutils literal"><span class="pre">s</span></code> by using the application’s
- configured decoder (<code class="xref py py-attr docutils literal"><span class="pre">json_decoder</span></code>) if there is an
- application on the stack.</p>
- </dd></dl>
- <dl class="function">
- <dt id="flask.json.htmlsafe_dump">
- <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>
- <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>
- </dd></dl>
- <dl class="function">
- <dt id="flask.json.htmlsafe_dumps">
- <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>
- <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"><script></span></code>
- tags. It accepts the same arguments and returns a JSON string. Note that
- this is available in templates through the <code class="docutils literal"><span class="pre">|tojson</span></code> filter which will
- also mark the result as safe. Due to how this function escapes certain
- characters this is safe even if used outside of <code class="docutils literal"><span class="pre"><script></span></code> tags.</p>
- <p>The following characters are escaped in strings:</p>
- <ul class="simple">
- <li><code class="docutils literal"><span class="pre"><</span></code></li>
- <li><code class="docutils literal"><span class="pre">></span></code></li>
- <li><code class="docutils literal"><span class="pre">&</span></code></li>
- <li><code class="docutils literal"><span class="pre">'</span></code></li>
- </ul>
- <p>This makes it safe to embed such strings in any place in HTML with the
- notable exception of double quoted attributes. In that case single
- quote your attributes or HTML escape it in addition.</p>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.10: </span>This function’s return value is now always safe for HTML usage, even
- if outside of script tags or if used in XHTML. This rule does not
- hold true when using this function in HTML attributes that are double
- quoted. Always single quote attributes if you use the <code class="docutils literal"><span class="pre">|tojson</span></code>
- filter. Alternatively use <code class="docutils literal"><span class="pre">|tojson|forceescape</span></code>.</p>
- </div>
- </dd></dl>
- <dl class="class">
- <dt id="flask.json.JSONDecoder">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">simplejson.decoder.JSONDecoder</span></code></p>
- <p>The default JSON decoder. This one does not change the behavior from
- the default simplejson decoder. Consult the <code class="xref py py-mod docutils literal"><span class="pre">json</span></code> documentation
- for more information. This decoder is not only used for the load
- functions of this module but also <code class="xref py py-attr docutils literal"><span class="pre">Request</span></code>.</p>
- </dd></dl>
- <dl class="class">
- <dt id="flask.json.JSONEncoder">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">simplejson.encoder.JSONEncoder</span></code></p>
- <p>The default Flask JSON encoder. This one extends the default simplejson
- 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
- <code class="docutils literal"><span class="pre">Markup</span></code> objects which are serialized as RFC 822 datetime strings (same
- as the HTTP date format). In order to support more data types override the
- <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>
- <dl class="method">
- <dt id="flask.json.JSONEncoder.default">
- <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>
- <dd><p>Implement this method in a subclass such that it returns a
- serializable object for <code class="docutils literal"><span class="pre">o</span></code>, or calls the base implementation (to
- raise a <code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code>).</p>
- <p>For example, to support arbitrary iterators, you could implement
- default like this:</p>
- <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>
- <span class="k">try</span><span class="p">:</span>
- <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>
- <span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span>
- <span class="k">pass</span>
- <span class="k">else</span><span class="p">:</span>
- <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="n">iterable</span><span class="p">)</span>
- <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>
- </pre></div>
- </div>
- </dd></dl>
- </dd></dl>
- <dl class="function">
- <dt id="flask.json.jsonify">
- <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>
- <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
- life easier. It turns the JSON output into a <code class="xref py py-class docutils literal"><span class="pre">Response</span></code>
- object with the <em class="mimetype">application/json</em> mimetype. For convenience, it
- also converts multiple arguments into an array or multiple keyword arguments
- into a dict. This means that both <code class="docutils literal"><span class="pre">jsonify(1,2,3)</span></code> and
- <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>
- <p>For clarity, the JSON serialization behavior has the following differences
- 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>
- <ol class="arabic simple">
- <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>
- <li>Multiple arguments: Converted to an array before being passed 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>
- <li>Multiple keyword arguments: Converted to a dict before being passed 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>
- <li>Both args and kwargs: Behavior undefined and will throw an exception.</li>
- </ol>
- <p>Example usage:</p>
- <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>
- <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">'/_get_current_user'</span><span class="p">)</span>
- <span class="k">def</span> <span class="nf">get_current_user</span><span class="p">():</span>
- <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>
- <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>
- <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>
- </pre></div>
- </div>
- <p>This will send a JSON response like this to the browser:</p>
- <div class="highlight-default"><div class="highlight"><pre><span></span><span class="p">{</span>
- <span class="s2">"username"</span><span class="p">:</span> <span class="s2">"admin"</span><span class="p">,</span>
- <span class="s2">"email"</span><span class="p">:</span> <span class="s2">"admin@localhost"</span><span class="p">,</span>
- <span class="s2">"id"</span><span class="p">:</span> <span class="mi">42</span>
- <span class="p">}</span>
- </pre></div>
- </div>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.11: </span>Added support for serializing top-level arrays. This introduces a
- security risk in ancient browsers. See <span class="xref std std-ref">json-security</span> for details.</p>
- </div>
- <p>This function’s response will be pretty printed if it was not requested
- with <code class="docutils literal"><span class="pre">X-Requested-With:</span> <span class="pre">XMLHttpRequest</span></code> to simplify debugging unless
- the <code class="docutils literal"><span class="pre">JSONIFY_PRETTYPRINT_REGULAR</span></code> config parameter is set to false.
- Compressed (not pretty) formatting currently means no indents and no
- spaces after separators.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.2.</span></p>
- </div>
- </dd></dl>
- </div>
- </div>
- <div class="section" id="module-flask.logging">
- <span id="flask-logging-module"></span><h2>flask.logging module<a class="headerlink" href="#module-flask.logging" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-logging">
- <h3>flask.logging<a class="headerlink" href="#flask-logging" title="Permalink to this headline">¶</a></h3>
- <p>Implements the logging support for Flask.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="function">
- <dt id="flask.logging.create_logger">
- <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>
- <dd><p>Creates a logger for the given application. This logger works
- similar to a regular Python logger but changes the effective logging
- level based on the application’s debug flag. Furthermore this
- function also removes all attached handlers in case there was a
- logger with the log name before.</p>
- </dd></dl>
- </div>
- </div>
- <div class="section" id="module-flask.sessions">
- <span id="flask-sessions-module"></span><h2>flask.sessions module<a class="headerlink" href="#module-flask.sessions" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-sessions">
- <h3>flask.sessions<a class="headerlink" href="#flask-sessions" title="Permalink to this headline">¶</a></h3>
- <p>Implements cookie based sessions based on itsdangerous.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="class">
- <dt id="flask.sessions.NullSession">
- <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>
- <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>
- <p>Class used to generate nicer error messages if sessions are not
- available. Will still allow read-only access to the empty session
- but fail on setting.</p>
- <dl class="method">
- <dt id="flask.sessions.NullSession.clear">
- <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>
- <dd></dd></dl>
- <dl class="method">
- <dt id="flask.sessions.NullSession.pop">
- <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>
- <dd></dd></dl>
- <dl class="method">
- <dt id="flask.sessions.NullSession.popitem">
- <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>
- <dd></dd></dl>
- <dl class="method">
- <dt id="flask.sessions.NullSession.setdefault">
- <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>
- <dd></dd></dl>
- <dl class="method">
- <dt id="flask.sessions.NullSession.update">
- <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>
- <dd></dd></dl>
- </dd></dl>
- <dl class="class">
- <dt id="flask.sessions.SecureCookieSession">
- <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>
- <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>
- <p>Base class for sessions based on signed cookies.</p>
- </dd></dl>
- <dl class="class">
- <dt id="flask.sessions.SecureCookieSessionInterface">
- <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>
- <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>
- <p>The default session interface that stores sessions in signed cookies
- through the <code class="xref py py-mod docutils literal"><span class="pre">itsdangerous</span></code> module.</p>
- <dl class="staticmethod">
- <dt id="flask.sessions.SecureCookieSessionInterface.digest_method">
- <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>
- <dd><p>the hash function to use for the signature. The default is sha1</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.sessions.SecureCookieSessionInterface.get_signing_serializer">
- <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>
- <dd></dd></dl>
- <dl class="attribute">
- <dt id="flask.sessions.SecureCookieSessionInterface.key_derivation">
- <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>
- <dd><p>the name of the itsdangerous supported key derivation. The default
- is hmac.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.sessions.SecureCookieSessionInterface.open_session">
- <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>
- <dd></dd></dl>
- <dl class="attribute">
- <dt id="flask.sessions.SecureCookieSessionInterface.salt">
- <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>
- <dd><p>the salt that should be applied on top of the secret key for the
- signing of cookie based sessions.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.sessions.SecureCookieSessionInterface.save_session">
- <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>
- <dd></dd></dl>
- <dl class="attribute">
- <dt id="flask.sessions.SecureCookieSessionInterface.serializer">
- <code class="descname">serializer</code><em class="property"> = <flask.sessions.TaggedJSONSerializer object at 0x000001E1821A4C18></em><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.serializer" title="Permalink to this definition">¶</a></dt>
- <dd><p>A python serializer for the payload. The default is a compact
- JSON derived serializer with support for some extra Python types
- such as datetime objects or tuples.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.sessions.SecureCookieSessionInterface.session_class">
- <code class="descname">session_class</code><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.session_class" title="Permalink to this definition">¶</a></dt>
- <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>
- </dd></dl>
- </dd></dl>
- <dl class="class">
- <dt id="flask.sessions.SessionInterface">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
- <p>The basic interface you have to implement in order to replace the
- default session interface which uses werkzeug’s securecookie
- implementation. The only methods you have to implement are
- <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
- useful defaults which you don’t need to change.</p>
- <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
- provide a dictionary like interface plus the properties and methods
- 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
- and adding that mixin:</p>
- <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>
- <span class="k">pass</span>
- </pre></div>
- </div>
- <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
- <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
- if the session support cannot work because some requirement is not
- 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
- will complain that the secret key was not set.</p>
- <p>To replace the session interface on an application all you have to do
- is to assign <code class="xref py py-attr docutils literal"><span class="pre">flask.Flask.session_interface</span></code>:</p>
- <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>
- <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>
- </pre></div>
- </div>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.8.</span></p>
- </div>
- <dl class="method">
- <dt id="flask.sessions.SessionInterface.get_cookie_domain">
- <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>
- <dd><p>Helpful helper method that returns the cookie domain that should
- be used for the session cookie if session cookies are used.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.sessions.SessionInterface.get_cookie_httponly">
- <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>
- <dd><p>Returns True if the session cookie should be httponly. This
- currently just returns the value of the <code class="docutils literal"><span class="pre">SESSION_COOKIE_HTTPONLY</span></code>
- config var.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.sessions.SessionInterface.get_cookie_path">
- <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>
- <dd><p>Returns the path for which the cookie should be valid. The
- default implementation uses the value from the <code class="docutils literal"><span class="pre">SESSION_COOKIE_PATH</span></code>
- config var if it’s set, and falls back to <code class="docutils literal"><span class="pre">APPLICATION_ROOT</span></code> or
- uses <code class="docutils literal"><span class="pre">/</span></code> if it’s <code class="docutils literal"><span class="pre">None</span></code>.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.sessions.SessionInterface.get_cookie_secure">
- <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>
- <dd><p>Returns True if the cookie should be secure. This currently
- just returns the value of the <code class="docutils literal"><span class="pre">SESSION_COOKIE_SECURE</span></code> setting.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.sessions.SessionInterface.get_expiration_time">
- <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>
- <dd><p>A helper method that returns an expiration date for the session
- or <code class="docutils literal"><span class="pre">None</span></code> if the session is linked to the browser session. The
- default implementation returns now + the permanent session
- lifetime configured on the application.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.sessions.SessionInterface.is_null_session">
- <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>
- <dd><p>Checks if a given object is a null session. Null sessions are
- not asked to be saved.</p>
- <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>
- by default.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.sessions.SessionInterface.make_null_session">
- <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>
- <dd><p>Creates a null session which acts as a replacement object if the
- real session support could not be loaded due to a configuration
- error. This mainly aids the user experience because the job of the
- null session is to still support lookup without complaining but
- modifications are answered with a helpful error message of what
- failed.</p>
- <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>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.sessions.SessionInterface.null_session_class">
- <code class="descname">null_session_class</code><a class="headerlink" href="#flask.sessions.SessionInterface.null_session_class" title="Permalink to this definition">¶</a></dt>
- <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
- be created when a null session is requested. Likewise the
- <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
- this type.</p>
- <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>
- </dd></dl>
- <dl class="method">
- <dt id="flask.sessions.SessionInterface.open_session">
- <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>
- <dd><p>This method has to be implemented and must either return <code class="docutils literal"><span class="pre">None</span></code>
- in case the loading failed because of a configuration error or an
- instance of a session object which implements a dictionary like
- 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>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.sessions.SessionInterface.pickle_based">
- <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>
- <dd><p>A flag that indicates if the session interface is pickle based.
- This can be used by flask extensions to make a decision in regards
- to how to deal with the session object.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.10.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.sessions.SessionInterface.save_session">
- <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>
- <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>
- at the end of the request. This is still called during a request
- context so if you absolutely need access to the request you can do
- that.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.sessions.SessionInterface.should_set_cookie">
- <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>
- <dd><p>Indicates whether a cookie should be set now or not. This is
- used by session backends to figure out if they should emit a
- set-cookie header or not. The default behavior is controlled by
- the <code class="docutils literal"><span class="pre">SESSION_REFRESH_EACH_REQUEST</span></code> config variable. If
- it’s set to <code class="docutils literal"><span class="pre">False</span></code> then a cookie is only set if the session is
- modified, if set to <code class="docutils literal"><span class="pre">True</span></code> it’s always set if the session is
- permanent.</p>
- <p>This check is usually skipped if sessions get deleted.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.11.</span></p>
- </div>
- </dd></dl>
- </dd></dl>
- <dl class="class">
- <dt id="flask.sessions.SessionMixin">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
- <p>Expands a basic dictionary with an accessors that are expected
- by Flask extensions and users for the session.</p>
- <dl class="attribute">
- <dt id="flask.sessions.SessionMixin.modified">
- <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>
- <dd><p>for some backends this will always be <code class="docutils literal"><span class="pre">True</span></code>, but some backends will
- default this to false and detect changes in the dictionary for as
- long as changes do not happen on mutable structures in the session.
- The default mixin implementation just hardcodes <code class="docutils literal"><span class="pre">True</span></code> in.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.sessions.SessionMixin.new">
- <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>
- <dd><p>some session backends can tell you if a session is new, but that is
- not necessarily guaranteed. Use with caution. The default mixin
- implementation just hardcodes <code class="docutils literal"><span class="pre">False</span></code> in.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.sessions.SessionMixin.permanent">
- <code class="descname">permanent</code><a class="headerlink" href="#flask.sessions.SessionMixin.permanent" title="Permalink to this definition">¶</a></dt>
- <dd><p>this reflects the <code class="docutils literal"><span class="pre">'_permanent'</span></code> key in the dict.</p>
- </dd></dl>
- </dd></dl>
- <dl class="class">
- <dt id="flask.sessions.TaggedJSONSerializer">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
- <p>A customized JSON serializer that supports a few extra types that
- we take for granted when serializing (tuples, markup objects, datetime).</p>
- <dl class="method">
- <dt id="flask.sessions.TaggedJSONSerializer.dumps">
- <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>
- <dd></dd></dl>
- <dl class="method">
- <dt id="flask.sessions.TaggedJSONSerializer.loads">
- <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>
- <dd></dd></dl>
- </dd></dl>
- </div>
- </div>
- <div class="section" id="module-flask.signals">
- <span id="flask-signals-module"></span><h2>flask.signals module<a class="headerlink" href="#module-flask.signals" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-signals">
- <h3>flask.signals<a class="headerlink" href="#flask-signals" title="Permalink to this headline">¶</a></h3>
- <p>Implements signals based on blinker if available, otherwise
- falls silently back to a noop.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="class">
- <dt id="flask.signals.Namespace">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
- <dl class="method">
- <dt id="flask.signals.Namespace.signal">
- <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>
- <dd></dd></dl>
- </dd></dl>
- </div>
- </div>
- <div class="section" id="module-flask.templating">
- <span id="flask-templating-module"></span><h2>flask.templating module<a class="headerlink" href="#module-flask.templating" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-templating">
- <h3>flask.templating<a class="headerlink" href="#flask-templating" title="Permalink to this headline">¶</a></h3>
- <p>Implements the bridge to Jinja2.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="class">
- <dt id="flask.templating.DispatchingJinjaLoader">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">jinja2.loaders.BaseLoader</span></code></p>
- <p>A loader that looks for templates in the application and all
- the blueprint folders.</p>
- <dl class="method">
- <dt id="flask.templating.DispatchingJinjaLoader.get_source">
- <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>
- <dd></dd></dl>
- <dl class="method">
- <dt id="flask.templating.DispatchingJinjaLoader.list_templates">
- <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>
- <dd></dd></dl>
- </dd></dl>
- <dl class="class">
- <dt id="flask.templating.Environment">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">jinja2.environment.Environment</span></code></p>
- <p>Works like a regular Jinja2 environment but has some additional
- knowledge of how Flask’s blueprint works so that it can prepend the
- name of the blueprint to referenced templates if necessary.</p>
- </dd></dl>
- <dl class="function">
- <dt id="flask.templating.render_template">
- <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>
- <dd><p>Renders a template from the template folder with the given
- context.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>template_name_or_list</strong> – the name of the template to be
- rendered, or an iterable with template names
- the first one existing will be rendered</li>
- <li><strong>context</strong> – the variables that should be available in the
- context of the template.</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="function">
- <dt id="flask.templating.render_template_string">
- <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>
- <dd><p>Renders a template from the given template source string
- with the given context. Template variables will be autoescaped.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>source</strong> – the source code of the template to be
- rendered</li>
- <li><strong>context</strong> – the variables that should be available in the
- context of the template.</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- </div>
- </div>
- <div class="section" id="module-flask.testing">
- <span id="flask-testing-module"></span><h2>flask.testing module<a class="headerlink" href="#module-flask.testing" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-testing">
- <h3>flask.testing<a class="headerlink" href="#flask-testing" title="Permalink to this headline">¶</a></h3>
- <p>Implements test support helpers. This module is lazily imported
- and usually not used in production environments.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="class">
- <dt id="flask.testing.FlaskClient">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">werkzeug.test.Client</span></code></p>
- <p>Works like a regular Werkzeug test client but has some knowledge about
- how Flask works to defer the cleanup of the request context stack to the
- 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
- information about how to use this class refer to
- <code class="xref py py-class docutils literal"><span class="pre">werkzeug.test.Client</span></code>.</p>
- <p>Basic usage is outlined in the <span class="xref std std-ref">testing</span> chapter.</p>
- <dl class="method">
- <dt id="flask.testing.FlaskClient.open">
- <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>
- <dd></dd></dl>
- <dl class="attribute">
- <dt id="flask.testing.FlaskClient.preserve_context">
- <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>
- <dd></dd></dl>
- <dl class="method">
- <dt id="flask.testing.FlaskClient.session_transaction">
- <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>
- <dd><p>When used in combination with a <code class="docutils literal"><span class="pre">with</span></code> statement this opens a
- session transaction. This can be used to modify the session that
- the test client uses. Once the <code class="docutils literal"><span class="pre">with</span></code> block is left the session is
- stored back.</p>
- <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>
- <span class="n">session</span><span class="p">[</span><span class="s1">'value'</span><span class="p">]</span> <span class="o">=</span> <span class="mi">42</span>
- </pre></div>
- </div>
- <p>Internally this is implemented by going through a temporary test
- request context and since session handling could depend on
- request variables this function accepts the same arguments as
- <code class="xref py py-meth docutils literal"><span class="pre">test_request_context()</span></code> which are directly
- passed through.</p>
- </dd></dl>
- </dd></dl>
- <dl class="function">
- <dt id="flask.testing.make_test_environ_builder">
- <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>
- <dd><p>Creates a new test builder with some application defaults thrown in.</p>
- </dd></dl>
- </div>
- </div>
- <div class="section" id="module-flask.views">
- <span id="flask-views-module"></span><h2>flask.views module<a class="headerlink" href="#module-flask.views" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-views">
- <h3>flask.views<a class="headerlink" href="#flask-views" title="Permalink to this headline">¶</a></h3>
- <p>This module provides class-based views inspired by the ones in Django.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="class">
- <dt id="flask.views.MethodView">
- <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>
- <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>
- <p>Like a regular class-based view but that dispatches requests to
- particular methods. For instance if you implement a method called
- <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
- 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
- forward your request to that. Also <code class="xref py py-attr docutils literal"><span class="pre">options</span></code> is set for you
- automatically:</p>
- <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>
- <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
- <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">'counter'</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
- <span class="k">def</span> <span class="nf">post</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
- <span class="n">session</span><span class="p">[</span><span class="s1">'counter'</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">'counter'</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>
- <span class="k">return</span> <span class="s1">'OK'</span>
- <span class="n">app</span><span class="o">.</span><span class="n">add_url_rule</span><span class="p">(</span><span class="s1">'/counter'</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">'counter'</span><span class="p">))</span>
- </pre></div>
- </div>
- <dl class="method">
- <dt id="flask.views.MethodView.dispatch_request">
- <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>
- <dd></dd></dl>
- </dd></dl>
- <dl class="class">
- <dt id="flask.views.MethodViewType">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">type</span></code></p>
- </dd></dl>
- <dl class="class">
- <dt id="flask.views.View">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
- <p>Alternative way to use view functions. A subclass has to implement
- <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
- 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
- do not have to be passed to the <code class="xref py py-meth docutils literal"><span class="pre">add_url_rule()</span></code>
- method explicitly:</p>
- <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>
- <span class="n">methods</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'GET'</span><span class="p">]</span>
- <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>
- <span class="k">return</span> <span class="s1">'Hello </span><span class="si">%s</span><span class="s1">!'</span> <span class="o">%</span> <span class="n">name</span>
- <span class="n">app</span><span class="o">.</span><span class="n">add_url_rule</span><span class="p">(</span><span class="s1">'/hello/<name>'</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">'myview'</span><span class="p">))</span>
- </pre></div>
- </div>
- <p>When you want to decorate a pluggable view you will have to either do that
- when the view function is created (by wrapping the return value of
- <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>
- <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>
- <span class="n">methods</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'GET'</span><span class="p">]</span>
- <span class="n">decorators</span> <span class="o">=</span> <span class="p">[</span><span class="n">superuser_required</span><span class="p">]</span>
- <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="o">...</span>
- </pre></div>
- </div>
- <p>The decorators stored in the decorators list are applied one after another
- when the view function is created. Note that you can <em>not</em> use the class
- based decorators since those would decorate the view class and not the
- generated view function!</p>
- <dl class="classmethod">
- <dt id="flask.views.View.as_view">
- <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>
- <dd><p>Converts the class into an actual view function that can be used
- with the routing system. Internally this generates a function on the
- 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
- 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>
- <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
- constructor of the class.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.views.View.decorators">
- <code class="descname">decorators</code><em class="property"> = ()</em><a class="headerlink" href="#flask.views.View.decorators" title="Permalink to this definition">¶</a></dt>
- <dd><p>The canonical way to decorate class-based views is to decorate the
- return value of as_view(). However since this moves parts of the
- logic from the class declaration to the place where it’s hooked
- into the routing system.</p>
- <p>You can place one or more decorators in this list and whenever the
- view function is created the result is automatically decorated.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.8.</span></p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="flask.views.View.dispatch_request">
- <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>
- <dd><p>Subclasses have to override this method to implement the
- actual view function code. This method is called with all
- the arguments from the URL rule.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.views.View.methods">
- <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>
- <dd><p>A list of methods this view can handle.</p>
- </dd></dl>
- </dd></dl>
- </div>
- </div>
- <div class="section" id="module-flask.wrappers">
- <span id="flask-wrappers-module"></span><h2>flask.wrappers module<a class="headerlink" href="#module-flask.wrappers" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask-wrappers">
- <h3>flask.wrappers<a class="headerlink" href="#flask-wrappers" title="Permalink to this headline">¶</a></h3>
- <p>Implements the WSGI wrappers (request and response).</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="class">
- <dt id="flask.wrappers.Request">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">werkzeug.wrappers.Request</span></code></p>
- <p>The request object used by default in Flask. Remembers the
- matched endpoint and view arguments.</p>
- <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
- the request object used you can subclass this and set
- <code class="xref py py-attr docutils literal"><span class="pre">request_class</span></code> to your subclass.</p>
- <p>The request object is a <code class="xref py py-class docutils literal"><span class="pre">Request</span></code> subclass and
- provides all of the attributes Werkzeug defines plus a few Flask
- specific ones.</p>
- <dl class="attribute">
- <dt id="flask.wrappers.Request.blueprint">
- <code class="descname">blueprint</code><a class="headerlink" href="#flask.wrappers.Request.blueprint" title="Permalink to this definition">¶</a></dt>
- <dd><p>The name of the current blueprint</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.wrappers.Request.endpoint">
- <code class="descname">endpoint</code><a class="headerlink" href="#flask.wrappers.Request.endpoint" title="Permalink to this definition">¶</a></dt>
- <dd><p>The endpoint that matched the request. This in combination with
- <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
- modified URL. If an exception happened when matching, this will
- be <code class="docutils literal"><span class="pre">None</span></code>.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.wrappers.Request.get_json">
- <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>
- <dd><p>Parses the incoming JSON request data and returns it. By default
- this function will return <code class="docutils literal"><span class="pre">None</span></code> if the mimetype is not
- <em class="mimetype">application/json</em> but this can be overridden by the
- <code class="docutils literal"><span class="pre">force</span></code> parameter. If parsing fails the
- <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
- invoked.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>force</strong> – if set to <code class="docutils literal"><span class="pre">True</span></code> the mimetype is ignored.</li>
- <li><strong>silent</strong> – if set to <code class="docutils literal"><span class="pre">True</span></code> this method will fail silently
- and return <code class="docutils literal"><span class="pre">None</span></code>.</li>
- <li><strong>cache</strong> – if set to <code class="docutils literal"><span class="pre">True</span></code> the parsed JSON data is remembered
- on the request.</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.wrappers.Request.is_json">
- <code class="descname">is_json</code><a class="headerlink" href="#flask.wrappers.Request.is_json" title="Permalink to this definition">¶</a></dt>
- <dd><p>Indicates if this request is JSON or not. By default a request
- is considered to include JSON data if the mimetype is
- <em class="mimetype">application/json</em> or <em class="mimetype">application/*+json</em>.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.11.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.wrappers.Request.json">
- <code class="descname">json</code><a class="headerlink" href="#flask.wrappers.Request.json" title="Permalink to this definition">¶</a></dt>
- <dd><p>If the mimetype is <em class="mimetype">application/json</em> this will contain the
- parsed JSON data. Otherwise this will be <code class="docutils literal"><span class="pre">None</span></code>.</p>
- <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>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.wrappers.Request.max_content_length">
- <code class="descname">max_content_length</code><a class="headerlink" href="#flask.wrappers.Request.max_content_length" title="Permalink to this definition">¶</a></dt>
- <dd><p>Read-only view of the <code class="docutils literal"><span class="pre">MAX_CONTENT_LENGTH</span></code> config key.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.wrappers.Request.module">
- <code class="descname">module</code><a class="headerlink" href="#flask.wrappers.Request.module" title="Permalink to this definition">¶</a></dt>
- <dd><p>The name of the current module if the request was dispatched
- to an actual module. This is deprecated functionality, use blueprints
- instead.</p>
- </dd></dl>
- <dl class="method">
- <dt id="flask.wrappers.Request.on_json_loading_failed">
- <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>
- <dd><p>Called if decoding of the JSON data failed. The return value of
- 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
- default implementation just raises a <code class="xref py py-class docutils literal"><span class="pre">BadRequest</span></code> exception.</p>
- <div class="versionchanged">
- <p><span class="versionmodified">Changed in version 0.10: </span>Removed buggy previous behavior of generating a random JSON
- response. If you want that behavior back you can trivially
- add it by subclassing.</p>
- </div>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.8.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.wrappers.Request.routing_exception">
- <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>
- <dd><p>If matching the URL failed, this is the exception that will be
- raised / was raised as part of the request handling. This is
- usually a <code class="xref py py-exc docutils literal"><span class="pre">NotFound</span></code> exception or
- something similar.</p>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.wrappers.Request.url_rule">
- <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>
- <dd><p>The internal URL rule that matched the request. This can be
- useful to inspect which methods are allowed for the URL from
- a before/after handler (<code class="docutils literal"><span class="pre">request.url_rule.methods</span></code>) etc.</p>
- <div class="versionadded">
- <p><span class="versionmodified">New in version 0.6.</span></p>
- </div>
- </dd></dl>
- <dl class="attribute">
- <dt id="flask.wrappers.Request.view_args">
- <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>
- <dd><p>A dict of view arguments that matched the request. If an exception
- happened when matching, this will be <code class="docutils literal"><span class="pre">None</span></code>.</p>
- </dd></dl>
- </dd></dl>
- <dl class="class">
- <dt id="flask.wrappers.Response">
- <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>
- <dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">werkzeug.wrappers.Response</span></code></p>
- <p>The response object that is used by default in Flask. Works like the
- response object from Werkzeug but is set to have an HTML mimetype by
- default. Quite often you don’t have to create this object yourself because
- <code class="xref py py-meth docutils literal"><span class="pre">make_response()</span></code> will take care of that for you.</p>
- <p>If you want to replace the response object used you can subclass this and
- set <code class="xref py py-attr docutils literal"><span class="pre">response_class</span></code> to your subclass.</p>
- <dl class="attribute">
- <dt id="flask.wrappers.Response.default_mimetype">
- <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>
- <dd></dd></dl>
- </dd></dl>
- </div>
- </div>
- <div class="section" id="module-flask">
- <span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-flask" title="Permalink to this headline">¶</a></h2>
- <div class="section" id="flask">
- <h3>flask<a class="headerlink" href="#flask" title="Permalink to this headline">¶</a></h3>
- <p>A microframework based on Werkzeug. It’s extensively documented
- and follows best practice patterns.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">copyright:</th><td class="field-body"><ol class="first loweralpha simple" start="3">
- <li>2015 by Armin Ronacher.</li>
- </ol>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
- <div class="sphinxsidebarwrapper">
- <h3><a href="../index.html">Table Of Contents</a></h3>
- <ul>
- <li><a class="reference internal" href="#">flask package</a><ul>
- <li><a class="reference internal" href="#subpackages">Subpackages</a></li>
- <li><a class="reference internal" href="#submodules">Submodules</a></li>
- <li><a class="reference internal" href="#module-flask.app">flask.app module</a><ul>
- <li><a class="reference internal" href="#flask-app">flask.app</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask.blueprints">flask.blueprints module</a><ul>
- <li><a class="reference internal" href="#flask-blueprints">flask.blueprints</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask.cli">flask.cli module</a><ul>
- <li><a class="reference internal" href="#flask-cli">flask.cli</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask.config">flask.config module</a><ul>
- <li><a class="reference internal" href="#flask-config">flask.config</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask.ctx">flask.ctx module</a><ul>
- <li><a class="reference internal" href="#flask-ctx">flask.ctx</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask.debughelpers">flask.debughelpers module</a><ul>
- <li><a class="reference internal" href="#flask-debughelpers">flask.debughelpers</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask.exthook">flask.exthook module</a><ul>
- <li><a class="reference internal" href="#flask-exthook">flask.exthook</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask.globals">flask.globals module</a><ul>
- <li><a class="reference internal" href="#flask-globals">flask.globals</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask.helpers">flask.helpers module</a><ul>
- <li><a class="reference internal" href="#flask-helpers">flask.helpers</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask.json">flask.json module</a><ul>
- <li><a class="reference internal" href="#flask-jsonimpl">flask.jsonimpl</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask.logging">flask.logging module</a><ul>
- <li><a class="reference internal" href="#flask-logging">flask.logging</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask.sessions">flask.sessions module</a><ul>
- <li><a class="reference internal" href="#flask-sessions">flask.sessions</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask.signals">flask.signals module</a><ul>
- <li><a class="reference internal" href="#flask-signals">flask.signals</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask.templating">flask.templating module</a><ul>
- <li><a class="reference internal" href="#flask-templating">flask.templating</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask.testing">flask.testing module</a><ul>
- <li><a class="reference internal" href="#flask-testing">flask.testing</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask.views">flask.views module</a><ul>
- <li><a class="reference internal" href="#flask-views">flask.views</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask.wrappers">flask.wrappers module</a><ul>
- <li><a class="reference internal" href="#flask-wrappers">flask.wrappers</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#module-flask">Module contents</a><ul>
- <li><a class="reference internal" href="#flask">flask</a></li>
- </ul>
- </li>
- </ul>
- </li>
- </ul>
- <div class="relations">
- <h3>Related Topics</h3>
- <ul>
- <li><a href="../index.html">Documentation overview</a><ul>
- </ul></li>
- </ul>
- </div>
- <div role="note" aria-label="source link">
- <h3>This Page</h3>
- <ul class="this-page-menu">
- <li><a href="../_sources/flask/flask.txt"
- rel="nofollow">Show Source</a></li>
- </ul>
- </div>
- <div id="searchbox" style="display: none" role="search">
- <h3>Quick search</h3>
- <form class="search" action="../search.html" method="get">
- <div><input type="text" name="q" /></div>
- <div><input type="submit" value="Go" /></div>
- <input type="hidden" name="check_keywords" value="yes" />
- <input type="hidden" name="area" value="default" />
- </form>
- </div>
- <script type="text/javascript">$('#searchbox').show(0);</script>
- </div>
- </div>
- <div class="clearer"></div>
- </div>
- <div class="footer">
- ©2016, Author.
-
- |
- Powered by <a href="http://sphinx-doc.org/">Sphinx 1.4.8</a>
- & <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.9</a>
-
- |
- <a href="../_sources/flask/flask.txt"
- rel="nofollow">Page source</a>
- </div>
-
-
- </body>
- </html>
|