Skip to content
Myr

Started working on documentation.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

So far just the stable parts :)

authored by Armin Ronacher · committed by Armin Ronacher · parent b15ad39 · Browse files · 9 files+641 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

9 files+641 added−9 removed

  • other:+641 added−9 removed

9 files+641 added−9 removed

added:docs/.gitignore+1 added
1_build
added:docs/api.rst+15 added
1API2===34.. module:: flask56This part of the documentation covers all the interfaces of Flask. For7parts where Flask depends on external libraries, we document the most8important right here and provide links to the canonical documentation.91011General Structure12-----------------1314.. autoclass:: Flask15 :members:
added:docs/conf.py+236 added
1# -*- coding: utf-8 -*-2#3# Flask documentation build configuration file, created by4# sphinx-quickstart on Tue Apr 6 15:24:58 2010.5#6# This file is execfile()d with the current directory set to its containing dir.7#8# Note that not all possible configuration values are present in this9# autogenerated file.10#11# All configuration values have a default; values that are commented out12# serve to show the default.1314import sys, os1516# If extensions (or modules to document with autodoc) are in another directory,17# add these directories to sys.path here. If the directory is relative to the18# documentation root, use os.path.abspath to make it absolute, like shown here.19#sys.path.append(os.path.abspath('.'))2021# -- General configuration -----------------------------------------------------2223# If your documentation needs a minimal Sphinx version, state it here.24#needs_sphinx = '1.0'2526# Add any Sphinx extension module names here, as strings. They can be extensions27# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.28extensions = ['sphinx.ext.autodoc']2930# Add any paths that contain templates here, relative to this directory.31templates_path = ['_templates']3233# The suffix of source filenames.34source_suffix = '.rst'3536# The encoding of source files.37#source_encoding = 'utf-8-sig'3839# The master toctree document.40master_doc = 'index'4142# General information about the project.43project = u'Flask'44copyright = u'2010, Armin Ronacher'4546import pkg_resources4748# The version info for the project you're documenting, acts as replacement for49# |version| and |release|, also used in various other places throughout the50# built documents.51release = __import__('pkg_resources').get_distribution('Flask').version52version = '.'.join(release.split('.')[:2])5354# The language for content autogenerated by Sphinx. Refer to documentation55# for a list of supported languages.56#language = None5758# There are two options for replacing |today|: either, you set today to some59# non-false value, then it is used:60#today = ''61# Else, today_fmt is used as the format for a strftime call.62#today_fmt = '%B %d, %Y'6364# List of patterns, relative to source directory, that match files and65# directories to ignore when looking for source files.66exclude_patterns = ['_build']6768# The reST default role (used for this markup: `text`) to use for all documents.69#default_role = None7071# If true, '()' will be appended to :func: etc. cross-reference text.72#add_function_parentheses = True7374# If true, the current module name will be prepended to all description75# unit titles (such as .. function::).76#add_module_names = True7778# If true, sectionauthor and moduleauthor directives will be shown in the79# output. They are ignored by default.80#show_authors = False8182# The name of the Pygments (syntax highlighting) style to use.83pygments_style = 'sphinx'8485# A list of ignored prefixes for module index sorting.86#modindex_common_prefix = []878889# -- Options for HTML output ---------------------------------------------------9091# The theme to use for HTML and HTML Help pages. Major themes that come with92# Sphinx are currently 'default' and 'sphinxdoc'.93html_theme = 'nature'9495# Theme options are theme-specific and customize the look and feel of a theme96# further. For a list of options available for each theme, see the97# documentation.98#html_theme_options = {}99100# Add any paths that contain custom themes here, relative to this directory.101#html_theme_path = []102103# The name for this set of Sphinx documents. If None, it defaults to104# "<project> v<release> documentation".105#html_title = None106107# A shorter title for the navigation bar. Default is the same as html_title.108#html_short_title = None109110# The name of an image file (relative to this directory) to place at the top111# of the sidebar.112#html_logo = None113114# The name of an image file (within the static path) to use as favicon of the115# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32116# pixels large.117#html_favicon = None118119# Add any paths that contain custom static files (such as style sheets) here,120# relative to this directory. They are copied after the builtin static files,121# so a file named "default.css" will overwrite the builtin "default.css".122html_static_path = ['_static']123124# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,125# using the given strftime format.126#html_last_updated_fmt = '%b %d, %Y'127128# If true, SmartyPants will be used to convert quotes and dashes to129# typographically correct entities.130#html_use_smartypants = True131132# Custom sidebar templates, maps document names to template names.133#html_sidebars = {}134135# Additional templates that should be rendered to pages, maps page names to136# template names.137#html_additional_pages = {}138139# If false, no module index is generated.140#html_use_modindex = True141142# If false, no index is generated.143#html_use_index = True144145# If true, the index is split into individual pages for each letter.146#html_split_index = False147148# If true, links to the reST sources are added to the pages.149#html_show_sourcelink = True150151# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.152#html_show_sphinx = True153154# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.155#html_show_copyright = True156157# If true, an OpenSearch description file will be output, and all pages will158# contain a <link> tag referring to it. The value of this option must be the159# base URL from which the finished HTML is served.160#html_use_opensearch = ''161162# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").163#html_file_suffix = ''164165# Output file base name for HTML help builder.166htmlhelp_basename = 'Flaskdoc'167168169# -- Options for LaTeX output --------------------------------------------------170171# The paper size ('letter' or 'a4').172#latex_paper_size = 'letter'173174# The font size ('10pt', '11pt' or '12pt').175#latex_font_size = '10pt'176177# Grouping the document tree into LaTeX files. List of tuples178# (source start file, target name, title, author, documentclass [howto/manual]).179latex_documents = [180 ('index', 'Flask.tex', u'Flask Documentation',181 u'Armin Ronacher', 'manual'),182]183184# The name of an image file (relative to this directory) to place at the top of185# the title page.186#latex_logo = None187188# For "manual" documents, if this is true, then toplevel headings are parts,189# not chapters.190#latex_use_parts = False191192# Additional stuff for the LaTeX preamble.193#latex_preamble = ''194195# Documents to append as an appendix to all manuals.196#latex_appendices = []197198# If false, no module index is generated.199#latex_use_modindex = True200201202# -- Options for Epub output ---------------------------------------------------203204# Bibliographic Dublin Core info.205#epub_title = ''206#epub_author = ''207#epub_publisher = ''208#epub_copyright = ''209210# The language of the text. It defaults to the language option211# or en if the language is not set.212#epub_language = ''213214# The scheme of the identifier. Typical schemes are ISBN or URL.215#epub_scheme = ''216217# The unique identifier of the text. This can be a ISBN number218# or the project homepage.219#epub_identifier = ''220221# A unique identification for the text.222#epub_uid = ''223224# HTML files that should be inserted before the pages created by sphinx.225# The format is a list of tuples containing the path and title.226#epub_pre_files = []227228# HTML files shat should be inserted after the pages created by sphinx.229# The format is a list of tuples containing the path and title.230#epub_post_files = []231232# A list of files that should not be packed into the epub file.233#epub_exclude_files = []234235# The depth of the table of contents in toc.ncx.236#epub_tocdepth = 3
added:docs/index.rst+11 added
1Welcome to Flask2================34Welcome to Flask's documentation.56Contents:78.. toctree::9 :maxdepth: 21011 api
added:docs/make.bat+139 added
1@ECHO OFF23REM Command file for Sphinx documentation45if "%SPHINXBUILD%" == "" (6 set SPHINXBUILD=sphinx-build7)8set BUILDDIR=_build9set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .10if NOT "%PAPER%" == "" (11 set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%12)1314if "%1" == "" goto help1516if "%1" == "help" (17 :help18 echo.Please use `make ^<target^>` where ^<target^> is one of19 echo. html to make standalone HTML files20 echo. dirhtml to make HTML files named index.html in directories21 echo. singlehtml to make a single large HTML file22 echo. pickle to make pickle files23 echo. json to make JSON files24 echo. htmlhelp to make HTML files and a HTML help project25 echo. qthelp to make HTML files and a qthelp project26 echo. devhelp to make HTML files and a Devhelp project27 echo. epub to make an epub28 echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter29 echo. changes to make an overview over all changed/added/deprecated items30 echo. linkcheck to check all external links for integrity31 echo. doctest to run all doctests embedded in the documentation if enabled32 goto end33)3435if "%1" == "clean" (36 for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i37 del /q /s %BUILDDIR%\*38 goto end39)4041if "%1" == "html" (42 %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html43 echo.44 echo.Build finished. The HTML pages are in %BUILDDIR%/html.45 goto end46)4748if "%1" == "dirhtml" (49 %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml50 echo.51 echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.52 goto end53)5455if "%1" == "singlehtml" (56 %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml57 echo.58 echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.59 goto end60)6162if "%1" == "pickle" (63 %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle64 echo.65 echo.Build finished; now you can process the pickle files.66 goto end67)6869if "%1" == "json" (70 %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json71 echo.72 echo.Build finished; now you can process the JSON files.73 goto end74)7576if "%1" == "htmlhelp" (77 %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp78 echo.79 echo.Build finished; now you can run HTML Help Workshop with the ^80.hhp project file in %BUILDDIR%/htmlhelp.81 goto end82)8384if "%1" == "qthelp" (85 %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp86 echo.87 echo.Build finished; now you can run "qcollectiongenerator" with the ^88.qhcp project file in %BUILDDIR%/qthelp, like this:89 echo.^> qcollectiongenerator %BUILDDIR%\qthelp\Flask.qhcp90 echo.To view the help file:91 echo.^> assistant -collectionFile %BUILDDIR%\qthelp\Flask.ghc92 goto end93)9495if "%1" == "devhelp" (96 %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% _build/devhelp97 echo.98 echo.Build finished.99 goto end100)101102if "%1" == "epub" (103 %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub104 echo.105 echo.Build finished. The epub file is in %BUILDDIR%/epub.106 goto end107)108109if "%1" == "latex" (110 %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex111 echo.112 echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.113 goto end114)115116if "%1" == "changes" (117 %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes118 echo.119 echo.The overview file is in %BUILDDIR%/changes.120 goto end121)122123if "%1" == "linkcheck" (124 %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck125 echo.126 echo.Link check complete; look for any errors in the above output ^127or in %BUILDDIR%/linkcheck/output.txt.128 goto end129)130131if "%1" == "doctest" (132 %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest133 echo.134 echo.Testing of doctests in the sources finished, look at the ^135results in %BUILDDIR%/doctest/output.txt.136 goto end137)138139:end
added:docs/Makefile+118 added
1# Makefile for Sphinx documentation2#34# You can set these variables from the command line.5SPHINXOPTS =6SPHINXBUILD = sphinx-build7PAPER =8BUILDDIR = _build910# Internal variables.11PAPEROPT_a4 = -D latex_paper_size=a412PAPEROPT_letter = -D latex_paper_size=letter13ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .1415.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp epub latex changes linkcheck doctest1617help:18 @echo "Please use \`make <target>' where <target> is one of"19 @echo " html to make standalone HTML files"20 @echo " dirhtml to make HTML files named index.html in directories"21 @echo " singlehtml to make a single large HTML file"22 @echo " pickle to make pickle files"23 @echo " json to make JSON files"24 @echo " htmlhelp to make HTML files and a HTML help project"25 @echo " qthelp to make HTML files and a qthelp project"26 @echo " devhelp to make HTML files and a Devhelp project"27 @echo " epub to make an epub"28 @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"29 @echo " latexpdf to make LaTeX files and run them through pdflatex"30 @echo " changes to make an overview of all changed/added/deprecated items"31 @echo " linkcheck to check all external links for integrity"32 @echo " doctest to run all doctests embedded in the documentation (if enabled)"3334clean:35 -rm -rf $(BUILDDIR)/*3637html:38 $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html39 @echo40 @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."4142dirhtml:43 $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml44 @echo45 @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."4647singlehtml:48 $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml49 @echo50 @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."5152pickle:53 $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle54 @echo55 @echo "Build finished; now you can process the pickle files."5657json:58 $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json59 @echo60 @echo "Build finished; now you can process the JSON files."6162htmlhelp:63 $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp64 @echo65 @echo "Build finished; now you can run HTML Help Workshop with the" \66 ".hhp project file in $(BUILDDIR)/htmlhelp."6768qthelp:69 $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp70 @echo71 @echo "Build finished; now you can run "qcollectiongenerator" with the" \72 ".qhcp project file in $(BUILDDIR)/qthelp, like this:"73 @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Flask.qhcp"74 @echo "To view the help file:"75 @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Flask.qhc"7677devhelp:78 $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) _build/devhelp79 @echo80 @echo "Build finished."81 @echo "To view the help file:"82 @echo "# mkdir -p $$HOME/.local/share/devhelp/Flask"83 @echo "# ln -s _build/devhelp $$HOME/.local/share/devhelp/Flask"84 @echo "# devhelp"8586epub:87 $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub88 @echo89 @echo "Build finished. The epub file is in $(BUILDDIR)/epub."9091latex:92 $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex93 @echo94 @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."95 @echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \96 "run these through (pdf)latex."9798latexpdf: latex99 $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) _build/latex100 @echo "Running LaTeX files through pdflatex..."101 make -C _build/latex all-pdf102 @echo "pdflatex finished; the PDF files are in _build/latex."103104changes:105 $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes106 @echo107 @echo "The overview file is in $(BUILDDIR)/changes."108109linkcheck:110 $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck111 @echo112 @echo "Link check complete; look for any errors in the above output " \113 "or in $(BUILDDIR)/linkcheck/output.txt."114115doctest:116 $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest117 @echo "Testing of doctests in the sources finished, look at the " \118 "results in $(BUILDDIR)/doctest/output.txt."
modified:examples/minitwit/minitwit.py+1 added-1 removed
55 unmodified lines
5657def gravatar_url(email, size=80):58 """Return the gravatar image for the given email address"""59 return 'http://www.gravatar.com/avatar/%s?d=identicon&s=%d' % \60 (md5(email.lower().encode('utf-8')).hexdigest(), size)60 (md5(email.strip().lower().encode('utf-8')).hexdigest(), size)616263@app.request_init64def before_request():
164 unmodified lines
modified:.gitignore+1 added
1.DS_Store2*.pyc3*.pyo4env5*.egg-info
modified:flask.py+119 added-8 removed
123 unmodified lines
124125126class Flask(object):127 """The flask object implements a WSGI application and acts as the central128 object. It is passed the name of the module or package of the application129 and optionally a configuration. When it's created it sets up the130 template engine and provides ways to register view functions.128 object. It is passed the name of the module or package of the129 application. Once it is created it will act as a central registry for130 the view functions, the URL rules, template configuration and much more.131132 The name of the package is used to resolve resources from inside the133 package or the folder the module is contained in depending on if the134 package parameter resolves to an actual python package (a folder with135 an `__init__.py` file inside) or a standard module (just a `.py` file).136137 For more information about resource loading, see :func:`open_resource`.138139 Usually you create a :class:`Flask` instance in your main module or140 in the `__init__.py` file of your package like this::141142 from flask import Flask143 app = Flask(__name__)144 """145146 #: the class that is used for request objects147 request_class = FlaskRequest
20 unmodified lines
168 extensions=['jinja2.ext.autoescape', 'jinja2.ext.with_']169 )170171 def __init__(self, package_name):172 #: the debug flag. Set this to `True` to enable debugging of173 #: the application. In debug mode the debugger will kick in174 #: when an unhandled exception ocurrs and the integrated server175 #: will automatically reload the application if changes in the176 #: code are detected.177 self.debug = False178179 #: the name of the package or module. Do not change this once180 #: it was set by the constructor.181 self.package_name = package_name182183 #: a dictionary of all view functions registered. The keys will184 #: be function names which are also used to generate URLs and185 #: the values are the function objects themselves.186 #: to register a view function, use the :meth:`route` decorator.187 self.view_functions = {}188189 #: a dictionary of all registered error handlers. The key is190 #: be the error code as integer, the value the function that191 #: should handle that error.192 #: To register a error handler, use the :meth:`errorhandler`193 #: decorator.194 self.error_handlers = {}195196 #: a list of functions that should be called at the beginning197 #: of the request before request dispatching kicks in. This198 #: can for example be used to open database connections or199 #: getting hold of the currently logged in user.200 #: To register a function here, use the :meth:`request_init`201 #: decorator.202 self.request_init_funcs = []203204 #: a list of functions that are called at the end of the205 #: request. Tha function is passed the current response206 #: object and modify it in place or replace it.207 #: To register a function here use the :meth:`request_shtdown`208 #: decorator.209 self.request_shutdown_funcs = []210 self.url_map = Map()211212 if self.static_path is not None:213 self.url_map.add(Rule(self.static_path + '/<filename>',214 build_only=True, endpoint='static'))215216 #: the Jinja2 environment. It is created from the217 #: :attr:`jinja_options` and the loader that is returned218 #: by the :meth:`create_jinja_loader` function.219 self.jinja_env = Environment(loader=self.create_jinja_loader(),220 **self.jinja_options)221 self.jinja_env.globals.update(222 url_for=url_for,
11 unmodified lines
234 """235 return PackageLoader(self.package_name)236237 def run(self, host='localhost', port=5000, **options):190 """Runs the application on a local development server"""238 """Runs the application on a local development server. If the239 :attr:`debug` flag is set the server will automatically reload240 for code changes and show a debugger in case an exception happened.241 """242 from werkzeug import run_simple243 if 'debug' in options:244 self.debug = options.pop('debug')245 if self.static_path is not None:
10 unmodified lines
256 from werkzeug import Client257 return Client(self, self.response_class, use_cookies=True)258259 def open_resource(self, resource):209 """Opens a resource from the application's resource folder"""260 """Opens a resource from the application's resource folder. To see261 how this works, consider the following folder structure::262263 /myapplication.py264 /schemal.sql265 /static266 /style.css267 /template268 /layout.html269 /index.html270271 If you want to open the `schema.sql` file you would do the272 following::273274 with app.open_resource('schema.sql') as f:275 contents = f.read()276 do_something_with(contents)277 """278 return pkg_resources.resource_stream(self.package_name, resource)279280 def open_session(self, request):213 """Creates or opens a new session. Default implementation requires214 that `securecookie.secret_key` is set.281 """Creates or opens a new session. Default implementation stores all282 session data in a signed cookie. This requires that the283 :attr:`secret_key` is set.284 """285 key = self.secret_key286 if key is not None:287 return SecureCookie.load_cookie(request, self.session_cookie_name,288 secret_key=key)289290 def save_session(self, session, response):222 """Saves the session if it needs updates."""291 """Saves the session if it needs updates. For the default292 implementation, check :meth:`open_session`.293 """294 if session is not None:295 session.save_cookie(response, self.session_cookie_name)296297 def route(self, rule, **options):
2 unmodified lines
300301 @app.route('/')302 def index():303 return 'Hello World'304305 Variables parts in the route can be specified with angular306 brackets (``/user/<username>``). By default a variable part307 in the URL accepts any string without a slash however a differnt308 converter can be specified as well by using ``<converter:name>``.309310 Variable parts are passed to the view function as keyword311 arguments.312313 The following converters are possible:314315 =========== ===========================================316 `int` accepts integers317 `float` like `int` but for floating point values318 `path` like the default but also accepts slashes319 =========== ===========================================320321 Here some examples::322323 @app.route('/')324 def index():325 pass326327 @app.route('/<username>')328 def show_user(username):329 pass330331 @app.route('/post/<int:post_id>')332 def show_post(post_id):333 pass334335 The :meth:`route` decorator accepts a couple of other arguments336 as well:337338 :param methods: a list of methods this rule should be limited339 to (``GET``, ``POST`` etc.)340 :param subdomain: specifies the rule for the subdoain in case341 subdomain matching is in use.342 :param strict_slashes: can be used to disable the strict slashes343 setting for this rule. See above.344 """345 def decorator(f):346 if 'endpoint' not in options:347 options['endpoint'] = f.__name__
120 unmodified lines