forked from orbit-oss/flask
Merge branch 'master' into module-support
This commit is contained in:
commit
5144d3b65a
4 changed files with 42 additions and 10 deletions
|
|
@ -54,6 +54,24 @@ So what did that code do?
|
||||||
|
|
||||||
To stop the server, hit control-C.
|
To stop the server, hit control-C.
|
||||||
|
|
||||||
|
.. _public-server:
|
||||||
|
|
||||||
|
.. admonition:: Externally Visible Server
|
||||||
|
|
||||||
|
If you run the server you will notice that the server is only available
|
||||||
|
from your own computer, not from any other in the network. This is the
|
||||||
|
default because in debugging mode a user of the application can execute
|
||||||
|
arbitrary Python code on your computer. If you have `debug` disabled
|
||||||
|
or trust the users on your network, you can make the server publicly
|
||||||
|
available.
|
||||||
|
|
||||||
|
Just change the call of the :meth:`~flask.Flask.run` method to look
|
||||||
|
like this::
|
||||||
|
|
||||||
|
app.run(host='0.0.0.0')
|
||||||
|
|
||||||
|
This tells your operating system to listen on a public IP.
|
||||||
|
|
||||||
|
|
||||||
Debug Mode
|
Debug Mode
|
||||||
----------
|
----------
|
||||||
|
|
|
||||||
|
|
@ -57,13 +57,8 @@ without problems. When you head over to the server you will get an 404
|
||||||
page not found error because we don't have any views yet. But we will
|
page not found error because we don't have any views yet. But we will
|
||||||
focus on that a little later. First we should get the database working.
|
focus on that a little later. First we should get the database working.
|
||||||
|
|
||||||
.. admonition:: Troubleshooting
|
.. admonition:: Externally Visible Server
|
||||||
|
|
||||||
If you notice later that the browser cannot connect to the server
|
Want your server to be publically available? Check out the
|
||||||
during development, you might want to try this line instead::
|
:ref:`externally visible server <public-server>` section for more
|
||||||
|
information.
|
||||||
app.run(host='127.0.0.1')
|
|
||||||
|
|
||||||
In a nutshell: Werkzeug starts up as IPv6 on many operating systems by
|
|
||||||
default and not every browser is happy with that. This forces IPv4
|
|
||||||
usage.
|
|
||||||
|
|
|
||||||
7
flask.py
7
flask.py
|
|
@ -850,7 +850,7 @@ class Flask(_PackageBoundObject):
|
||||||
"""Converts the return value from a view function to a real
|
"""Converts the return value from a view function to a real
|
||||||
response object that is an instance of :attr:`response_class`.
|
response object that is an instance of :attr:`response_class`.
|
||||||
|
|
||||||
The following types are allowd for `rv`:
|
The following types are allowed for `rv`:
|
||||||
|
|
||||||
======================= ===========================================
|
======================= ===========================================
|
||||||
:attr:`response_class` the object is returned unchanged
|
:attr:`response_class` the object is returned unchanged
|
||||||
|
|
@ -866,6 +866,11 @@ class Flask(_PackageBoundObject):
|
||||||
|
|
||||||
:param rv: the return value from the view function
|
:param rv: the return value from the view function
|
||||||
"""
|
"""
|
||||||
|
if rv is None:
|
||||||
|
from warnings import warn
|
||||||
|
warn(Warning('View function did not return a response'),
|
||||||
|
stacklevel=2)
|
||||||
|
return u''
|
||||||
if isinstance(rv, self.response_class):
|
if isinstance(rv, self.response_class):
|
||||||
return rv
|
return rv
|
||||||
if isinstance(rv, basestring):
|
if isinstance(rv, basestring):
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import sys
|
||||||
import flask
|
import flask
|
||||||
import unittest
|
import unittest
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
|
||||||
example_path = os.path.join(os.path.dirname(__file__), '..', 'examples')
|
example_path = os.path.join(os.path.dirname(__file__), '..', 'examples')
|
||||||
|
|
@ -224,6 +225,19 @@ class BasicFunctionalityTestCase(unittest.TestCase):
|
||||||
assert flask.url_for('static', filename='index.html') \
|
assert flask.url_for('static', filename='index.html') \
|
||||||
== '/static/index.html'
|
== '/static/index.html'
|
||||||
|
|
||||||
|
def test_none_response(self):
|
||||||
|
warnings.filterwarnings('error', 'View function did not return')
|
||||||
|
app = flask.Flask(__name__)
|
||||||
|
@app.route('/')
|
||||||
|
def test():
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
app.test_client().get('/')
|
||||||
|
except Warning:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
assert "Expected warning"
|
||||||
|
|
||||||
|
|
||||||
class JSONTestCase(unittest.TestCase):
|
class JSONTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue