1024programmer Java Configuring the Django framework running on Apache through mods

Configuring the Django framework running on Apache through mods

In order to configure Django based on mod_python, you first need to install Apache with the mod_python module available. This usually means there should be a LoadModule directive in the Apache configuration file. It looks like this:

 LoadModule python_module /usr/lib/apache2/modules/mod_python.so

 

Then, edit your Apache configuration file and add a directive that ties a specific URL path to a specific Django installation. For example:

 
   SetHandler python-program
   PythonHandler django.core.handlers.modpython
   SetEnv DJANGO_SETTINGS_MODULE mysite.settings
   PythonDebug Off
 

 

Be sure to replace the mysite.settings item in DJANGO_SETTINGS_MODULE with the appropriate content for your site.

It tells Apache that any URLs that follow the / path should be handled using Django’s mod_python. It passes the value of DJANGO_SETTINGS_MODULE so that mod_python knows which configuration should be used at this time.

Note the use of the “` directive instead of “` . The latter is used to point to a location in your file system, whereas “`

 System Message: WARNING/2 (, line 403); backlink

 Inline literal start-string without end-string.

 System Message: WARNING/2 (, line 403); backlink

 Inline literal start-string without end-string.

 System Message: WARNING/2 (, line 403); backlink

 Inline literal start-string without end-string.

 System Message: WARNING/2 (, line 403); backlink

 Inline literal start-string without end-string.

 System Message: ERROR/3 (, line 405)

 Unexpected indentation.

 

URL location that points to a Web site. “`

   System Message: WARNING/2 (, line 405); backlink

   Inline literal start-string without end-string.

   System Message: WARNING/2 (, line 405); backlink

   Inline literal start-string without end-string.

 

Apache may not only run in the environment where you log in normally, but also in other different user environments; there may also be different file paths or sys.path. You need to tell mod_python how to find your project and the location of Django.

 PythonPath "['/path/to/project', '/path/to/django'] + sys.path"

 

You can also add some other instructions, such as PythonAutoReload Off, to improve performance. See the mod_python documentation for a detailed list of instructions.

Note that you should set PythonDebug Off on production servers. If you use PythonDebug On, your users will see ugly (and revealing) Python tracebacks when an error occurs. If you turn PythonDebug On, when something goes wrong with mod_python, your users will see ugly (and revealing) Python error tracking information.

After restarting Apache, all requests to your site (or virtual host when you use the directive) will be handled by Djanog.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/787623

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索