Skip to content
Myr

docs: ``.html``, ``.py``

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

authored by defuz · committed by defuz · parent d4b9b98 · Browse files · 8 files+16 added−16 removed
This commit

State

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

Diff stats

8 files+16 added−16 removed

  • other:+16 added−16 removed

8 files+16 added−16 removed

modified:docs/deploying/cgi.rst+4 added-4 removed
22 unmodified lines
23Creating a `.cgi` file24----------------------2526First you need to create the CGI application file. Let's call it27`yourapplication.cgi`::27:file:`yourapplication.cgi`::2829 #!/usr/bin/python30 from wsgiref.handlers import CGIHandler31 from yourapplication import app
3 unmodified lines
35Server Setup36------------3738Usually there are two ways to configure the server. Either just copy the39`.cgi` into a `cgi-bin` (and use `mod_rewrite` or something similar to39``.cgi`` into a :file:`cgi-bin` (and use `mod_rewrite` or something similar to40rewrite the URL) or let the server point to the file directly.4142In Apache for example you can put something like this into the config:43
1 unmodified line
4546 ScriptAlias /app /path/to/the/application.cgi4748On shared webhosting, though, you might not have access to your Apache config.49In this case, a file called `.htaccess`, sitting in the public directory you want50your app to be available, works too but the `ScriptAlias` directive won't49In this case, a file called ``.htaccess``, sitting in the public directory you want50your app to be available, works too but the ``ScriptAlias`` directive won't51work in that case:5253.. sourcecode:: apache54
7 unmodified lines
modified:docs/deploying/mod_wsgi.rst+5 added-5 removed
50 unmodified lines
5152Creating a `.wsgi` file53-----------------------5455To run your application you need a `yourapplication.wsgi` file. This file55To run your application you need a :file:`yourapplication.wsgi` file. This file56contains the code `mod_wsgi` is executing on startup to get the application57object. The object called `application` in that file is then used as58application.59
9 unmodified lines
69the libraries that are in use are on the python load path. If you don't70want to install it system wide consider using a `virtual python`_71instance. Keep in mind that you will have to actually install your72application into the virtualenv as well. Alternatively there is the73option to just patch the path in the `.wsgi` file before the import::73option to just patch the path in the ``.wsgi`` file before the import::7475 import sys76 sys.path.insert(0, '/path/to/the/application')77
92 unmodified lines
170Support for Automatic Reloading171-------------------------------172173To help deployment tools you can activate support for automatic174reloading. Whenever something changes the `.wsgi` file, `mod_wsgi` will174reloading. Whenever something changes the ``.wsgi`` file, `mod_wsgi` will175reload all the daemon processes for us.176177For that, just add the following directive to your `Directory` section:178
6 unmodified lines
185186Virtual environments have the advantage that they never install the187required dependencies system wide so you have a better control over what188is used where. If you want to use a virtual environment with mod_wsgi189you have to modify your `.wsgi` file slightly.189you have to modify your ``.wsgi`` file slightly.190191Add the following lines to the top of your `.wsgi` file::191Add the following lines to the top of your ``.wsgi`` file::192193 activate_this = '/path/to/env/bin/activate_this.py'194 execfile(activate_this, dict(__file__=activate_this))195
2 unmodified lines
modified:docs/patterns/fabric.rst+2 added-2 removed
84 unmodified lines
8586However this requires that our server already has the87:file:`/var/www/yourapplication` folder created and88:file:`/var/www/yourapplication/env` to be a virtual environment. Furthermore89are we not creating the configuration or `.wsgi` file on the server. So89are we not creating the configuration or ``.wsgi`` file on the server. So90how do we bootstrap a new server into our infrastructure?9192This now depends on the number of servers we want to set up. If we just93have one application server (which the majority of applications will
15 unmodified lines
1092. Upload a new :file:`application.wsgi` file to the server and the110 configuration file for the application (eg: :file:`application.cfg`)1111123. Create a new Apache config for ``yourapplication`` and activate it.113 Make sure to activate watching for changes of the `.wsgi` file so113 Make sure to activate watching for changes of the ``.wsgi`` file so114 that we can automatically reload the application by touching it.115 (See :ref:`mod_wsgi-deployment` for more information)116117So now the question is, where do the :file:`application.wsgi` and
79 unmodified lines
modified:docs/patterns/fileuploads.rst+1 added-1 removed
41 unmodified lines
42Why do we limit the extensions that are allowed? You probably don't want43your users to be able to upload everything there if the server is directly44sending out the data to the client. That way you can make sure that users45are not able to upload HTML files that would cause XSS problems (see46:ref:`xss`). Also make sure to disallow `.php` files if the server46:ref:`xss`). Also make sure to disallow ``.php`` files if the server47executes them, but who has PHP installed on his server, right? :)4849Next the functions that check if an extension is valid and that uploads50the file and redirects the user to the URL for the uploaded file::
140 unmodified lines
modified:docs/patterns/packages.rst+1 added-1 removed
21 unmodified lines
2223To convert that into a larger one, just create a new folder24:file:`yourapplication` inside the existing one and move everything below it.25Then rename :file:`yourapplication.py` to :file:`__init__.py`. (Make sure to delete26all `.pyc` files first, otherwise things would most likely break)26all ``.pyc`` files first, otherwise things would most likely break)2728You should then end up with something like that::2930 /yourapplication
85 unmodified lines
modified:docs/tutorial/setup.rst+1 added-1 removed
6 unmodified lines
7Let's call it flaskr.py. We will place this file inside the flaskr folder.8We will begin by adding the imports we need and by adding the config9section. For small applications, it is possible to drop the configuration10directly into the module, and this is what we will be doing here. However11a cleaner solution would be to create a separate `.ini` or `.py` file and11a cleaner solution would be to create a separate ``.ini`` or ``.py`` file and12load that or import the values from there.1314First we add the imports in :file:`flaskr.py`::15
98 unmodified lines
modified:flask/app.py+1 added-1 removed
69 unmodified lines
7071 The name of the package is used to resolve resources from inside the72 package or the folder the module is contained in depending on if the73 package parameter resolves to an actual python package (a folder with74 an :file:`__init__.py` file inside) or a standard module (just a `.py` file).74 an :file:`__init__.py` file inside) or a standard module (just a ``.py`` file).7576 For more information about resource loading, see :func:`open_resource`.7778 Usually you create a :class:`Flask` instance in your main module or
1831 unmodified lines
modified:flask/helpers.py+1 added-1 removed
885 unmodified lines
886 /templates887 /layout.html888 /index.html889890 If you want to open the `schema.sql` file you would do the890 If you want to open the :file:`schema.sql` file you would do the891 following::892893 with app.open_resource('schema.sql') as f:894 contents = f.read()
9 unmodified lines