| 1 |
================================= |
|---|
| 2 |
>>! |
|---|
| 3 |
How to use Django with mod_python |
|---|
| 4 |
<<! |
|---|
| 5 |
>>!! |
|---|
| 6 |
mod_pythonìì ì¥ê³ ìŽìíêž° |
|---|
| 7 |
<<!! |
|---|
| 8 |
================================= |
|---|
| 9 |
|
|---|
| 10 |
>>! |
|---|
| 11 |
Apache_ with `mod_python`_ currently is the preferred setup for using Django |
|---|
| 12 |
on a production server. |
|---|
| 13 |
<<! |
|---|
| 14 |
>>!! |
|---|
| 15 |
Apache_ with `mod_python`_ì ì í ìë²(production server)ìì ì¥ê³ 륌 ì¬ì©íêž° ìíŽ |
|---|
| 16 |
íì¬ ê°ì¥ ì ížëë ì€ì ì |
|---|
| 17 |
ëë€.. |
|---|
| 18 |
<<!! |
|---|
| 19 |
|
|---|
| 20 |
>>! |
|---|
| 21 |
mod_python is similar to `mod_perl`_ : It embeds Python within Apache and loads |
|---|
| 22 |
Python code into memory when the server starts. Code stays in memory throughout |
|---|
| 23 |
the life of an Apache process, which leads to significant performance gains over |
|---|
| 24 |
other server arrangements. |
|---|
| 25 |
<<! |
|---|
| 26 |
>>!! |
|---|
| 27 |
mod_pythonì `mod_perl`_곌 ì ì¬í©ëë€ : ìíì¹ ëŽìì íìŽì¬ì ìë² ë©íê³ , |
|---|
| 28 |
ìíì¹ê° ììí ë íìŽì¬ ìœë륌 ìœë륌 ë©ëªšëЬì ë¡ëí©ëë€. |
|---|
| 29 |
ìœëë ìíì¹ íë¡ìžì€ê° ìŽììë ëì ë©ëªšëЬì ëšì ììŒë©°, |
|---|
| 30 |
ìŽë ë€ë¥ž ìë²êµ¬ì±ë³Žë€ 죌목í ë§í ì±ë¥ í¥ìì ìŽëìŽ ë |
|---|
| 31 |
ëë€. |
|---|
| 32 |
<<!! |
|---|
| 33 |
|
|---|
| 34 |
>>! |
|---|
| 35 |
Django requires Apache 2.x and mod_python 3.x, and you should use Apache's |
|---|
| 36 |
`prefork MPM`_, as opposed to the `worker MPM`_. |
|---|
| 37 |
<<! |
|---|
| 38 |
>>!! |
|---|
| 39 |
ì¥ê³ ë ìíì¹ 2.x ì mod_python 3.x 륌 íìë¡ íë©°, |
|---|
| 40 |
ë°ëì `worker MPM`_ì ëë¹ëë `prefork MPM`_ ìíì¹ë¥Œ ì¬ì©íŽìŒ í©ëë€. |
|---|
| 41 |
<<!! |
|---|
| 42 |
|
|---|
| 43 |
>>! |
|---|
| 44 |
You may also be interested in `How to use Django with FastCGI, SCGI or AJP`_ |
|---|
| 45 |
(which also covers SCGI and AJP). |
|---|
| 46 |
<<! |
|---|
| 47 |
>>!! |
|---|
| 48 |
`FastCGI, SCGI ëë AJP ìì ì¥ê³ ìŽìíêž°`_ë ìŽíŽë³Žìžì. |
|---|
| 49 |
(SCGIì AJP ëí ë€ë£¹ëë€). |
|---|
| 50 |
<<!! |
|---|
| 51 |
|
|---|
| 52 |
.. _Apache: http://httpd.apache.org/ |
|---|
| 53 |
.. _mod_python: http://www.modpython.org/ |
|---|
| 54 |
.. _mod_perl: http://perl.apache.org/ |
|---|
| 55 |
.. _prefork MPM: http://httpd.apache.org/docs/2.2/mod/prefork.html |
|---|
| 56 |
.. _worker MPM: http://httpd.apache.org/docs/2.2/mod/worker.html |
|---|
| 57 |
>>! |
|---|
| 58 |
.. _How to use Django with FastCGI, SCGI or AJP: ../fastcgi/ |
|---|
| 59 |
<<! |
|---|
| 60 |
>>!! |
|---|
| 61 |
.. _FastCGI, SCGI ëë AJPìì ì¥ê³ ìŽìíêž°: ../fastcgi/ |
|---|
| 62 |
<<!! |
|---|
| 63 |
|
|---|
| 64 |
>>! |
|---|
| 65 |
Basic configuration |
|---|
| 66 |
<<! |
|---|
| 67 |
>>!! |
|---|
| 68 |
Ʞ볞 ì€ì |
|---|
| 69 |
<<!! |
|---|
| 70 |
=================== |
|---|
| 71 |
|
|---|
| 72 |
>>! |
|---|
| 73 |
To configure Django with mod_python, first make sure you have Apache installed, |
|---|
| 74 |
with the mod_python module activated. |
|---|
| 75 |
<<! |
|---|
| 76 |
>>!! |
|---|
| 77 |
mod_pythonìì ì¥ê³ 륌 ì€ì íêž° ìíŽì, 뚌ì ì¬ë¬ë¶ì mod_python 몚ëìŽ íì±íë |
|---|
| 78 |
ìíì¹ê° ì€ì¹ëìŽ ììŽìŒ í©ëë€, |
|---|
| 79 |
<<!! |
|---|
| 80 |
|
|---|
| 81 |
>>! |
|---|
| 82 |
Then edit your ``httpd.conf`` file and add the following:: |
|---|
| 83 |
<<! |
|---|
| 84 |
>>!! |
|---|
| 85 |
ê·žëŠ¬ê³ ëì ì¬ë¬ë¶ì ``httpd.conf`` íìŒì ìŽìŽì ë€ìì ì¶ê°íììì€:: |
|---|
| 86 |
<<!! |
|---|
| 87 |
|
|---|
| 88 |
<Location "/mysite/"> |
|---|
| 89 |
SetHandler python-program |
|---|
| 90 |
PythonHandler django.core.handlers.modpython |
|---|
| 91 |
SetEnv DJANGO_SETTINGS_MODULE mysite.settings |
|---|
| 92 |
PythonDebug On |
|---|
| 93 |
</Location> |
|---|
| 94 |
|
|---|
| 95 |
>>! |
|---|
| 96 |
...and replace ``mysite.settings`` with the Python import path to your Django |
|---|
| 97 |
project's settings file. |
|---|
| 98 |
<<! |
|---|
| 99 |
>>!! |
|---|
| 100 |
...ê·žëŠ¬ê³ ``mysite.settings``륌 ì¬ë¬ë¶ì ì¥ê³ íë¡ì ížì ì€ì íìŒì ëí íìŽì¬ 겜ë¡ë¡ ë첎íììì€. |
|---|
| 101 |
<<!! |
|---|
| 102 |
|
|---|
| 103 |
>>! |
|---|
| 104 |
This tells Apache: "Use mod_python for any URL at or under '/mysite/', using the |
|---|
| 105 |
Django mod_python handler." It passes the value of ``DJANGO_SETTINGS_MODULE`` |
|---|
| 106 |
so mod_python knows which settings to use. |
|---|
| 107 |
<<! |
|---|
| 108 |
>>!! |
|---|
| 109 |
ìŽë ìíì¹ìê² ì§ì륌 í©ëë€: "ì¥ê³ mod_python ížë€ë¬ë¥Œ ì¬ì©íì¬, |
|---|
| 110 |
'/mysite/' ìŽíì ìŽë í URLì ëíŽìë mod_pythonì ì¬ì©íëŒ." |
|---|
| 111 |
``DJANGO_SETTINGS_MODULE``ì ê°ì ì ë¬íì¬ |
|---|
| 112 |
mod_pythonì ìŽë€ ì€ì ì ì¬ì©íŽìŒ íëì§ ìê² ë©ëë€. |
|---|
| 113 |
(mod_pythonì ìŽë€ ì€ì ì ì¬ì©íŽìŒ íëì§ ``DJANGO_SETTINGS_MODULE``ì ê°ìŒë¡ ìì ììµëë€.) |
|---|
| 114 |
<<!! |
|---|
| 115 |
|
|---|
| 116 |
>>! |
|---|
| 117 |
Note that we're using the ``<Location>`` directive, not the ``<Directory>`` |
|---|
| 118 |
directive. The latter is used for pointing at places on your filesystem, |
|---|
| 119 |
whereas ``<Location>`` points at places in the URL structure of a Web site. |
|---|
| 120 |
``<Directory>`` would be meaningless here. |
|---|
| 121 |
<<! |
|---|
| 122 |
>>!! |
|---|
| 123 |
``<Directory>`` ì§ììê° ìëëŒ, ``<Location>`` ì§ììê° ì¬ì©ëê³ ìë ê²ì 죌ìíììì€. |
|---|
| 124 |
ì ìë ì¬ë¬ë¶ì íìŒìì€í |
|---|
| 125 |
ìì ìì¹ë¥Œ ê°ëЬí€ëë° ë°íŽ, |
|---|
| 126 |
``<Location>``ì ì¹ì¬ìŽížì URL 구조ìì ìì¹ë¥Œ ê°ëЬíµëë€. |
|---|
| 127 |
ì¬êž°ìë ``<Directory>`` ê° ì믞 ììµëë€. |
|---|
| 128 |
<<!! |
|---|
| 129 |
|
|---|
| 130 |
>>! |
|---|
| 131 |
Also, if your Django project is not on the default ``PYTHONPATH`` for your |
|---|
| 132 |
computer, you'll have to tell mod_python where your project can be found: |
|---|
| 133 |
<<! |
|---|
| 134 |
>>!! |
|---|
| 135 |
ëí, ë§ìœ ì¬ë¬ë¶ì ì¥ê³ íë¡ì ížê° 컎íší°ì Ʞ볞 ``PYTHONPATH``ìì ìë€ë©Ž, |
|---|
| 136 |
ì¬ë¬ë¶ì íë¡ì ížë¥Œ ìŽëì ì°ŸììŒ íëì§ë¥Œ mod_pythonìê² ìë €ì€ìŒ í©ëë€. |
|---|
| 137 |
<<!! |
|---|
| 138 |
|
|---|
| 139 |
.. parsed-literal:: |
|---|
| 140 |
|
|---|
| 141 |
<Location "/mysite/"> |
|---|
| 142 |
SetHandler python-program |
|---|
| 143 |
PythonHandler django.core.handlers.modpython |
|---|
| 144 |
SetEnv DJANGO_SETTINGS_MODULE mysite.settings |
|---|
| 145 |
PythonDebug On |
|---|
| 146 |
**PythonPath "['/path/to/project'] + sys.path"** |
|---|
| 147 |
</Location> |
|---|
| 148 |
|
|---|
| 149 |
>>! |
|---|
| 150 |
The value you use for ``PythonPath`` should include the parent directories of |
|---|
| 151 |
all the modules you are going to import in your application. It should also |
|---|
| 152 |
include the parent directory of the ``DJANGO_SETTINGS_MODULE`` location. This |
|---|
| 153 |
is exactly the same situation as setting the Python path for interactive |
|---|
| 154 |
usage. Whenever you try to import something, Python will run through all the |
|---|
| 155 |
directories in ``sys.path`` in turn, from first to last, and try to import |
|---|
| 156 |
from each directory until one succeeds. |
|---|
| 157 |
<<! |
|---|
| 158 |
>>!! |
|---|
| 159 |
ì¬ë¬ë¶ìŽ ì¬ì©íë ``PythonPath`` ê°ì ì¬ë¬ë¶ì ìŽí늬ìŒìŽì |
|---|
| 160 |
ìì import íë €ê³ íë |
|---|
| 161 |
몚ë 몚ëë€ì ë¶ëªš ëë í 늬륌 êŒ í¬íšíŽìŒ í©ëë€. ëí |
|---|
| 162 |
``DJANGO_SETTINGS_MODULE`` location ì ë¶ëªš ëë í 늬륌 í¬íšíŽìŒ í©ëë€. |
|---|
| 163 |
ìŽë ë°ë¡ íìŽì¬ì ëííìŒë¡ ì¬ì©í ë |
|---|
| 164 |
path륌 ì€ì íë ê²ê³Œ ëê°ì ìí©ì |
|---|
| 165 |
ëë€. |
|---|
| 166 |
ì¬ë¬ë¶ìŽ ë¬Žìžê°ë¥Œ import íë € í ëë§ë€, íìŽì¬ì import ê° ì±ê³µí ëê¹ì§ |
|---|
| 167 |
``sys.path`` ìì 몚ë ëë í 늬륌 ì²ìë¶í° ëê¹ì§ ì°šë¡ë¡ ìëíŽ ëŽ |
|---|
| 168 |
ëë€. |
|---|
| 169 |
<<!! |
|---|
| 170 |
|
|---|
| 171 |
>>! |
|---|
| 172 |
An example might make this clearer. Suppose |
|---|
| 173 |
you have some applications under ``/usr/local/django-apps/`` (for example, |
|---|
| 174 |
``/usr/local/django-apps/weblog/`` and so forth), your settings file is at |
|---|
| 175 |
``/var/www/mysite/settings.py`` and you have specified |
|---|
| 176 |
``DJANGO_SETTINGS_MODULE`` as in the above example. In this case, you would |
|---|
| 177 |
need to write your ``PythonPath`` directive as:: |
|---|
| 178 |
<<! |
|---|
| 179 |
>>!! |
|---|
| 180 |
ìì 륌 볎멎 íì€íŽ ì§ëë€. ê°ë ¹ |
|---|
| 181 |
``/usr/local/django-apps/`` ëë í 늬 ìëì ì¬ë¬ë¶ì ìŽë€ ìŽí늬ìŒìŽì |
|---|
| 182 |
|
|---|
| 183 |
(``/usr/local/django-apps/weblog/`` ê°ì)ìŽ ìê³ , ì¬ë¬ë¶ì ì€ì íìŒì |
|---|
| 184 |
``/var/www/mysite/settings.py`` ìŽëŒì ì¬ë¬ë¶ì ``DJANGO_SETTINGS_MODULE`` 륌 |
|---|
| 185 |
ìì ìì ì²ëŒ ì€ì íìµëë€. ìŽ ê²œì°, ì¬ë¬ë¶ì ``PythonPath`` ì§ìì륌 |
|---|
| 186 |
ìëì ê°ìŽ ìì±í íìê° ììµëë€:: |
|---|
| 187 |
<<!! |
|---|
| 188 |
|
|---|
| 189 |
PythonPath "['/usr/local/django-apps/', '/var/www'] + sys.path" |
|---|
| 190 |
|
|---|
| 191 |
>>! |
|---|
| 192 |
With this path, ``import weblog`` and ``import mysite.settings`` will both |
|---|
| 193 |
work. If you had ``import blogroll`` in your code somewhere and ``blogroll`` |
|---|
| 194 |
lived under the ``weblog/`` directory, you would *also* need to add |
|---|
| 195 |
``/usr/local/django-apps/weblog/`` to your ``PythonPath``. Remember: the |
|---|
| 196 |
**parent directories** of anything you import directly must be on the Python |
|---|
| 197 |
path. |
|---|
| 198 |
<<! |
|---|
| 199 |
>>!! |
|---|
| 200 |
ìŽ path ìì, ``import weblog`` ì ``import mysite.settings`` ë ë€ ìëí©ëë€. ë§ìœ ì¬ë¬ë¶ì |
|---|
| 201 |
ìœë ìŽëê°ì ``import blogroll``ê° ìê³ ``blogroll``ìŽ ``weblog/`` ëë í 늬 |
|---|
| 202 |
ìëì ìì¹íê³ ìë€ë©Ž, ì¬ë¬ë¶ì *ëí* ``/usr/local/django-apps/weblog/`` 륌 |
|---|
| 203 |
``PythonPath`` ìì ë£ìŽìŒ í©ëë€. |
|---|
| 204 |
êž°ìµíììì€:ì¬ë¬ë¶ìŽ ìì import íë €ê³ íë |
|---|
| 205 |
몚ë ê²ë€ì **ë¶ëªš ëë í 늬**ë ë°ëì íìŽì¬ path ìì ììŽìŒ í©ëë€. |
|---|
| 206 |
<<!! |
|---|
| 207 |
|
|---|
| 208 |
.. note:: |
|---|
| 209 |
|
|---|
| 210 |
>>! |
|---|
| 211 |
If you're using Windows, we still recommended that you use forward |
|---|
| 212 |
slashes in the pathnames, even though Windows normally uses the backslash |
|---|
| 213 |
character as its native separator. Apache knows how to convert from the |
|---|
| 214 |
forward slash format to the native format, so this approach is portable and |
|---|
| 215 |
easier to read. (It avoids tricky problems with having to double-escape |
|---|
| 216 |
backslashes.) |
|---|
| 217 |
<<! |
|---|
| 218 |
>>!! |
|---|
| 219 |
ë§ìœ ì¬ë¬ë¶ìŽ Windows륌 ì¬ì©ì€ìŽëŒë©Ž, ìŒë°ì ìŒë¡ Windowsë ìì¬ëì 묞ì(\)륌 |
|---|
| 220 |
ìŽì첎ì ì ê²œë¡ êµ¬ë¶ìë¡ ì¬ì©íì§ë§, ì°ëЬë ì¬ì í ì¬ëì(/)륌 겜ë¡ì ì¬ì©í ê²ì |
|---|
| 221 |
ì¶ì²í©ëë€. ìíì¹ë ì¬ëì í¬ë§·ì ìŽë»ê² ìŽì첎ì í¬ë§·ìŒë¡ ë³ê²œí ì§ ìêž° ë묞ì, |
|---|
| 222 |
ìŽ ë°©ììŽ ê°ížíê³ (portable) ë ìœêž° ìœìµëë€. |
|---|
| 223 |
(ìŽë ìŽì€-ìŽì€ìŒìŽí ìì¬ëì(\\) 묞ì 륌 |
|---|
| 224 |
íŒíë êœìì |
|---|
| 225 |
ëë€.) |
|---|
| 226 |
<<!! |
|---|
| 227 |
|
|---|
| 228 |
>>! |
|---|
| 229 |
This is valid even on a Windows system:: |
|---|
| 230 |
<<! |
|---|
| 231 |
>>!! |
|---|
| 232 |
Windows ìì€í |
|---|
| 233 |
ììì ìŽê² ìì ì íší©ëë€:: |
|---|
| 234 |
<<!! |
|---|
| 235 |
|
|---|
| 236 |
PythonPath "['c:/path/to/project'] + sys.path" |
|---|
| 237 |
|
|---|
| 238 |
>>! |
|---|
| 239 |
You can also add directives such as ``PythonAutoReload Off`` for performance. |
|---|
| 240 |
See the `mod_python documentation`_ for a full list of options. |
|---|
| 241 |
<<! |
|---|
| 242 |
>>!! |
|---|
| 243 |
ì¬ë¬ë¶ì ëí ``PythonAutoReload Off`` ì§ìì륌 ì±ë¥ì ìíŽ ì¶ê°í ì ììµëë€. |
|---|
| 244 |
ì 첎 ìµì |
|---|
| 245 |
ë€ì `mod_python 묞ì`_ìì 볌 ì ììµëë€. |
|---|
| 246 |
<<!! |
|---|
| 247 |
|
|---|
| 248 |
>>! |
|---|
| 249 |
Note that you should set ``PythonDebug Off`` on a production server. If you |
|---|
| 250 |
leave ``PythonDebug On``, your users would see ugly (and revealing) Python |
|---|
| 251 |
tracebacks if something goes wrong within mod_python. |
|---|
| 252 |
<<! |
|---|
| 253 |
>>!! |
|---|
| 254 |
ì¬ë¬ë¶ì ì í ìë²(production server)ìììë ë°ëì ``PythonDebug Off``ë¡ ì€ì íŽìŒ í©ëë€. |
|---|
| 255 |
``PythonDebug On`` ìžì±ë¡ ë멎, ë§ìœ mod_python ììì ëê° ì못 ëììë |
|---|
| 256 |
ì¬ë¬ë¶ì ì¬ì©ìë€ì 볎Ʞíí(ê·žëŠ¬ê³ ì ëëŒí) íìŽì¬ traceback ë€ì ë³Žê² ë ê²ì |
|---|
| 257 |
ëë€. |
|---|
| 258 |
<<!! |
|---|
| 259 |
|
|---|
| 260 |
>>! |
|---|
| 261 |
Restart Apache, and any request to /mysite/ or below will be served by Django. |
|---|
| 262 |
Note that Django's URLconfs won't trim the "/mysite/" -- they get passed the |
|---|
| 263 |
full URL. |
|---|
| 264 |
<<! |
|---|
| 265 |
>>!! |
|---|
| 266 |
ìíì¹ë¥Œ ì¬ ììí멎, /mysite/ ëë ê·ž ìëì ìŽë í ìì²ì ëíŽìë ì¥ê³ ê° ì²ëŠ¬ë¥Œ í©ëë€. |
|---|
| 267 |
ì¥ê³ ì URLconfë "/mysite/" 륌 trim íì§ ììì 죌ì íììì€ -- full URLìŽ ì ë¬ë©ëë€. |
|---|
| 268 |
|
|---|
| 269 |
<<!! |
|---|
| 270 |
|
|---|
| 271 |
>>! |
|---|
| 272 |
When deploying Django sites on mod_python, you'll need to restart Apache each |
|---|
| 273 |
time you make changes to your Python code. |
|---|
| 274 |
<<! |
|---|
| 275 |
>>!! |
|---|
| 276 |
ì¥ê³ 륌 mod_pythonìŒë¡ ìŽì©í ë, ì¬ë¬ë¶ì íìŽì¬ ìœë륌 ë³ê²œí ëë§ë€ |
|---|
| 277 |
ìíì¹ë¥Œ ì¬ ììí íìê° ììµëë€. |
|---|
| 278 |
<<!! |
|---|
| 279 |
|
|---|
| 280 |
>>! |
|---|
| 281 |
Multiple Django installations on the same Apache |
|---|
| 282 |
<<! |
|---|
| 283 |
>>!! |
|---|
| 284 |
í ìíì¹ììì ì¥ê³ ë€ì€ ì€ì¹ |
|---|
| 285 |
<<!! |
|---|
| 286 |
================================================ |
|---|
| 287 |
|
|---|
| 288 |
>>! |
|---|
| 289 |
It's entirely possible to run multiple Django installations on the same Apache |
|---|
| 290 |
instance. Just use ``VirtualHost`` for that, like so:: |
|---|
| 291 |
<<! |
|---|
| 292 |
>>!! |
|---|
| 293 |
í ìíì¹ ìžì€íŽì€ ììì ë€ì€ ì€ì¹ë ì¥ê³ 륌 ì€í ìí¬ ì ììµëë€. ë°ë¡ VirtualHost 륌 |
|---|
| 294 |
ìëì ê°ìŽ ì¬ì©í©ëë€:: |
|---|
| 295 |
<<!! |
|---|
| 296 |
|
|---|
| 297 |
NameVirtualHost * |
|---|
| 298 |
|
|---|
| 299 |
<VirtualHost *> |
|---|
| 300 |
ServerName www.example.com |
|---|
| 301 |
# ... |
|---|
| 302 |
SetEnv DJANGO_SETTINGS_MODULE mysite.settings |
|---|
| 303 |
</VirtualHost> |
|---|
| 304 |
|
|---|
| 305 |
<VirtualHost *> |
|---|
| 306 |
ServerName www2.example.com |
|---|
| 307 |
# ... |
|---|
| 308 |
SetEnv DJANGO_SETTINGS_MODULE mysite.other_settings |
|---|
| 309 |
</VirtualHost> |
|---|
| 310 |
|
|---|
| 311 |
>>! |
|---|
| 312 |
If you need to put two Django installations within the same ``VirtualHost``, |
|---|
| 313 |
you'll need to take a special precaution to ensure mod_python's cache doesn't |
|---|
| 314 |
mess things up. Use the ``PythonInterpreter`` directive to give different |
|---|
| 315 |
``<Location>`` directives separate interpreters:: |
|---|
| 316 |
<<! |
|---|
| 317 |
>>!! |
|---|
| 318 |
ë§ìœ ì¬ë¬ë¶ìŽ ê°ì ``VirtualHost``ìì ëê°ì ì¥ê³ 륌 ì€ì¹í íìê° ìë€ë©Ž, |
|---|
| 319 |
ì¬ë¬ë¶ì mod_pythonì ìºìê° êŒ¬ìŽì§ ìëë¡ íêž° ìí í¹ë³í ìë°©ì± |
|---|
| 320 |
ìŽ íìí©ëë€. |
|---|
| 321 |
``PythonInterpreter`` ì§ìì륌 ì¬ì©íì¬ ê°êž° ë€ë¥ž ``<Location>`` ì§ììë€ìŽ ìží°í늬í°ë¥Œ |
|---|
| 322 |
ë¶ëЬíëë¡ íììì€:: |
|---|
| 323 |
<<!! |
|---|
| 324 |
|
|---|
| 325 |
<VirtualHost *> |
|---|
| 326 |
ServerName www.example.com |
|---|
| 327 |
# ... |
|---|
| 328 |
<Location "/something"> |
|---|
| 329 |
SetEnv DJANGO_SETTINGS_MODULE mysite.settings |
|---|
| 330 |
PythonInterpreter mysite |
|---|
| 331 |
</Location> |
|---|
| 332 |
|
|---|
| 333 |
<Location "/otherthing"> |
|---|
| 334 |
SetEnv DJANGO_SETTINGS_MODULE mysite.other_settings |
|---|
| 335 |
PythonInterpreter othersite |
|---|
| 336 |
</Location> |
|---|
| 337 |
</VirtualHost> |
|---|
| 338 |
|
|---|
| 339 |
>>! |
|---|
| 340 |
The values of ``PythonInterpreter`` don't really matter, as long as they're |
|---|
| 341 |
different between the two ``Location`` blocks. |
|---|
| 342 |
<<! |
|---|
| 343 |
>>!! |
|---|
| 344 |
ê°êž° ë€ë¥ž ëê°ì ``Location`` ëžë ìì ìë í, ``PythonInterpreter`` ì ê°ì |
|---|
| 345 |
ì í 묞ì ëì§ ììµëë€. |
|---|
| 346 |
<<!! |
|---|
| 347 |
|
|---|
| 348 |
>>! |
|---|
| 349 |
Running a development server with mod_python |
|---|
| 350 |
<<! |
|---|
| 351 |
>>!! |
|---|
| 352 |
mod_pythonìì ê°ë° ìë²(developement server) ì€ííêž° |
|---|
| 353 |
<<!! |
|---|
| 354 |
============================================ |
|---|
| 355 |
|
|---|
| 356 |
>>! |
|---|
| 357 |
If you use mod_python for your development server, you can avoid the hassle of |
|---|
| 358 |
having to restart the server each time you make code changes. Just set |
|---|
| 359 |
``MaxRequestsPerChild 1`` in your ``httpd.conf`` file to force Apache to reload |
|---|
| 360 |
everything for each request. But don't do that on a production server, or we'll |
|---|
| 361 |
revoke your Django privileges. |
|---|
| 362 |
<<! |
|---|
| 363 |
>>!! |
|---|
| 364 |
ë§ìœ ì¬ë¬ë¶ìŽ ê°ë° ìë²(developement server)ìì mod_pythonì ì¬ì©íë€ë©Ž, |
|---|
| 365 |
ì¬ë¬ë¶ì ìœë륌 ë°ê¿ëë§ë€ ìíì¹ë¥Œ ì¬ìì íŽìŒíë ë¶ížíšì íŒí ì ììµëë€. |
|---|
| 366 |
ë°ë¡ ``httpd.conf`` íìŒì ``MaxRequestsPerChild 1``ì ì€ì íì¬ ë§€ ìì²ë§ë€ ê°ì ë¡ ìíì¹ê° 몚ë ê²ì 늬ë¡ë íëë¡ í©ëë€. |
|---|
| 367 |
íì§ë§ ì í ìë²(production server) ìììë ìŽë ê² íì§ ë§ììì€. ê·žë ì§ ììŒë©Ž, |
|---|
| 368 |
ì¬ë¬ë¶ì ì¥ê³ ê¶íë€ì ì¬ížì¶í©ëë€. |
|---|
| 369 |
<<!! |
|---|
| 370 |
|
|---|
| 371 |
>>! |
|---|
| 372 |
If you're the type of programmer who debugs using scattered ``print`` |
|---|
| 373 |
statements, note that ``print`` statements have no effect in mod_python; they |
|---|
| 374 |
don't appear in the Apache log, as one might expect. If you have the need to |
|---|
| 375 |
print debugging information in a mod_python setup, either do this:: |
|---|
| 376 |
<<! |
|---|
| 377 |
>>!! |
|---|
| 378 |
ë§ìœ ì¬ë¬ë¶ìŽ ì¬êž°ì êž° í©ìŽì§ ``print`` 묞ì ì¬ì©íì¬ ëë²ê¹ |
|---|
| 379 |
íë íë¡ê·žëëšž ë¶ë¥ëŒë©Ž, |
|---|
| 380 |
mod_python ìì ``print`` 묞ì ì묎 íšê³Œê° ììì 죌ì íììì€; í¹ì êž°ëíìì§ ëªšë¥Œ, |
|---|
| 381 |
ìíì¹ ë¡ê·žìë 볎ìŽì§ ììµëë€. ë§ìœ mod_python í겜ìì |
|---|
| 382 |
ëë²ê¹ |
|---|
| 383 |
ì 볎륌 êŒ ì°ìŽìŒ í íìê° ìë€ë©Ž, ìŽë ê² íììì€:: |
|---|
| 384 |
<<!! |
|---|
| 385 |
|
|---|
| 386 |
>>! |
|---|
| 387 |
assert False, the_value_i_want_to_see |
|---|
| 388 |
<<! |
|---|
| 389 |
>>!! |
|---|
| 390 |
assert False, ëŽê° ìê³ ì¶ì ê° |
|---|
| 391 |
<<!! |
|---|
| 392 |
|
|---|
| 393 |
>>! |
|---|
| 394 |
Or add the debugging information to the template of your page. |
|---|
| 395 |
<<! |
|---|
| 396 |
>>!! |
|---|
| 397 |
í¹ì ëë²ê¹ |
|---|
| 398 |
ì 볎륌 ì¬ë¬ë¶ íìŽì§ì í |
|---|
| 399 |
í늿ì ì¶ê° íììì€. |
|---|
| 400 |
<<!! |
|---|
| 401 |
|
|---|
| 402 |
>>! |
|---|
| 403 |
.. _mod_python documentation: http://modpython.org/live/current/doc-html/directives.html |
|---|
| 404 |
<<! |
|---|
| 405 |
>>!! |
|---|
| 406 |
.. _mod_python 묞ì: http://modpython.org/live/current/doc-html/directives.html |
|---|
| 407 |
<<!! |
|---|
| 408 |
|
|---|
| 409 |
>>! |
|---|
| 410 |
Serving media files |
|---|
| 411 |
<<! |
|---|
| 412 |
>>!! |
|---|
| 413 |
믞ëìŽ íìŒ ì²ëЬíêž° |
|---|
| 414 |
<<!! |
|---|
| 415 |
=================== |
|---|
| 416 |
|
|---|
| 417 |
>>! |
|---|
| 418 |
Django doesn't serve media files itself; it leaves that job to whichever Web |
|---|
| 419 |
server you choose. |
|---|
| 420 |
<<! |
|---|
| 421 |
>>!! |
|---|
| 422 |
ì¥ê³ ì첎ë 믞ëìŽ íìŒë€ì ì²ëЬíì§ ììµëë€; ì¥ê³ ë ê·ž ìì |
|---|
| 423 |
ì ì¬ë¬ë¶ìŽ ì íí |
|---|
| 424 |
ì¹ ìë²ìê² ëšê¹ëë€. |
|---|
| 425 |
<<!! |
|---|
| 426 |
|
|---|
| 427 |
>>! |
|---|
| 428 |
We recommend using a separate Web server -- i.e., one that's not also running |
|---|
| 429 |
Django -- for serving media. Here are some good choices: |
|---|
| 430 |
<<! |
|---|
| 431 |
>>!! |
|---|
| 432 |
ì°ëЬë ë¶ëЬë ì¹ìë² â ë°ê¿ë§í멎, ì¥ê³ 륌 ì€ííì§ ìë â 믞ëìŽ ì²ëŠ¬ë¥Œ ìí |
|---|
| 433 |
ì¹ìë²ë¥Œ ì¬ì©í ê²ì ì¶ì²í©ëë€. ì¬êž° ëªê°ì§ ì¢ì ì íìŽ ììµëë€: |
|---|
| 434 |
<<!! |
|---|
| 435 |
|
|---|
| 436 |
* lighttpd_ |
|---|
| 437 |
* TUX_ |
|---|
| 438 |
* A stripped-down version of Apache_ |
|---|
| 439 |
|
|---|
| 440 |
>>! |
|---|
| 441 |
If, however, you have no option but to serve media files on the same Apache |
|---|
| 442 |
``VirtualHost`` as Django, here's how you can turn off mod_python for a |
|---|
| 443 |
particular part of the site:: |
|---|
| 444 |
<<! |
|---|
| 445 |
>>!! |
|---|
| 446 |
ê·žë ì§ë§, ë§ìœ ì¬ë¬ë¶ìŽ ì íì ì¬ì§ê° ìê³ |
|---|
| 447 |
ì¥ê³ ê° ì€íëë ëìŒ ìíì¹ ``VirtualHost`` ììì 믞ëìŽ íìŒë€ì ì²ëЬíŽìŒ íë€ë©Ž, |
|---|
| 448 |
ì¬ìŽíž í¹ì ë¶ë¶ì mod_python ì ëë ë°©ë²ìŽ ììµëë€:: |
|---|
| 449 |
<<!! |
|---|
| 450 |
|
|---|
| 451 |
<Location "/media"> |
|---|
| 452 |
SetHandler None |
|---|
| 453 |
</Location> |
|---|
| 454 |
|
|---|
| 455 |
>>! |
|---|
| 456 |
Just change ``Location`` to the root URL of your media files. You can also use |
|---|
| 457 |
``<LocationMatch>`` to match a regular expression. |
|---|
| 458 |
<<! |
|---|
| 459 |
>>!! |
|---|
| 460 |
ë°ë¡ ``Location``ì 믞ëìŽ íìŒë€ì ë£šíž URLë¡ ë³ê²œíììì€. |
|---|
| 461 |
ì¬ë¬ë¶ì ì ê· ííììŒë¡ ë§€ì¹íêž° ìíŽ ``<LocationMatch>``륌 ì¬ì©í ìë ììµëë€. |
|---|
| 462 |
<<!! |
|---|
| 463 |
|
|---|
| 464 |
>>! |
|---|
| 465 |
This example sets up Django at the site root but explicitly disables Django for |
|---|
| 466 |
the ``media`` subdirectory and any URL that ends with ``.jpg``, ``.gif`` or |
|---|
| 467 |
``.png``:: |
|---|
| 468 |
<<! |
|---|
| 469 |
>>!! |
|---|
| 470 |
ìŽ ìë ì¬ìŽíž 룚ížì ì¥ê³ 륌 ì€ì íì§ë§ ``media`` ìëžëë í 늬ì |
|---|
| 471 |
``.jpg``, ``.gif`` ëë ``.png``ë¡ ëëë URLì ì¥ê³ 륌 ë¶ê°ë¥íê² íë |
|---|
| 472 |
ì€ì ì í©ëë€:: |
|---|
| 473 |
<<!! |
|---|
| 474 |
|
|---|
| 475 |
<Location "/"> |
|---|
| 476 |
SetHandler python-program |
|---|
| 477 |
PythonHandler django.core.handlers.modpython |
|---|
| 478 |
SetEnv DJANGO_SETTINGS_MODULE mysite.settings |
|---|
| 479 |
</Location> |
|---|
| 480 |
|
|---|
| 481 |
<Location "/media"> |
|---|
| 482 |
SetHandler None |
|---|
| 483 |
</Location> |
|---|
| 484 |
|
|---|
| 485 |
<LocationMatch "\.(jpg|gif|png)$"> |
|---|
| 486 |
SetHandler None |
|---|
| 487 |
</LocationMatch> |
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
.. _lighttpd: http://www.lighttpd.net/ |
|---|
| 491 |
.. _TUX: http://en.wikipedia.org/wiki/TUX_web_server |
|---|
| 492 |
.. _Apache: http://httpd.apache.org/ |
|---|
| 493 |
|
|---|
| 494 |
>>! |
|---|
| 495 |
Serving the admin files |
|---|
| 496 |
<<! |
|---|
| 497 |
>>!! |
|---|
| 498 |
admin íìŒë€ ì²ëЬíêž° |
|---|
| 499 |
<<!! |
|---|
| 500 |
======================= |
|---|
| 501 |
|
|---|
| 502 |
>>! |
|---|
| 503 |
Note that the Django development server automagically serves admin media files, |
|---|
| 504 |
but this is not the case when you use any other server arrangement. You're |
|---|
| 505 |
responsible for setting up Apache, or whichever media server you're using, to |
|---|
| 506 |
serve the admin files. |
|---|
| 507 |
<<! |
|---|
| 508 |
>>!! |
|---|
| 509 |
ì¥ê³ ê°ë° ìë²ë ìëìŒë¡ admin media íìŒë€ì ì²ëЬí©ëë€ë§, ë€ë¥ž ìë²êµ¬ì±ì |
|---|
| 510 |
ì¬ì©í 겜ì°ë ìŽì íŽë¹íì§ ììì 죌ì íììì€. admin íìŒë€ì ì²ëЬíêž° ìíŽ, |
|---|
| 511 |
ìíì¹, ëë ì¬ë¬ë¶ìŽ ì¬ì©ì€ìž ìŽë í 믞ëìŽ ìë²ì ëí ì€ì ì |
|---|
| 512 |
ì¬ë¬ë¶ìŽ íŽìŒ í©ëë€. |
|---|
| 513 |
<<!! |
|---|
| 514 |
|
|---|
| 515 |
>>! |
|---|
| 516 |
The admin files live in (``django/contrib/admin/media``) of the Django |
|---|
| 517 |
distribution. |
|---|
| 518 |
<<! |
|---|
| 519 |
>>!! |
|---|
| 520 |
admin íìŒì ì¥ê³ ë°°í¬íì (``django/contrib/admin/media``) ì |
|---|
| 521 |
ìì¹í©ëë€. |
|---|
| 522 |
<<!! |
|---|
| 523 |
|
|---|
| 524 |
>>! |
|---|
| 525 |
Here are two recommended approaches: |
|---|
| 526 |
<<! |
|---|
| 527 |
>>!! |
|---|
| 528 |
ì¬êž° ëê°ì§ ì¶ì² ë°©ë²ìŽ ììµëë€: |
|---|
| 529 |
<<!! |
|---|
| 530 |
|
|---|
| 531 |
>>! |
|---|
| 532 |
1. Create a symbolic link to the admin media files from within your |
|---|
| 533 |
document root. This way, all of your Django-related files -- code |
|---|
| 534 |
**and** templates -- stay in one place, and you'll still be able to |
|---|
| 535 |
``svn update`` your code to get the latest admin templates, if they |
|---|
| 536 |
change. |
|---|
| 537 |
2. Or, copy the admin media files so that they live within your Apache |
|---|
| 538 |
document root. |
|---|
| 539 |
<<! |
|---|
| 540 |
>>!! |
|---|
| 541 |
1. ì¬ë¬ë¶ì document root ëŽì admin media íìŒë€ì ëí ì¬ë³ŒëŠ ë§í¬ë¥Œ ë§ëëë€. |
|---|
| 542 |
ìŽ ê²œì°, ì¬ë¬ë¶ì 몚ë ì¥ê³ êŽë š íìŒë€ -- ìœë **ê·žëŠ¬ê³ ** í |
|---|
| 543 |
íëŠ¿ë€ -â ì |
|---|
| 544 |
í ì¥ìì ìê²ëë©°, ì¬ë¬ë¶ì ì¬ì í ë³ê²œë ìµì ì |
|---|
| 545 |
admin í |
|---|
| 546 |
í늿ë€ì ì»êž° ìíŽ, |
|---|
| 547 |
``svn update``륌 í ì ììµëë€. |
|---|
| 548 |
2. ëë, ì¬ë¬ë¶ì ìíì¹ document root ìì |
|---|
| 549 |
admin media íìŒë€ì ë³µì¬í©ëë€. |
|---|
| 550 |
<<!! |
|---|
| 551 |
|
|---|
| 552 |
>>! |
|---|
| 553 |
Using eggs with mod_python |
|---|
| 554 |
<<! |
|---|
| 555 |
>>!! |
|---|
| 556 |
mod_pythonìì eggs ì¬ì©íêž° |
|---|
| 557 |
<<!! |
|---|
| 558 |
========================== |
|---|
| 559 |
|
|---|
| 560 |
>>! |
|---|
| 561 |
If you installed Django from a Python egg_ or are using eggs in your Django |
|---|
| 562 |
project, some extra configuration is required. Create an extra file in your |
|---|
| 563 |
project (or somewhere else) that contains something like the following:: |
|---|
| 564 |
<<! |
|---|
| 565 |
>>!! |
|---|
| 566 |
ë§ìœ Python egg_ìì ì¥ê³ 륌 ì€ì¹íê±°ë ì¥ê³ íë¡ì ížì egg륌 ì¬ì© ì€ìŽëŒë©Ž, |
|---|
| 567 |
ì¶ê° ì€ì ìŽ íìí©ëë€. ì¬ë¬ë¶ì íë¡ì íž(ëë ìŽëê°ì)ì ìëì ê°ì ëŽì©ì í¬íšíë |
|---|
| 568 |
ë³ëì íìŒì ìì±íììì€:: |
|---|
| 569 |
<<!! |
|---|
| 570 |
|
|---|
| 571 |
import os |
|---|
| 572 |
os.environ['PYTHON_EGG_CACHE'] = '/some/directory' |
|---|
| 573 |
|
|---|
| 574 |
>>! |
|---|
| 575 |
Here, ``/some/directory`` is a directory that the Apache webserver process can |
|---|
| 576 |
write to. It will be used as the location for any unpacking of code the eggs |
|---|
| 577 |
need to do. |
|---|
| 578 |
<<! |
|---|
| 579 |
>>!! |
|---|
| 580 |
ì¬êž°, ``/some/directory`` ë ìíì¹ ì¹ìë² íë¡ìžì€ê° |
|---|
| 581 |
ì°êž°ë¥Œ íë ëë í 늬ì |
|---|
| 582 |
ëë€. |
|---|
| 583 |
eggê° íìë¡ íë ìœëë€ì ìì¶ì ížë ìì¹ë¡ ì¬ì©ë©ëë€. |
|---|
| 584 |
<<!! |
|---|
| 585 |
|
|---|
| 586 |
>>! |
|---|
| 587 |
Then you have to tell mod_python to import this file before doing anything |
|---|
| 588 |
else. This is done using the PythonImport_ directive to mod_python. You need |
|---|
| 589 |
to ensure that you have specified the ``PythonInterpreter`` directive to |
|---|
| 590 |
mod_python as described above__ (you need to do this even if you aren't |
|---|
| 591 |
serving multiple installations in this case). Then add the ``PythonImport`` |
|---|
| 592 |
line in the main server configuration (i.e., outside the ``Location`` or |
|---|
| 593 |
``VirtualHost`` sections). For example:: |
|---|
| 594 |
<<! |
|---|
| 595 |
>>!! |
|---|
| 596 |
ê·žëŠ¬ê³ ëì ì¬ë¬ë¶ì mod_pythonìê² ë€ë¥ž 묎ì볎ë€ë 뚌ì |
|---|
| 597 |
ìŽ íìŒì import í ê²ì ì§ìíŽìŒ í©ëë€. |
|---|
| 598 |
ìŽë mod_pythonì PythonImport_ ì§ìì륌 ì¬ì©í멎 ë©ëë€. |
|---|
| 599 |
ì¬ë¬ë¶ì mod_pythonì ì__ìì ì€ëª |
|---|
| 600 |
íëë¡ |
|---|
| 601 |
``PythonInterpreter`` ì§ìì륌 |
|---|
| 602 |
ëª |
|---|
| 603 |
ìíŽë¬ìŒ í©ëë€ |
|---|
| 604 |
(ì¬ë¬ë¶ì ìŽ ê²œì° ë€ì€ ì€ì¹ë¥Œ ì¬ì© íì§ ìëëŒë ìŽê²ì íŽìŒ í©ëë€). ê·žëŠ¬ê³ ëì ``PythonImport`` ì€ì ë©ìž ìë² ì€ì ì ì¶ê° íììì€(ìŠ, ``Location`` ëë ``VirtualHost`` ì¹ì |
|---|
| 605 |
ì ë°ê¹¥). ì륌 ë€ìŽ:: |
|---|
| 606 |
<<!! |
|---|
| 607 |
|
|---|
| 608 |
PythonInterpreter my_django |
|---|
| 609 |
PythonImport /path/to/my/project/file.py my_django |
|---|
| 610 |
|
|---|
| 611 |
>>! |
|---|
| 612 |
Note that you can use an absolute path here (or a normal dotted import path), |
|---|
| 613 |
as described in the `mod_python manual`_. We use an absolute path in the |
|---|
| 614 |
above example because if any Python path modifications are required to access |
|---|
| 615 |
your project, they will not have been done at the time the ``PythonImport`` |
|---|
| 616 |
line is processed. |
|---|
| 617 |
<<! |
|---|
| 618 |
>>!! |
|---|
| 619 |
ì¬ë¬ë¶ì `mod_python ë§€ëŽìŒ`_ìì ì€ëª |
|---|
| 620 |
í ëë¡ |
|---|
| 621 |
ì ë 겜ë¡(ëë ìŒë°ì ìž ëíž import 겜ë¡)륌 ì¬ì©í ì ììµëë€. ì°ëЬë ì¬ë¬ë¶ì |
|---|
| 622 |
íë¡ì ížì ì ê·Œ íêž° ìíŽ íìŽì¬ path ìì ìŽ íìí ìë ìëë°, |
|---|
| 623 |
``PythonImport`` ëŒìžìŽ ì²ëЬëë ìì ììë ìŽê²ìŽ ìì§ ìë£ê° ëì§ ììêž° ë묞ì |
|---|
| 624 |
ìì ìì ìì ì°ëЬë ì ë 겜ë¡ë¥Œ ì¬ì©íìµëë€. |
|---|
| 625 |
<<!! |
|---|
| 626 |
|
|---|
| 627 |
.. _Egg: http://peak.telecommunity.com/DevCenter/PythonEggs |
|---|
| 628 |
.. _PythonImport: http://www.modpython.org/live/current/doc-html/dir-other-pimp.html |
|---|
| 629 |
>>! |
|---|
| 630 |
.. _mod_python manual: PythonImport_ |
|---|
| 631 |
__ `Multiple Django installations on the same Apache`_ |
|---|
| 632 |
<<! |
|---|
| 633 |
>>!! |
|---|
| 634 |
.. _mod_python ë§€ëŽìŒ: PythonImport_ |
|---|
| 635 |
__ `í ìíì¹ ììì ì¥ê³ ë€ì€ ì€ì¹`_ |
|---|
| 636 |
<<!! |
|---|
| 637 |
|
|---|
| 638 |
>>! |
|---|
| 639 |
Error handling |
|---|
| 640 |
<<! |
|---|
| 641 |
>>!! |
|---|
| 642 |
ìë¬ ì²ëЬ |
|---|
| 643 |
<<!! |
|---|
| 644 |
============== |
|---|
| 645 |
|
|---|
| 646 |
>>! |
|---|
| 647 |
When you use Apache/mod_python, errors will be caught by Django -- in other |
|---|
| 648 |
words, they won't propagate to the Apache level and won't appear in the Apache |
|---|
| 649 |
``error_log``. |
|---|
| 650 |
<<! |
|---|
| 651 |
>>!! |
|---|
| 652 |
ì¬ë¬ë¶ìŽ ìíì¹/mod_pythonì ì¬ì©í ë, ìë¬ë ì¥ê³ ì ìíŽ ì¡íëë€ -- ë€ë¥ž ë§ë¡, |
|---|
| 653 |
ìë¬ë¥Œ ìíì¹ ë 벚ì ì í íì§ ììŒë©°, ìíì¹ ``error_log`` ìë |
|---|
| 654 |
ëíëì§ ììµëë€. |
|---|
| 655 |
<<!! |
|---|
| 656 |
|
|---|
| 657 |
>>! |
|---|
| 658 |
The exception for this is if something is really wonky in your Django setup. In |
|---|
| 659 |
that case, you'll see an "Internal Server Error" page in your browser and the |
|---|
| 660 |
full Python traceback in your Apache ``error_log`` file. The ``error_log`` |
|---|
| 661 |
traceback is spread over multiple lines. (Yes, this is ugly and rather hard to |
|---|
| 662 |
read, but it's how mod_python does things.) |
|---|
| 663 |
<<! |
|---|
| 664 |
>>!! |
|---|
| 665 |
ìŽì ëí ììžë ì¬ë¬ë¶ì ì¥ê³ íë¡ê·žëšìì 묎ìžê° ì ë§ ìì ì ìë ìŒìŽ |
|---|
| 666 |
ë°ìí 겜ì°ì |
|---|
| 667 |
ëë€. ìŽ ê²œì°, ì¬ë¬ë¶ì ëžëŒì°ì ìì "Internal Server Error" íìŽì§ë¥Œ |
|---|
| 668 |
ë³Žê² ë ê²ìŽë©° full Python traceback ìŽ ìíì¹ ``error_log`` íìŒì ëšê²šì§ëë€. |
|---|
| 669 |
``error_log`` tracebackì ì¬ë¬ì€ì ê±žì³ ì¶ë ¥ë©ëë€. (ì, ìŽê²ì |
|---|
| 670 |
볎Ʞ ííê³ ìœêž°ë ìŽë µìµëë€ë§, ìŽê² mod_python ìŽ ì²ëЬíë ë°©ìì |
|---|
| 671 |
ëë€.) |
|---|
| 672 |
<<!! |
|---|
| 673 |
|
|---|
| 674 |
>>! |
|---|
| 675 |
If you get a segmentation fault |
|---|
| 676 |
<<! |
|---|
| 677 |
>>!! |
|---|
| 678 |
segment fault ê° ë¬ë€ë©Ž |
|---|
| 679 |
<<!! |
|---|
| 680 |
=============================== |
|---|
| 681 |
|
|---|
| 682 |
>>! |
|---|
| 683 |
If Apache causes a segmentation fault, there are two probable causes, neither |
|---|
| 684 |
of which has to do with Django itself. |
|---|
| 685 |
<<! |
|---|
| 686 |
>>!! |
|---|
| 687 |
ë§ìœ ìíì¹ê° segment fault 륌 ëžë€ë©Ž, ëê°ì§ ìì ììžìŽ ìëë°, |
|---|
| 688 |
ëë€ ì¥ê³ ì첎ì 묞ì ê° ìëëë€. |
|---|
| 689 |
<<!! |
|---|
| 690 |
|
|---|
| 691 |
>>! |
|---|
| 692 |
1. It may be because your Python code is importing the "pyexpat" module, |
|---|
| 693 |
which may conflict with the version embedded in Apache. For full |
|---|
| 694 |
information, see `Expat Causing Apache Crash`_. |
|---|
| 695 |
2. It may be because you're running mod_python and mod_php in the same |
|---|
| 696 |
Apache instance, with MySQL as your database backend. In some cases, |
|---|
| 697 |
this causes a known mod_python issue due to version conflicts in PHP and |
|---|
| 698 |
the Python MySQL backend. There's full information in the |
|---|
| 699 |
`mod_python FAQ entry`_. |
|---|
| 700 |
<<! |
|---|
| 701 |
>>!! |
|---|
| 702 |
1. ì¬ë¬ë¶ì íìŽì¬ ìœëê° ìíì¹ì ìë² ë©ë ë²ì 곌 |
|---|
| 703 |
ì¶©ëëë "pyexpat" 몚ëì ìí¬í |
|---|
| 704 |
íê³ ìêž° ëë¬žìŒ ì ììµëë€. |
|---|
| 705 |
ì 첎 ì 볎ë `Expat Causing Apache Crash`_ 륌 볎ììì€. |
|---|
| 706 |
2. ì¬ë¬ë¶ìŽ ë°ìŽí°ë² ìŽì€ íëšë¶ë¡ MySQLì ì¬ì©íì¬ mod_python곌 mod_php륌 |
|---|
| 707 |
ëìŒ ìíì¹ ìžì€íŽì€ìì ì€íì€ìŽêž° ëë¬žìŒ ì ììµëë€. ìŽë€ 겜ì°, |
|---|
| 708 |
ìŽë PHPì Pythonì MySQL íëšë¶ììì ë²ì ì¶©ëì ìí ê²ìŒë¡ ìë €ì§ |
|---|
| 709 |
mod_python ìŽì륌 ìŒìŒíµëë€. |
|---|
| 710 |
`mod_python FAQ entry`_ì ì 첎 ì ë³Žê° ììµëë€. |
|---|
| 711 |
<<!! |
|---|
| 712 |
|
|---|
| 713 |
>>! |
|---|
| 714 |
If you continue to have problems setting up mod_python, a good thing to do is |
|---|
| 715 |
get a barebones mod_python site working, without the Django framework. This is |
|---|
| 716 |
an easy way to isolate mod_python-specific problems. `Getting mod_python Working`_ |
|---|
| 717 |
details this procedure. |
|---|
| 718 |
<<! |
|---|
| 719 |
>>!! |
|---|
| 720 |
ë§ìœ ì¬ë¬ë¶ìê² mod_python ì€ì 묞ì ê° ê³ìëë€ë©Ž, |
|---|
| 721 |
ì¥ê³ íë ììí¬ ììŽ, mod_python Ʞ볞 ì¬ìŽížê° ì ìëíëë¡ íììì€. |
|---|
| 722 |
ìŽë mod_python ì íì ë 묞ì 륌 ê³ ëŠœìí€ë ì¬ìŽ ë°©ë²ì |
|---|
| 723 |
ëë€. |
|---|
| 724 |
`Getting mod_python Working`_ì ìŽ ì ì°šê° ììžíê² ììµëë€. |
|---|
| 725 |
<<!! |
|---|
| 726 |
|
|---|
| 727 |
>>! |
|---|
| 728 |
The next step should be to edit your test code and add an import of any |
|---|
| 729 |
Django-specific code you're using -- your views, your models, your URLconf, |
|---|
| 730 |
your RSS configuration, etc. Put these imports in your test handler function |
|---|
| 731 |
and access your test URL in a browser. If this causes a crash, you've confirmed |
|---|
| 732 |
it's the importing of Django code that causes the problem. Gradually reduce the |
|---|
| 733 |
set of imports until it stops crashing, so as to find the specific module that |
|---|
| 734 |
causes the problem. Drop down further into modules and look into their imports, |
|---|
| 735 |
as necessary. |
|---|
| 736 |
<<! |
|---|
| 737 |
>>!! |
|---|
| 738 |
ë€ì ëšê³ë í |
|---|
| 739 |
ì€íž ìœë륌 ìŽìŽì ì¬ë¬ë¶ìŽ ì¬ì©íë ì¥ê³ êŽë š ìœë â |
|---|
| 740 |
view, model, URLconf, RSS ì€ì ë°ì ë±ì ëí 몚ë import ë€ì ì¶ê° íììì€. |
|---|
| 741 |
ìŽë€ importë€ì ì¬ë¬ë¶ì í |
|---|
| 742 |
ì€íž ížë€ë¬ íšìì ë£ê³ ëžëŒì°ì ìì |
|---|
| 743 |
ì¬ë¬ë¶ì í |
|---|
| 744 |
ì€íž URLì ì ìíììì€. ë§ìœ ìŽê²ìŽ ë¬žì 륌 ë°ììíšë€ë©Ž, |
|---|
| 745 |
import í ì¥ê³ ìœëë€ìŽ ë¬žì 륌 ìŒìŒí€ë ê²ììŽ íìžë ê²ì |
|---|
| 746 |
ëë€. í¬ëìê° |
|---|
| 747 |
ë©ì¶ëê¹ì§ import 륌 ì ì°šì ìŒë¡ ì€ì¬ëê°ì, 묞ì 륌 ë§ììí€ë |
|---|
| 748 |
í¹ì 몚ëì ì°Ÿìµëë€. íìíë€ë©Ž íŽë¹ 몚ë ììŒë¡ ë ë€ìŽê° |
|---|
| 749 |
ê·ž ê³³ì import ë€ì ì¡°ì¬í©ëë€. |
|---|
| 750 |
<<!! |
|---|
| 751 |
|
|---|
| 752 |
.. _Expat Causing Apache Crash: http://www.dscpl.com.au/articles/modpython-006.html |
|---|
| 753 |
.. _mod_python FAQ entry: http://modpython.org/FAQ/faqw.py?req=show&file=faq02.013.htp |
|---|
| 754 |
.. _Getting mod_python Working: http://www.dscpl.com.au/articles/modpython-001.html |
|---|