Ticket #18029: 18029-1.diff
File 18029-1.diff, 46.8 KB (added by , 13 years ago) |
---|
-
deleted file django/contrib/auth/handlers/modpython.py
diff --git a/django/contrib/auth/handlers/__init__.py b/django/contrib/auth/handlers/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/django/contrib/auth/handlers/modpython.py b/django/contrib/auth/handlers/modpython.py deleted file mode 100644 index de961fa..0000000
+ - 1 from mod_python import apache2 import os3 4 def authenhandler(req, **kwargs):5 """6 Authentication handler that checks against Django's auth database.7 """8 9 # mod_python fakes the environ, and thus doesn't process SetEnv. This fixes10 # that so that the following import works11 os.environ.update(req.subprocess_env)12 13 # apache 2.2 requires a call to req.get_basic_auth_pw() before14 # req.user and friends are available.15 req.get_basic_auth_pw()16 17 # check for PythonOptions18 _str_to_bool = lambda s: s.lower() in ('1', 'true', 'on', 'yes')19 20 options = req.get_options()21 permission_name = options.get('DjangoPermissionName', None)22 staff_only = _str_to_bool(options.get('DjangoRequireStaffStatus', "on"))23 superuser_only = _str_to_bool(options.get('DjangoRequireSuperuserStatus', "off"))24 settings_module = options.get('DJANGO_SETTINGS_MODULE', None)25 if settings_module:26 os.environ['DJANGO_SETTINGS_MODULE'] = settings_module27 28 from django.contrib.auth.models import User29 from django import db30 db.reset_queries()31 32 # check that the username is valid33 kwargs = {'username': req.user, 'is_active': True}34 if staff_only:35 kwargs['is_staff'] = True36 if superuser_only:37 kwargs['is_superuser'] = True38 try:39 try:40 user = User.objects.get(**kwargs)41 except User.DoesNotExist:42 return apache.HTTP_UNAUTHORIZED43 44 # check the password and any permission given45 if user.check_password(req.get_basic_auth_pw()):46 if permission_name:47 if user.has_perm(permission_name):48 return apache.OK49 else:50 return apache.HTTP_UNAUTHORIZED51 else:52 return apache.OK53 else:54 return apache.HTTP_UNAUTHORIZED55 finally:56 db.connection.close() -
django/core/cache/__init__.py
diff --git a/django/core/cache/__init__.py b/django/core/cache/__init__.py index 9eac8ec..d8095d4 100644
a b cache class. 14 14 15 15 See docs/topics/cache.txt for information on the public API. 16 16 """ 17 from urlparse import parse_qsl 18 17 19 from django.conf import settings 18 20 from django.core import signals 19 21 from django.core.cache.backends.base import ( … … from django.core.cache.backends.base import ( 21 23 from django.core.exceptions import ImproperlyConfigured 22 24 from django.utils import importlib 23 25 24 try:25 # The mod_python version is more efficient, so try importing it first.26 from mod_python.util import parse_qsl27 except ImportError:28 from urlparse import parse_qsl29 30 26 __all__ = [ 31 27 'get_cache', 'cache', 'DEFAULT_CACHE_ALIAS' 32 28 ] -
deleted file django/core/handlers/modpython.py
diff --git a/django/core/handlers/modpython.py b/django/core/handlers/modpython.py deleted file mode 100644 index fb23fb4..0000000
+ - 1 import os2 import sys3 from warnings import warn4 5 from django import http6 from django.core import signals7 from django.core.handlers.base import BaseHandler8 from django.core.urlresolvers import set_script_prefix9 from django.utils import datastructures10 from django.utils.encoding import force_unicode, iri_to_uri11 from django.utils.log import getLogger12 13 logger = getLogger('django.request')14 15 class ModPythonRequest(http.HttpRequest):16 def __init__(self, req):17 self._req = req18 # FIXME: This isn't ideal. The request URI may be encoded (it's19 # non-normalized) slightly differently to the "real" SCRIPT_NAME20 # and PATH_INFO values. This causes problems when we compute path_info,21 # below. For now, don't use script names that will be subject to22 # encoding/decoding.23 self.path = force_unicode(req.uri)24 root = req.get_options().get('django.root', '')25 self.django_root = root26 # req.path_info isn't necessarily computed correctly in all27 # circumstances (it's out of mod_python's control a bit), so we use28 # req.uri and some string manipulations to get the right value.29 if root and req.uri.startswith(root):30 self.path_info = force_unicode(req.uri[len(root):])31 else:32 self.path_info = self.path33 if not self.path_info:34 # Django prefers empty paths to be '/', rather than '', to give us35 # a common start character for URL patterns. So this is a little36 # naughty, but also pretty harmless.37 self.path_info = u'/'38 self._post_parse_error = False39 self._stream = self._req40 self._read_started = False41 42 def get_full_path(self):43 # RFC 3986 requires self._req.args to be in the ASCII range, but this44 # doesn't always happen, so rather than crash, we defensively encode it.45 return '%s%s' % (self.path, self._req.args and ('?' + iri_to_uri(self._req.args)) or '')46 47 def _is_secure(self):48 try:49 return self._req.is_https()50 except AttributeError:51 # mod_python < 3.2.10 doesn't have req.is_https().52 return self._req.subprocess_env.get('HTTPS', '').lower() in ('on', '1')53 54 def _get_request(self):55 if not hasattr(self, '_request'):56 self._request = datastructures.MergeDict(self.POST, self.GET)57 return self._request58 59 def _get_get(self):60 if not hasattr(self, '_get'):61 self._get = http.QueryDict(self._req.args, encoding=self._encoding)62 return self._get63 64 def _set_get(self, get):65 self._get = get66 67 def _get_post(self):68 if not hasattr(self, '_post'):69 self._load_post_and_files()70 return self._post71 72 def _set_post(self, post):73 self._post = post74 75 def _get_cookies(self):76 if not hasattr(self, '_cookies'):77 self._cookies = http.parse_cookie(self._req.headers_in.get('cookie', ''))78 return self._cookies79 80 def _set_cookies(self, cookies):81 self._cookies = cookies82 83 def _get_files(self):84 if not hasattr(self, '_files'):85 self._load_post_and_files()86 return self._files87 88 def _get_meta(self):89 "Lazy loader that returns self.META dictionary"90 if not hasattr(self, '_meta'):91 self._meta = {92 'AUTH_TYPE': self._req.ap_auth_type,93 'CONTENT_LENGTH': self._req.headers_in.get('content-length', 0),94 'CONTENT_TYPE': self._req.headers_in.get('content-type'),95 'GATEWAY_INTERFACE': 'CGI/1.1',96 'PATH_INFO': self.path_info,97 'PATH_TRANSLATED': None, # Not supported98 'QUERY_STRING': self._req.args,99 'REMOTE_ADDR': self._req.connection.remote_ip,100 'REMOTE_HOST': None, # DNS lookups not supported101 'REMOTE_IDENT': self._req.connection.remote_logname,102 'REMOTE_USER': self._req.user,103 'REQUEST_METHOD': self._req.method,104 'SCRIPT_NAME': self.django_root,105 'SERVER_NAME': self._req.server.server_hostname,106 'SERVER_PORT': self._req.connection.local_addr[1],107 'SERVER_PROTOCOL': self._req.protocol,108 'SERVER_SOFTWARE': 'mod_python'109 }110 for key, value in self._req.headers_in.items():111 key = 'HTTP_' + key.upper().replace('-', '_')112 self._meta[key] = value113 return self._meta114 115 def _get_method(self):116 return self.META['REQUEST_METHOD'].upper()117 118 GET = property(_get_get, _set_get)119 POST = property(_get_post, _set_post)120 COOKIES = property(_get_cookies, _set_cookies)121 FILES = property(_get_files)122 META = property(_get_meta)123 REQUEST = property(_get_request)124 method = property(_get_method)125 126 class ModPythonHandler(BaseHandler):127 request_class = ModPythonRequest128 129 def __call__(self, req):130 warn(('The mod_python handler is deprecated; use a WSGI or FastCGI server instead.'),131 DeprecationWarning)132 133 # mod_python fakes the environ, and thus doesn't process SetEnv. This fixes that134 os.environ.update(req.subprocess_env)135 136 # now that the environ works we can see the correct settings, so imports137 # that use settings now can work138 from django.conf import settings139 140 # if we need to set up middleware, now that settings works we can do it now.141 if self._request_middleware is None:142 self.load_middleware()143 144 set_script_prefix(req.get_options().get('django.root', ''))145 signals.request_started.send(sender=self.__class__)146 try:147 try:148 request = self.request_class(req)149 except UnicodeDecodeError:150 logger.warning('Bad Request (UnicodeDecodeError)',151 exc_info=sys.exc_info(),152 extra={153 'status_code': 400,154 }155 )156 response = http.HttpResponseBadRequest()157 else:158 response = self.get_response(request)159 finally:160 signals.request_finished.send(sender=self.__class__)161 162 # Convert our custom HttpResponse object back into the mod_python req.163 req.content_type = response['Content-Type']164 for key, value in response.items():165 if key != 'content-type':166 req.headers_out[str(key)] = str(value)167 for c in response.cookies.values():168 req.headers_out.add('Set-Cookie', c.output(header=''))169 req.status = response.status_code170 try:171 for chunk in response:172 req.write(chunk)173 finally:174 response.close()175 176 return 0 # mod_python.apache.OK177 178 def handler(req):179 # mod_python hooks into this function.180 return ModPythonHandler()(req) -
deleted file django/core/handlers/profiler-hotshot.py
diff --git a/django/core/handlers/profiler-hotshot.py b/django/core/handlers/profiler-hotshot.py deleted file mode 100644 index 0522de6..0000000
+ - 1 import hotshot2 import os3 import time4 5 from django.core.handlers.modpython import ModPythonHandler6 7 PROFILE_DATA_DIR = "/var/log/cmsprofile"8 9 def handler(req):10 '''11 Handler that uses hotshot to store profile data.12 13 Stores profile data in PROFILE_DATA_DIR. Since hotshot has no way (that I14 know of) to append profile data to a single file, each request gets its own15 profile. The file names are in the format <url>.<n>.prof where <url> is16 the request path with "/" replaced by ".", and <n> is a timestamp with17 microseconds to prevent overwriting files.18 19 Use the gather_profile_stats.py script to gather these individual request20 profiles into aggregated profiles by request path.21 '''22 profname = "%s.%.3f.prof" % (req.uri.strip("/").replace('/', '.'), time.time())23 profname = os.path.join(PROFILE_DATA_DIR, profname)24 prof = hotshot.Profile(profname)25 return prof.runcall(ModPythonHandler(), req) -
django/http/__init__.py
diff --git a/django/http/__init__.py b/django/http/__init__.py index 5f407a4..2f3392f 100644
a b import warnings 9 9 10 10 from pprint import pformat 11 11 from urllib import urlencode, quote 12 from urlparse import urljoin 12 from urlparse import urljoin, parse_qsl 13 13 try: 14 14 from cStringIO import StringIO 15 15 except ImportError: 16 16 from StringIO import StringIO 17 try:18 # The mod_python version is more efficient, so try importing it first.19 from mod_python.util import parse_qsl20 except ImportError:21 from urlparse import parse_qsl22 17 23 18 import Cookie 24 19 # Some versions of Python 2.7 and later won't need this encoding bug fix: … … class HttpRequest(object): 348 343 ## File-like and iterator interface. 349 344 ## 350 345 ## Expects self._stream to be set to an appropriate source of bytes by 351 ## a corresponding request subclass ( WSGIRequest or ModPythonRequest).346 ## a corresponding request subclass (e.g. WSGIRequest). 352 347 ## Also when request data has already been read by request.POST or 353 348 ## request.body, self._stream points to a StringIO instance 354 349 ## containing that data. -
docs/faq/usage.txt
diff --git a/docs/faq/usage.txt b/docs/faq/usage.txt index 2b185be..1514543 100644
a b Make sure that: 13 13 14 14 * The module doesn't contain syntax errors (of course). 15 15 16 * If you're using mod_python but *not* using Django's request handler,17 you'll need to work around a mod_python bug related to the use of18 ``SetEnv``; before you import anything from Django you'll need to do19 the following::20 21 os.environ.update(req.subprocess_env)22 23 (where ``req`` is the mod_python request object).24 25 16 I can't stand your template language. Do I have to use it? 26 17 ---------------------------------------------------------- 27 18 -
docs/howto/apache-auth.txt
diff --git a/docs/howto/apache-auth.txt b/docs/howto/apache-auth.txt index 215c519..719fbc1 100644
a b 2 2 Authenticating against Django's user database from Apache 3 3 ========================================================= 4 4 5 .. warning::6 7 Support for mod_python has been deprecated within Django. At that8 time, this method of authentication will no longer be provided by9 Django. The community is welcome to offer its own alternate10 solutions using WSGI middleware or other approaches.11 12 5 Since keeping multiple authentication databases in sync is a common problem when 13 6 dealing with Apache, you can configuring Apache to authenticate against Django's 14 :doc:`authentication system </topics/auth>` directly. For example, you15 could:7 :doc:`authentication system </topics/auth>` directly. This requires Apache 8 version >= 2.2 and mod_wsgi >= 2.0. For example, you could: 16 9 17 10 * Serve static/media files directly from Apache only to authenticated users. 18 11 … … could: 22 15 * Allow certain users to connect to a WebDAV share created with mod_dav_. 23 16 24 17 .. _Subversion: http://subversion.tigris.org/ 25 .. _mod_dav: http://httpd.apache.org/docs/2. 0/mod/mod_dav.html18 .. _mod_dav: http://httpd.apache.org/docs/2.2/mod/mod_dav.html 26 19 27 20 Configuring Apache 28 21 ================== 29 22 30 23 To check against Django's authorization database from a Apache configuration 31 file, you'll need to use mod_python's ``PythonAuthenHandler`` directive along 32 with the standard ``Auth*`` and ``Require`` directives: 24 file, you'll need to set 'wsgi' as the value of ``AuthBasicProvider`` or 25 ``AuthDigestProvider`` directive and then use the ``WSGIAuthUserScript`` 26 directive to set the path to your authentification script: 33 27 34 28 .. code-block:: apache 35 29 36 30 <Location /example/> 37 31 AuthType Basic 38 32 AuthName "example.com" 33 AuthBasicProvider wsgi 34 WSGIAuthUserScript /usr/local/wsgi/scripts/auth.wsgi 39 35 Require valid-user 40 41 SetEnv DJANGO_SETTINGS_MODULE mysite.settings42 PythonAuthenHandler django.contrib.auth.handlers.modpython43 36 </Location> 44 37 45 .. admonition:: Using the authentication handler with Apache 2.2 46 47 If you're using Apache 2.2, you'll need to take a couple extra steps. 48 49 You'll need to ensure that ``mod_auth_basic`` and ``mod_authz_user`` 50 are loaded. These might be compiled statically into Apache, or you might 51 need to use ``LoadModule`` to load them dynamically (as shown in the 52 example at the bottom of this note). 53 54 You'll also need to insert configuration directives that prevent Apache 55 from trying to use other authentication modules, as well as specifying 56 the ``AuthUserFile`` directive and pointing it to ``/dev/null``. Depending 57 on which other authentication modules you have loaded, you might need one 58 or more of the following directives: 59 60 .. code-block:: apache 61 62 AuthBasicAuthoritative Off 63 AuthDefaultAuthoritative Off 64 AuthzLDAPAuthoritative Off 65 AuthzDBMAuthoritative Off 66 AuthzDefaultAuthoritative Off 67 AuthzGroupFileAuthoritative Off 68 AuthzOwnerAuthoritative Off 69 AuthzUserAuthoritative Off 70 71 A complete configuration, with differences between Apache 2.0 and 72 Apache 2.2 marked in bold, would look something like: 73 74 .. parsed-literal:: 75 76 **LoadModule auth_basic_module modules/mod_auth_basic.so** 77 **LoadModule authz_user_module modules/mod_authz_user.so** 78 79 ... 80 81 <Location /example/> 82 AuthType Basic 83 AuthName "example.com" 84 **AuthUserFile /dev/null** 85 **AuthBasicAuthoritative Off** 86 Require valid-user 87 88 SetEnv DJANGO_SETTINGS_MODULE mysite.settings 89 PythonAuthenHandler django.contrib.auth.handlers.modpython 90 </Location> 91 92 By default, the authentication handler will limit access to the ``/example/`` 93 location to users marked as staff members. You can use a set of 94 ``PythonOption`` directives to modify this behavior: 95 96 ================================ ========================================= 97 ``PythonOption`` Explanation 98 ================================ ========================================= 99 ``DjangoRequireStaffStatus`` If set to ``on`` only "staff" users (i.e. 100 those with the ``is_staff`` flag set) 101 will be allowed. 102 103 Defaults to ``on``. 104 105 ``DjangoRequireSuperuserStatus`` If set to ``on`` only superusers (i.e. 106 those with the ``is_superuser`` flag set) 107 will be allowed. 108 109 Defaults to ``off``. 110 111 ``DjangoPermissionName`` The name of a permission to require for 112 access. See :ref:`custom permissions 113 <custom-permissions>` for more 114 information. 115 116 By default no specific permission will be 117 required. 118 ================================ ========================================= 38 Your auth.wsgi script will have to implement either a 39 ``check_password(environ, user, password)`` function (for ``AuthBasicProvider``) 40 or a ``get_realm_hash(environ, user, realm)`` function (for ``AuthDigestProvider``). 119 41 120 Note that sometimes ``SetEnv`` doesn't play well in this mod_python 121 configuration, for reasons unknown. If you're having problems getting 122 mod_python to recognize your ``DJANGO_SETTINGS_MODULE``, you can set it using 123 ``PythonOption`` instead of ``SetEnv``. Therefore, these two Apache directives 124 are equivalent:: 42 See the `mod_wsgi documentation`_ for more details about the implementation 43 of such a solution. 125 44 126 SetEnv DJANGO_SETTINGS_MODULE mysite.settings 127 PythonOption DJANGO_SETTINGS_MODULE mysite.settings 45 .. _mod_wsgi documentation: http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms#Apache_Authentication_Provider -
docs/howto/deployment/index.txt
diff --git a/docs/howto/deployment/index.txt b/docs/howto/deployment/index.txt index 113f606..8e27a03 100644
a b ways to easily deploy Django: 11 11 12 12 wsgi/index 13 13 fastcgi 14 mod_python (deprecated) <modpython>15 14 16 15 If you're new to deploying Django and/or Python, we'd recommend you try 17 16 :doc:`mod_wsgi </howto/deployment/wsgi/modwsgi>` first. In most cases it'll be … … the easiest, fastest, and most stable deployment choice. 22 21 * `Chapter 12 of the Django Book (second edition)`_ discusses deployment 23 22 and especially scaling in more detail. However, note that this edition 24 23 was written against Django version 1.1 and has not been updated since 25 :doc:`mod_python </howto/deployment/modpython>` was deprecated.24 `mod_python` was first deprecated, then completely removed in Django 1.5. 26 25 27 26 .. _chapter 12 of the django book (second edition): http://djangobook.com/en/2.0/chapter12/ -
deleted file docs/howto/deployment/modpython.txt
diff --git a/docs/howto/deployment/modpython.txt b/docs/howto/deployment/modpython.txt deleted file mode 100644 index b1ddf58..0000000
+ - 1 ============================================2 How to use Django with Apache and mod_python3 ============================================4 5 .. warning::6 7 Support for mod_python has been deprecated, and will be removed in8 Django 1.5. If you are configuring a new deployment, you are9 strongly encouraged to consider using :doc:`mod_wsgi10 </howto/deployment/wsgi/modwsgi>` or any of the other :doc:`supported11 servers </howto/deployment/index>`.12 13 .. highlight:: apache14 15 The `mod_python`_ module for Apache_ can be used to deploy Django to a16 production server, although it has been mostly superseded by the simpler17 :doc:`mod_wsgi deployment option </howto/deployment/wsgi/modwsgi>`.18 19 mod_python is similar to (and inspired by) `mod_perl`_ : It embeds Python within20 Apache and loads Python code into memory when the server starts. Code stays in21 memory throughout the life of an Apache process, which leads to significant22 performance gains over other server arrangements.23 24 Django requires Apache 2.x and mod_python 3.x, and you should use Apache's25 `prefork MPM`_, as opposed to the `worker MPM`_.26 27 .. seealso::28 29 * Apache is a big, complex animal, and this document only scratches the30 surface of what Apache can do. If you need more advanced information about31 Apache, there's no better source than `Apache's own official32 documentation`_33 34 * You may also be interested in :doc:`How to use Django with FastCGI, SCGI,35 or AJP </howto/deployment/fastcgi>`.36 37 .. _Apache: http://httpd.apache.org/38 .. _mod_python: http://www.modpython.org/39 .. _mod_perl: http://perl.apache.org/40 .. _prefork MPM: http://httpd.apache.org/docs/2.2/mod/prefork.html41 .. _worker MPM: http://httpd.apache.org/docs/2.2/mod/worker.html42 .. _apache's own official documentation: http://httpd.apache.org/docs/43 44 Basic configuration45 ===================46 47 To configure Django with mod_python, first make sure you have Apache installed,48 with the mod_python module activated.49 50 Then edit your ``httpd.conf`` file and add the following::51 52 <Location "/mysite/">53 SetHandler python-program54 PythonHandler django.core.handlers.modpython55 SetEnv DJANGO_SETTINGS_MODULE mysite.settings56 PythonOption django.root /mysite57 PythonDebug On58 </Location>59 60 ...and replace ``mysite.settings`` with the Python import path to your Django61 project's settings file.62 63 This tells Apache: "Use mod_python for any URL at or under '/mysite/', using the64 Django mod_python handler." It passes the value of :ref:`DJANGO_SETTINGS_MODULE65 <django-settings-module>` so mod_python knows which settings to use.66 67 Because mod_python does not know we are serving this site from underneath the68 ``/mysite/`` prefix, this value needs to be passed through to the mod_python69 handler in Django, via the ``PythonOption django.root ...`` line. The value set70 on that line (the last item) should match the string given in the ``<Location71 ...>`` directive. The effect of this is that Django will automatically strip the72 ``/mysite`` string from the front of any URLs before matching them against your73 URLconf patterns. If you later move your site to live under ``/mysite2``, you74 will not have to change anything except the ``django.root`` option in the config75 file.76 77 When using ``django.root`` you should make sure that what's left, after the78 prefix has been removed, begins with a slash. Your URLconf patterns that are79 expecting an initial slash will then work correctly. In the above example,80 since we want to send things like ``/mysite/admin/`` to ``/admin/``, we need81 to remove the string ``/mysite`` from the beginning, so that is the82 ``django.root`` value. It would be an error to use ``/mysite/`` (with a83 trailing slash) in this case.84 85 Note that we're using the ``<Location>`` directive, not the ``<Directory>``86 directive. The latter is used for pointing at places on your filesystem,87 whereas ``<Location>`` points at places in the URL structure of a Web site.88 ``<Directory>`` would be meaningless here.89 90 Also, if your Django project is not on the default ``PYTHONPATH`` for your91 computer, you'll have to tell mod_python where your project can be found:92 93 .. parsed-literal::94 95 <Location "/mysite/">96 SetHandler python-program97 PythonHandler django.core.handlers.modpython98 SetEnv DJANGO_SETTINGS_MODULE mysite.settings99 PythonOption django.root /mysite100 PythonDebug On101 **PythonPath "['/path/to/project'] + sys.path"**102 </Location>103 104 The value you use for ``PythonPath`` should include the parent directories of105 all the modules you are going to import in your application. It should also106 include the parent directory of the :ref:`DJANGO_SETTINGS_MODULE107 <django-settings-module>` location. This is exactly the same situation as108 setting the Python path for interactive usage. Whenever you try to import109 something, Python will run through all the directories in ``sys.path`` in turn,110 from first to last, and try to import from each directory until one succeeds.111 112 Make sure that your Python source files' permissions are set such that the113 Apache user (usually named ``apache`` or ``httpd`` on most systems) will have114 read access to the files.115 116 An example might make this clearer. Suppose you have some applications under117 ``/usr/local/django-apps/`` (for example, ``/usr/local/django-apps/weblog/`` and118 so forth), your settings file is at ``/var/www/mysite/settings.py`` and you have119 specified :ref:`DJANGO_SETTINGS_MODULE <django-settings-module>` as in the above120 example. In this case, you would need to write your ``PythonPath`` directive121 as::122 123 PythonPath "['/usr/local/django-apps/', '/var/www'] + sys.path"124 125 With this path, ``import weblog`` and ``import mysite.settings`` will both126 work. If you had ``import blogroll`` in your code somewhere and ``blogroll``127 lived under the ``weblog/`` directory, you would *also* need to add128 ``/usr/local/django-apps/weblog/`` to your ``PythonPath``. Remember: the129 **parent directories** of anything you import directly must be on the Python130 path.131 132 .. note::133 134 If you're using Windows, we still recommended that you use forward135 slashes in the pathnames, even though Windows normally uses the backslash136 character as its native separator. Apache knows how to convert from the137 forward slash format to the native format, so this approach is portable and138 easier to read. (It avoids tricky problems with having to double-escape139 backslashes.)140 141 This is valid even on a Windows system::142 143 PythonPath "['c:/path/to/project'] + sys.path"144 145 You can also add directives such as ``PythonAutoReload Off`` for performance.146 See the `mod_python documentation`_ for a full list of options.147 148 Note that you should set ``PythonDebug Off`` on a production server. If you149 leave ``PythonDebug On``, your users would see ugly (and revealing) Python150 tracebacks if something goes wrong within mod_python.151 152 Restart Apache, and any request to ``/mysite/`` or below will be served by153 Django. Note that Django's URLconfs won't trim the "/mysite/" -- they get passed154 the full URL.155 156 When deploying Django sites on mod_python, you'll need to restart Apache each157 time you make changes to your Python code.158 159 .. _mod_python documentation: http://modpython.org/live/current/doc-html/directives.html160 161 Multiple Django installations on the same Apache162 ================================================163 164 It's entirely possible to run multiple Django installations on the same Apache165 instance. Just use ``VirtualHost`` for that, like so::166 167 NameVirtualHost *168 169 <VirtualHost *>170 ServerName www.example.com171 # ...172 SetEnv DJANGO_SETTINGS_MODULE mysite.settings173 </VirtualHost>174 175 <VirtualHost *>176 ServerName www2.example.com177 # ...178 SetEnv DJANGO_SETTINGS_MODULE mysite.other_settings179 </VirtualHost>180 181 If you need to put two Django installations within the same ``VirtualHost``182 (or in different ``VirtualHost`` blocks that share the same server name),183 you'll need to take a special precaution to ensure mod_python's cache doesn't184 mess things up. Use the ``PythonInterpreter`` directive to give different185 ``<Location>`` directives separate interpreters::186 187 <VirtualHost *>188 ServerName www.example.com189 # ...190 <Location "/something">191 SetEnv DJANGO_SETTINGS_MODULE mysite.settings192 PythonInterpreter mysite193 </Location>194 195 <Location "/otherthing">196 SetEnv DJANGO_SETTINGS_MODULE mysite.other_settings197 PythonInterpreter othersite198 </Location>199 </VirtualHost>200 201 The values of ``PythonInterpreter`` don't really matter, as long as they're202 different between the two ``Location`` blocks.203 204 Running a development server with mod_python205 ============================================206 207 If you use mod_python for your development server, you can avoid the hassle of208 having to restart the server each time you make code changes. Just set209 ``MaxRequestsPerChild 1`` in your ``httpd.conf`` file to force Apache to reload210 everything for each request. But don't do that on a production server, or we'll211 revoke your Django privileges.212 213 If you're the type of programmer who debugs using scattered ``print``214 statements, note that output to ``stdout`` will not appear in the Apache215 log and can even `cause response errors`_.216 217 .. _cause response errors: http://blog.dscpl.com.au/2009/04/wsgi-and-printing-to-standard-output.html218 219 If you have the need to print debugging information in a mod_python setup, you220 have a few options. You can print to ``stderr`` explicitly, like so::221 222 print >> sys.stderr, 'debug text'223 sys.stderr.flush()224 225 (note that ``stderr`` is buffered, so calling ``flush`` is necessary if you wish226 debugging information to be displayed promptly.)227 228 A more compact approach is to use an assertion::229 230 assert False, 'debug text'231 232 Another alternative is to add debugging information to the template of your page.233 234 Serving media files235 ===================236 237 Django doesn't serve media files itself; it leaves that job to whichever Web238 server you choose.239 240 We recommend using a separate Web server -- i.e., one that's not also running241 Django -- for serving media. Here are some good choices:242 243 * lighttpd_244 * Nginx_245 * TUX_246 * A stripped-down version of Apache_247 * Cherokee_248 249 If, however, you have no option but to serve media or static files on the250 same Apache ``VirtualHost`` as Django, here's how you can turn off mod_python251 for a particular part of the site::252 253 <Location "/media">254 SetHandler None255 </Location>256 257 Just change ``Location`` to the root URL of your media files. You can also use258 ``<LocationMatch>`` to match a regular expression.259 260 This example sets up Django at the site root but explicitly disables Django261 for the ``media`` and ``static`` subdirectories and any URL that ends with262 ``.jpg``, ``.gif`` or ``.png``::263 264 <Location "/">265 SetHandler python-program266 PythonHandler django.core.handlers.modpython267 SetEnv DJANGO_SETTINGS_MODULE mysite.settings268 </Location>269 270 <Location "/media">271 SetHandler None272 </Location>273 274 <Location "/static">275 SetHandler None276 </Location>277 278 <LocationMatch "\.(jpg|gif|png)$">279 SetHandler None280 </LocationMatch>281 282 .. _lighttpd: http://www.lighttpd.net/283 .. _Nginx: http://wiki.nginx.org/Main284 .. _TUX: http://en.wikipedia.org/wiki/TUX_web_server285 .. _Apache: http://httpd.apache.org/286 .. _Cherokee: http://www.cherokee-project.com/287 288 Serving the admin files289 =======================290 291 Note that the Django development server automagically serves the static files292 of the admin app, but this is not the case when you use any other server293 arrangement. You're responsible for setting up Apache, or whichever media294 server you're using, to serve the admin files.295 296 The admin files live in (:file:`django/contrib/admin/static/admin`) of the297 Django distribution.298 299 We **strongly** recommend using :mod:`django.contrib.staticfiles` to handle the300 admin files (this means using the :djadmin:`collectstatic` management command301 to collect the static files in :setting:`STATIC_ROOT`, and then configuring302 your Web server to serve :setting:`STATIC_ROOT` at :setting:`STATIC_URL`), but303 here are two other approaches:304 305 1. Create a symbolic link to the admin static files from within your306 document root.307 308 2. Or, copy the admin static files so that they live within your Apache309 document root.310 311 Using "eggs" with mod_python312 ============================313 314 If you installed Django from a Python egg_ or are using eggs in your Django315 project, some extra configuration is required. Create an extra file in your316 project (or somewhere else) that contains something like the following:317 318 .. code-block:: python319 320 import os321 os.environ['PYTHON_EGG_CACHE'] = '/some/directory'322 323 Here, ``/some/directory`` is a directory that the Apache Web server process can324 write to. It will be used as the location for any unpacking of code the eggs325 need to do.326 327 Then you have to tell mod_python to import this file before doing anything328 else. This is done using the PythonImport_ directive to mod_python. You need329 to ensure that you have specified the ``PythonInterpreter`` directive to330 mod_python as described above__ (you need to do this even if you aren't331 serving multiple installations in this case). Then add the ``PythonImport``332 line in the main server configuration (i.e., outside the ``Location`` or333 ``VirtualHost`` sections). For example::334 335 PythonInterpreter my_django336 PythonImport /path/to/my/project/file.py my_django337 338 Note that you can use an absolute path here (or a normal dotted import path),339 as described in the `mod_python manual`_. We use an absolute path in the340 above example because if any Python path modifications are required to access341 your project, they will not have been done at the time the ``PythonImport``342 line is processed.343 344 .. _Egg: http://peak.telecommunity.com/DevCenter/PythonEggs345 .. _PythonImport: http://www.modpython.org/live/current/doc-html/dir-other-pimp.html346 .. _mod_python manual: PythonImport_347 __ `Multiple Django installations on the same Apache`_348 349 Error handling350 ==============351 352 When you use Apache/mod_python, errors will be caught by Django -- in other353 words, they won't propagate to the Apache level and won't appear in the Apache354 ``error_log``.355 356 The exception for this is if something is really wonky in your Django setup. In357 that case, you'll see an "Internal Server Error" page in your browser and the358 full Python traceback in your Apache ``error_log`` file. The ``error_log``359 traceback is spread over multiple lines. (Yes, this is ugly and rather hard to360 read, but it's how mod_python does things.)361 362 If you get a segmentation fault363 ===============================364 365 If Apache causes a segmentation fault, there are two probable causes, neither366 of which has to do with Django itself.367 368 1. It may be because your Python code is importing the "pyexpat" module,369 which may conflict with the version embedded in Apache. For full370 information, see `Expat Causing Apache Crash`_.371 372 2. It may be because you're running mod_python and mod_php in the same373 Apache instance, with MySQL as your database backend. In some cases,374 this causes a known mod_python issue due to version conflicts in PHP and375 the Python MySQL backend. There's full information in the376 `mod_python FAQ entry`_.377 378 If you continue to have problems setting up mod_python, a good thing to do is379 get a barebones mod_python site working, without the Django framework. This is380 an easy way to isolate mod_python-specific problems. `Getting mod_python Working`_381 details this procedure.382 383 The next step should be to edit your test code and add an import of any384 Django-specific code you're using -- your views, your models, your URLconf,385 your RSS configuration, etc. Put these imports in your test handler function386 and access your test URL in a browser. If this causes a crash, you've confirmed387 it's the importing of Django code that causes the problem. Gradually reduce the388 set of imports until it stops crashing, so as to find the specific module that389 causes the problem. Drop down further into modules and look into their imports,390 as necessary.391 392 .. _Expat Causing Apache Crash: http://www.dscpl.com.au/wiki/ModPython/Articles/ExpatCausingApacheCrash393 .. _mod_python FAQ entry: http://modpython.org/FAQ/faqw.py?req=show&file=faq02.013.htp394 .. _Getting mod_python Working: http://www.dscpl.com.au/wiki/ModPython/Articles/GettingModPythonWorking395 396 If you get a UnicodeEncodeError397 ===============================398 399 If you're taking advantage of the internationalization features of Django (see400 :doc:`/topics/i18n/index`) and you intend to allow users to upload files, you must401 ensure that the environment used to start Apache is configured to accept402 non-ASCII file names. If your environment is not correctly configured, you403 will trigger ``UnicodeEncodeError`` exceptions when calling functions like404 ``os.path()`` on filenames that contain non-ASCII characters.405 406 To avoid these problems, the environment used to start Apache should contain407 settings analogous to the following::408 409 export LANG='en_US.UTF-8'410 export LC_ALL='en_US.UTF-8'411 412 Consult the documentation for your operating system for the appropriate syntax413 and location to put these configuration items; ``/etc/apache2/envvars`` is a414 common location on Unix platforms. Once you have added these statements415 to your environment, restart Apache. -
docs/howto/deployment/wsgi/modwsgi.txt
diff --git a/docs/howto/deployment/wsgi/modwsgi.txt b/docs/howto/deployment/wsgi/modwsgi.txt index 1aa4009..8398f12 100644
a b other approaches: 176 176 177 177 3. Copy the admin static files so that they live within your Apache 178 178 document root. 179 180 If you get a UnicodeEncodeError 181 =============================== 182 183 If you're taking advantage of the internationalization features of Django (see 184 :doc:`/topics/i18n/index`) and you intend to allow users to upload files, you must 185 ensure that the environment used to start Apache is configured to accept 186 non-ASCII file names. If your environment is not correctly configured, you 187 will trigger ``UnicodeEncodeError`` exceptions when calling functions like 188 ``os.path()`` on filenames that contain non-ASCII characters. 189 190 To avoid these problems, the environment used to start Apache should contain 191 settings analogous to the following:: 192 193 export LANG='en_US.UTF-8' 194 export LC_ALL='en_US.UTF-8' 195 196 Consult the documentation for your operating system for the appropriate syntax 197 and location to put these configuration items; ``/etc/apache2/envvars`` is a 198 common location on Unix platforms. Once you have added these statements 199 to your environment, restart Apache. -
docs/index.txt
diff --git a/docs/index.txt b/docs/index.txt index a5d2e13..66c8e73 100644
a b The development process 156 156 :doc:`Overview <howto/deployment/index>` | 157 157 :doc:`WSGI servers <howto/deployment/wsgi/index>` | 158 158 :doc:`FastCGI/SCGI/AJP <howto/deployment/fastcgi>` | 159 :doc:`Apache/mod_python (deprecated) <howto/deployment/modpython>` |160 159 :doc:`Apache authentication <howto/apache-auth>` | 161 160 :doc:`Handling static files <howto/static-files>` | 162 161 :doc:`Tracking code errors by email <howto/error-reporting>` -
docs/ref/contrib/gis/deployment.txt
diff --git a/docs/ref/contrib/gis/deployment.txt b/docs/ref/contrib/gis/deployment.txt index c50a378..d98fc51 100644
a b Deploying GeoDjango 13 13 Apache 14 14 ====== 15 15 In this section there are some example ``VirtualHost`` directives for 16 when deploying using either ``mod_python`` or ``mod_wsgi``. At this 17 time, we recommend ``mod_wsgi``, as it is now officially recommended 18 way to deploy Django applications with Apache. Moreover, if 19 ``mod_python`` is used, then a prefork version of Apache must also be 20 used. As long as ``mod_wsgi`` is configured correctly, it does not 16 when deploying using ``mod_wsgi``, which is now officially the recommended 17 way to deploy Django applications with Apache. 18 As long as ``mod_wsgi`` is configured correctly, it does not 21 19 matter whether the version of Apache is prefork or worker. 22 20 23 21 .. note:: … … Example:: 56 54 For more information, please consult Django's 57 55 :doc:`mod_wsgi documentation </howto/deployment/wsgi/modwsgi>`. 58 56 59 ``mod_python``60 --------------61 62 .. warning::63 Support for mod_python will be deprecated in a future release of Django. If64 you are configuring a new deployment, you are strongly encouraged to65 consider using :doc:`mod_wsgi </howto/deployment/wsgi/modwsgi>` or any of66 the other :doc:`supported servers </howto/deployment/index>`.67 68 Example::69 70 <VirtualHost *:80>71 72 <Location "/">73 SetHandler mod_python74 PythonHandler django.core.handlers.modpython75 SetEnv DJANGO_SETTINGS_MODULE world.settings76 PythonDebug On77 PythonPath "['/var/www/apps'] + sys.path"78 </Location>79 80 Alias /media/ "/usr/lib/python2.6/site-packages/django/contrib/admin/media/"81 <Location "/media">82 SetHandler None83 </Location>84 85 </VirtualHost>86 87 .. warning::88 89 When using ``mod_python`` you *must* be using a prefork version of Apache, or90 else your GeoDjango application may crash Apache.91 92 For more information, please consult Django's93 :doc:`mod_python documentation </howto/deployment/modpython>`.94 95 57 Lighttpd 96 58 ======== 97 59 -
docs/ref/request-response.txt
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt index c0ae73e..ae736b1 100644
a b All attributes except ``session`` should be considered read-only. 56 56 .. attribute:: HttpRequest.path_info 57 57 58 58 Under some Web server configurations, the portion of the URL after the host 59 name is split up into a script prefix portion and a path info portion 60 (this happens, for example, when using the ``django.root`` option 61 with the :doc:`modpython handler from Apache </howto/deployment/modpython>`). 59 name is split up into a script prefix portion and a path info portion. 62 60 The ``path_info`` attribute always contains the path info portion of the 63 61 path, no matter what Web server is being used. Using this instead of 64 62 attr:`~HttpRequest.path` can make your code much easier to move between test 65 63 and deployment servers. 66 64 67 For example, if the `` django.root`` for your application is set to65 For example, if the ``WSGIScriptAlias`` for your application is set to 68 66 ``"/minfo"``, then ``path`` might be ``"/minfo/music/bands/the_beatles/"`` 69 67 and ``path_info`` would be ``"/music/bands/the_beatles/"``. 70 68 -
docs/topics/http/urls.txt
diff --git a/docs/topics/http/urls.txt b/docs/topics/http/urls.txt index 1c2849d..73c06ca 100644
a b find the base URL of the Django project within its Web server 1020 1020 (normally, :func:`~django.core.urlresolvers.reverse` takes care of this for 1021 1021 you). In that case, you can call ``get_script_prefix()``, which will return the 1022 1022 script prefix portion of the URL for your Django project. If your Django 1023 project is at the root of its Web server, this is always ``"/"``, but it can be 1024 changed, for instance by using ``django.root`` (see :doc:`How to use 1025 Django with Apache and mod_python </howto/deployment/modpython>`). 1023 project is at the root of its Web server, this is always ``"/"``. -
tests/regressiontests/requests/tests.py
diff --git a/tests/regressiontests/requests/tests.py b/tests/regressiontests/requests/tests.py index f986046..5c3cf59 100644
a b from datetime import datetime, timedelta 4 4 from StringIO import StringIO 5 5 6 6 from django.conf import settings 7 from django.core.handlers.modpython import ModPythonRequest8 7 from django.core.handlers.wsgi import WSGIRequest, LimitedStream 9 8 from django.http import HttpRequest, HttpResponse, parse_cookie, build_request_repr, UnreadablePostError 10 9 from django.test.utils import get_warnings_state, restore_warnings_state … … class RequestsTests(unittest.TestCase): 54 53 self.assertEqual(build_request_repr(request, path_override='/otherpath/', GET_override={u'a': u'b'}, POST_override={u'c': u'd'}, COOKIES_override={u'e': u'f'}, META_override={u'g': u'h'}), 55 54 u"<WSGIRequest\npath:/otherpath/,\nGET:{u'a': u'b'},\nPOST:{u'c': u'd'},\nCOOKIES:{u'e': u'f'},\nMETA:{u'g': u'h'}>") 56 55 57 def test_modpythonrequest(self):58 class FakeModPythonRequest(ModPythonRequest):59 def __init__(self, *args, **kwargs):60 super(FakeModPythonRequest, self).__init__(*args, **kwargs)61 self._get = self._post = self._meta = self._cookies = {}62 63 class Dummy:64 def get_options(self):65 return {}66 67 req = Dummy()68 req.uri = 'bogus'69 request = FakeModPythonRequest(req)70 self.assertEqual(request.path, 'bogus')71 self.assertEqual(request.GET.keys(), [])72 self.assertEqual(request.POST.keys(), [])73 self.assertEqual(request.COOKIES.keys(), [])74 self.assertEqual(request.META.keys(), [])75 76 def test_modpythonrequest_repr(self):77 class Dummy:78 def get_options(self):79 return {}80 req = Dummy()81 req.uri = '/somepath/'82 request = ModPythonRequest(req)83 request._get = {u'get-key': u'get-value'}84 request._post = {u'post-key': u'post-value'}85 request._cookies = {u'post-key': u'post-value'}86 request._meta = {u'post-key': u'post-value'}87 self.assertEqual(repr(request), u"<ModPythonRequest\npath:/somepath/,\nGET:{u'get-key': u'get-value'},\nPOST:{u'post-key': u'post-value'},\nCOOKIES:{u'post-key': u'post-value'},\nMETA:{u'post-key': u'post-value'}>")88 self.assertEqual(build_request_repr(request), repr(request))89 self.assertEqual(build_request_repr(request, path_override='/otherpath/', GET_override={u'a': u'b'}, POST_override={u'c': u'd'}, COOKIES_override={u'e': u'f'}, META_override={u'g': u'h'}),90 u"<ModPythonRequest\npath:/otherpath/,\nGET:{u'a': u'b'},\nPOST:{u'c': u'd'},\nCOOKIES:{u'e': u'f'},\nMETA:{u'g': u'h'}>")91 92 56 def test_parse_cookie(self): 93 57 self.assertEqual(parse_cookie('invalid:key=true'), {}) 94 58