docs/conf.py
@@ -85,7 +85,7 @@ master_doc = 'index' # General substitutions. project = 'The Pyramid Web Application Development Framework' project = 'The Pyramid Web Framework' thisyear = datetime.datetime.now().year copyright = '2008-%s, Agendaless Consulting' % thisyear @@ -179,7 +179,7 @@ # The name for this set of Sphinx documents. If None, it defaults to # "<project> v<release> documentation". html_title = 'The Pyramid Web Application Development Framework v%s' % release html_title = 'The Pyramid Web Framework v%s' % release # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = 'Home' @@ -251,7 +251,7 @@ # (source start file, target name, title, author, document class [howto/manual]). latex_documents = [ ('latexindex', 'pyramid.tex', 'The Pyramid Web Application Development Framework', 'The Pyramid Web Framework', 'Chris McDonough', 'manual'), ] @@ -491,7 +491,7 @@ # -- Options for Epub output --------------------------------------------------- # Bibliographic Dublin Core info. epub_title = 'The Pyramid Web Application Development Framework, Version %s' \ epub_title = 'The Pyramid Web Framework, Version %s' \ % release epub_author = 'Chris McDonough' epub_publisher = 'Agendaless Consulting' @@ -509,7 +509,7 @@ epub_identifier = '0615445675' # A unique identification for the text. epub_uid = 'The Pyramid Web Application Development Framework, Version %s' \ epub_uid = 'The Pyramid Web Framework, Version %s' \ % release # HTML files that should be inserted before the pages created by sphinx. # The format is a list of tuples containing the path and title. docs/copyright.rst
@@ -1,7 +1,7 @@ Copyright, Trademarks, and Attributions ======================================= *The Pyramid Web Application Development Framework, Version 1.1* *The Pyramid Web Framework, Version 1.1* by Chris McDonough docs/getting_started/quick_glance.rst
@@ -2,19 +2,47 @@ Quick Glance ============ Pyramid lets you start small and finish big. The :doc:`index` guide Pyramid lets you start small and finish big. This :doc:`index` guide walks you through many of the key features. Let's put the emphasis on *start* by doing a quick tour through Pyramid. This *Quick Glance* is shorthand, snippet-oriented. It is not intended as full example. Instead, the other chapters will provide complete examples. This *Quick Glance* is provides snippets instead of full examples. For working code, see the *Getting Started* chapters on each topic. .. note:: Like the rest of Getting Started, we're using Python 3 in our samples. You can too, or you can use Python 2.7. Setup ===== This is just a "quick glance", so we won't kill ourselves showing installation details. The guides fully cover each topic, including setup. In a nutshell: .. code-block:: bash $ pyvenv-3.3 env33 $ source env33/bin/activate $ curl -O http://python-distribute.org/distribute_setup.py $ python3.3 ./distribute_setup.py $ rm distribute* $ easy_install-3.3 pip $ pip-3.3 install pyramid We use Python 3.3's builtin virtual environment tool ``pyvenv`` to make an isolated Python. It is so isolated, we don't have package installation tools! After setting those up and cleaning up, we install Pyramid into our virtual environment. .. note:: Note the use of ``3.3`` on many of the commands, as a way to emphasize in this document which versions of the commands we are using. This is optional. The Smallest ============ @@ -506,14 +534,183 @@ test setup and teardown. Our one test imports the view, makes a dummy request, and sees if the view returns what we expected. Logging ======= It's important to know what is going on inside our web application. In development we might need to collect some output. In production, we might need to detect situations when other people use the site. We need *logging*. Fortunately Pyramid uses the normal Python approach to logging. The scaffold generated, in your ``development.ini``, a number of lines that configure the logging for you to some reasonable defaults. You then see messages sent by Pyramid (for example, when a new request comes in.) Maybe you would like to log messages in your code? In your Python module, import and setup the logging: .. code-block:: python import logging log = logging.getLogger(__name__) You can now, in your code, log messages: .. code-block:: python log.debug('Some Message') This will log ``Some Message`` at a ``debug`` log level, to the application-configured logger in your ``development.ini``. What controls that? These sections in the configuration file: .. code-block:: ini [loggers] keys = root, hello_world [logger_hello_world] level = DEBUG handlers = qualname = hello_world Our application, a package named ``hello_world``, is setup as a logger and configured to log messages at a ``DEBUG`` or higher level. Sessions ======== When people use your web application, they frequently perform a task that requires semi-permanent data to be saved. For example,a shopping cart. These are frequently called *sessions*. Pyramid has basic built-in support for sessions, with add-ons such as *Beaker* (or your own custom sessioning engine) that provide richer session support. For the built-in session support, you first import the "factory" which provides the sessioning: .. code-block:: python from pyramid.session import UnencryptedCookieSessionFactoryConfig my_session_factory = UnencryptedCookieSessionFactoryConfig('itsaseekreet') We tell the configuration system that this is the source of our sessioning support when setting up the ``Configurator``: .. code-block:: python config = Configurator(session_factory = my_session_factory) This now lets us use the session in our application code: .. code-block:: python session = request.session if 'abc' in session: session['fred'] = 'yes' Databases ========= Web applications mean data. Data means databases. Frequently SQL databases. SQL Databases frequently mean an "ORM" (object-relational mapper.) In Python, ORM usually leads to the mega-quality *SQLAlchemy*, a Python package that greatly eases working with databases. Pyramid and SQLAlchemy are great friends. That friendship includes a scaffold! .. code-block:: bash $ pcreate --scaffold alchemy hello_sqlalchemy $ cd hello_sqlalchemy $ python3.3 setup.py develop We now have a working sample SQLAlchemy application with all dependencies installed. The sample project provides a console script to initialize a SQLite database with tables. Let's run it and then start the application: .. code-block:: bash $ initialize_hello_sqlalchemy_db development.ini $ pserve development.ini We can now visit our sample at `http://localhost:6543/ <http://localhost:6543/>`_. Some choices that the scaffold helped us with: - A ``setup.py`` with appropriate dependencies - Connection strings and integration in our ``development.ini`` file - A console script which we ran above to initialize the database - The SQLAlchemy engine integrated into the ``Configurator`` on application startup - Python modules for the SQLAlchemy models and the Pyramid views that go with them - Some unit tests...yummy! As mentioned above, an ORM is software that eases the mapping of database structures into a programming language. SQLAlchemy uses models for this, and its scaffold generated a sample model: .. code-block:: python class MyModel(Base): __tablename__ = 'models' id = Column(Integer, primary_key=True) name = Column(Text, unique=True) value = Column(Integer) def __init__(self, name, value): self.name = name self.value = value The Python module also includes this: .. code-block:: python from zope.sqlalchemy import ZopeTransactionExtension The generated application includes the optional support for ``pyramid_tm``, a unique transaction monitor that integrates your database transactions with your code for transparent rollback and commit. View code, which mediates the logic between web requests and the rest of the system, can then easily get at the data: .. code-block:: python one = DBSession.query(MyModel).filter(MyModel.name == 'one').first() - logging Forms ===== - resources, asset specs, tests, Developers have lots of opinions about forms, and thus there are many form libraries for Python. Pyramid doesn't directly bundle a form library, but *Deform* is a popular choice. Let's see it in action. First we install it: sessions, logging, special views databases, forms, security .. code-block:: bash $ pip-3.3 install deform Authentication ============== Authorization ============= Notes @@ -534,6 +731,6 @@ - Debugging - Template reloading - Explain and link to WSGI, Python Packages - Explain and link to WSGI, Python Packages - Richer routing docs/getting_started/quick_glance/hello_world/hello_world/templates/mytemplate.jinja2
@@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>The Pyramid Web Application Development Framework</title> <title>The Pyramid Web Framework</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <meta name="keywords" content="python web application" /> <meta name="description" content="pyramid web application" /> @@ -21,14 +21,14 @@ <body> <div id="wrap"> <div id="header"> <div class="header">The Pyramid Web Application Development Framework</div> <div class="header">The Pyramid Web Framework</div> </div> <div id="top"> <div class="top align-center"> <img src="{{request.application_url}}/static/logo.png" width="300" height="80" alt="Logo"/> <p class="app-welcome"> Welcome to <span class="app-name">{{project}}</span>, an application generated by<br/> the Pyramid web application development framework. the Pyramid Web Framework. </p> </div> </div> docs/getting_started/top_ten.rst
@@ -28,3 +28,5 @@ - Asset specifications - Traversal - Transactions docs/index.rst
@@ -1,7 +1,7 @@ .. _index: ================================================= The Pyramid Web Application Development Framework The Pyramid Web Framework ================================================= :app:`Pyramid` is a small, fast, down-to-earth Python web application docs/narr/MyProject/myproject/templates/mytemplate.pt
@@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal"> <head> <title>The Pyramid Web Application Development Framework</title> <title>The Pyramid Web Framework</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <meta name="keywords" content="python web application" /> <meta name="description" content="pyramid web application" /> @@ -24,7 +24,7 @@ <div class="middle align-center"> <p class="app-welcome"> Welcome to <span class="app-name">${project}</span>, an application generated by<br/> the Pyramid web application development framework. the Pyramid Web Framework. </p> </div> </div> docs/tutorials/wiki/src/authorization/tutorial/templates/mytemplate.pt
@@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal"> <head> <title>The Pyramid Web Application Development Framework</title> <title>The Pyramid Web Framework</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <meta name="keywords" content="python web application" /> <meta name="description" content="pyramid web application" /> @@ -24,7 +24,7 @@ <div class="middle align-center"> <p class="app-welcome"> Welcome to <span class="app-name">${project}</span>, an application generated by<br/> the Pyramid web application development framework. the Pyramid Web Framework. </p> </div> </div> docs/tutorials/wiki/src/basiclayout/tutorial/templates/mytemplate.pt
@@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal"> <head> <title>The Pyramid Web Application Development Framework</title> <title>The Pyramid Web Framework</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <meta name="keywords" content="python web application" /> <meta name="description" content="pyramid web application" /> @@ -24,7 +24,7 @@ <div class="middle align-center"> <p class="app-welcome"> Welcome to <span class="app-name">${project}</span>, an application generated by<br/> the Pyramid web application development framework. the Pyramid Web Framework. </p> </div> </div> docs/tutorials/wiki/src/models/tutorial/templates/mytemplate.pt
@@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal"> <head> <title>The Pyramid Web Application Development Framework</title> <title>The Pyramid Web Framework</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <meta name="keywords" content="python web application" /> <meta name="description" content="pyramid web application" /> @@ -24,7 +24,7 @@ <div class="middle align-center"> <p class="app-welcome"> Welcome to <span class="app-name">${project}</span>, an application generated by<br/> the Pyramid web application development framework. the Pyramid Web Framework. </p> </div> </div> docs/tutorials/wiki/src/tests/tutorial/templates/mytemplate.pt
@@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal"> <head> <title>The Pyramid Web Application Development Framework</title> <title>The Pyramid Web Framework</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <meta name="keywords" content="python web application" /> <meta name="description" content="pyramid web application" /> @@ -24,7 +24,7 @@ <div class="middle align-center"> <p class="app-welcome"> Welcome to <span class="app-name">${project}</span>, an application generated by<br/> the Pyramid web application development framework. the Pyramid Web Framework. </p> </div> </div> docs/tutorials/wiki/src/views/tutorial/templates/mytemplate.pt
@@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal"> <head> <title>The Pyramid Web Application Development Framework</title> <title>The Pyramid Web Framework</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <meta name="keywords" content="python web application" /> <meta name="description" content="pyramid web application" /> @@ -24,7 +24,7 @@ <div class="middle align-center"> <p class="app-welcome"> Welcome to <span class="app-name">${project}</span>, an application generated by<br/> the Pyramid web application development framework. the Pyramid Web Framework. </p> </div> </div> docs/tutorials/wiki2/src/authorization/tutorial/templates/mytemplate.pt
@@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal"> <head> <title>The Pyramid Web Application Development Framework</title> <title>The Pyramid Web Framework</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <meta name="keywords" content="python web application" /> <meta name="description" content="pyramid web application" /> @@ -24,7 +24,7 @@ <div class="middle align-center"> <p class="app-welcome"> Welcome to <span class="app-name">${project}</span>, an application generated by<br/> the Pyramid web application development framework. the Pyramid Web Framework. </p> </div> </div> docs/tutorials/wiki2/src/basiclayout/tutorial/templates/mytemplate.pt
@@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal"> <head> <title>The Pyramid Web Application Development Framework</title> <title>The Pyramid Web Framework</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <meta name="keywords" content="python web application" /> <meta name="description" content="pyramid web application" /> @@ -24,7 +24,7 @@ <div class="middle align-center"> <p class="app-welcome"> Welcome to <span class="app-name">${project}</span>, an application generated by<br/> the Pyramid web application development framework. the Pyramid Web Framework. </p> </div> </div> docs/tutorials/wiki2/src/models/tutorial/templates/mytemplate.pt
@@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal"> <head> <title>The Pyramid Web Application Development Framework</title> <title>The Pyramid Web Framework</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <meta name="keywords" content="python web application" /> <meta name="description" content="pyramid web application" /> @@ -24,7 +24,7 @@ <div class="middle align-center"> <p class="app-welcome"> Welcome to <span class="app-name">${project}</span>, an application generated by<br/> the Pyramid web application development framework. the Pyramid Web Framework. </p> </div> </div> docs/tutorials/wiki2/src/tests/tutorial/templates/mytemplate.pt
@@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal"> <head> <title>The Pyramid Web Application Development Framework</title> <title>The Pyramid Web Framework</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <meta name="keywords" content="python web application" /> <meta name="description" content="pyramid web application" /> @@ -24,7 +24,7 @@ <div class="middle align-center"> <p class="app-welcome"> Welcome to <span class="app-name">${project}</span>, an application generated by<br/> the Pyramid web application development framework. the Pyramid Web Framework. </p> </div> </div> docs/tutorials/wiki2/src/views/tutorial/templates/mytemplate.pt
@@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal"> <head> <title>The Pyramid Web Application Development Framework</title> <title>The Pyramid Web Framework</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <meta name="keywords" content="python web application" /> <meta name="description" content="pyramid web application" /> @@ -24,7 +24,7 @@ <div class="middle align-center"> <p class="app-welcome"> Welcome to <span class="app-name">${project}</span>, an application generated by<br/> the Pyramid web application development framework. the Pyramid Web Framework. </p> </div> </div> pyramid/scaffolds/alchemy/+package+/templates/mytemplate.pt_tmpl
@@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal"> <head> <title>The Pyramid Web Application Development Framework</title> <title>The Pyramid Web Framework</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <meta name="keywords" content="python web application" /> <meta name="description" content="pyramid web application" /> @@ -24,7 +24,7 @@ <div class="middle align-center"> <p class="app-welcome"> Welcome to <span class="app-name">${project}</span>, an application generated by<br/> the Pyramid web application development framework. the Pyramid Web Framework. </p> </div> </div> pyramid/scaffolds/starter/+package+/templates/mytemplate.pt_tmpl
@@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal"> <head> <title>The Pyramid Web Application Development Framework</title> <title>The Pyramid Web Framework</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <meta name="keywords" content="python web application" /> <meta name="description" content="pyramid web application" /> @@ -24,7 +24,7 @@ <div class="middle align-center"> <p class="app-welcome"> Welcome to <span class="app-name">${project}</span>, an application generated by<br/> the Pyramid web application development framework. the Pyramid Web Framework. </p> </div> </div> pyramid/scaffolds/zodb/+package+/templates/mytemplate.pt
@@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal"> <head> <title>The Pyramid Web Application Development Framework</title> <title>The Pyramid Web Framework</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <meta name="keywords" content="python web application" /> <meta name="description" content="pyramid web application" /> @@ -24,7 +24,7 @@ <div class="middle align-center"> <p class="app-welcome"> Welcome to <span class="app-name">${project}</span>, an application generated by<br/> the Pyramid web application development framework. the Pyramid Web Framework. </p> </div> </div> pyramid/tests/test_scaffolds/fixture_scaffold/+package+/templates/mytemplate.pt_tmpl
@@ -1,7 +1,7 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal"> <head> <title>The Pyramid Web Application Development Framework</title> <title>The Pyramid Web Framework</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <meta name="keywords" content="python web application" /> <meta name="description" content="pyramid web application" /> @@ -24,7 +24,7 @@ <div class="middle align-center"> <p class="app-welcome"> Welcome to <span class="app-name">${project}</span>, an application generated by<br/> the Pyramid web application development framework. the Pyramid Web Framework. </p> </div> </div> setup.py
@@ -71,7 +71,7 @@ setup(name='pyramid', version='1.4', description=('The Pyramid web application development framework, a ' description=('The Pyramid Web Framework, a ' 'Pylons project'), long_description=README + '\n\n' + CHANGES, classifiers=[