Use mod_python to configure the Django framework running on Apache

Source: Internet
Author: User
This article mainly introduces the Django framework running on Apache through mod_python configuration. Django is the most popular Pythonweb development framework. For more information about how to configure Django based on mod_python, install Apache with the available mod_python module. This usually means that there should be a LoadModule command 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 Directive that ties a specific URL path to a specific Django installation. example:

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

Make sure that the mysite. settings project in DJANGO_SETTINGS_MODULE is replaced with the content corresponding to your site.

It tells Apache that any URL after the path/is processed using Django's mod_python. It passes the value of DJANGO_SETTINGS_MODULE to know which configuration should be used at this time.

Note that "'command instead of"' is used here "'. The latter is used to point to a location in your file system, however "'

System Message: WARNING/2 (
 
  , line 403); backlinkInline literal start-string without end-string.System Message: WARNING/2 (
  
   , line 403); backlinkInline literal start-string without end-string.System Message: WARNING/2 (
   
    , line 403); backlinkInline literal start-string without end-string.System Message: WARNING/2 (
    
     , line 403); backlinkInline literal start-string without end-string.System Message: ERROR/3 (
     
      , line 405)Unexpected indentation.
     
    
   
  
 

Point to the URL of 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 normal login environment, but also in different user environments. it may also have different file paths or sys. path. You need to tell mod_python how to find your project and Django location.

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

You can also add other commands, such as PythonAutoReload Off, to improve performance. View the mod_python document to obtain a detailed command list.

Note that you should set PythonDebug Off on the finished server. If you use PythonDebug On, your users will see ugly (and exposed) Python tracing information when an error occurs in the program. If you set PythonDebug to On, when mod_python has some errors, your users will see ugly (and some information will be exposed) Python's error tracking information.

After Apache is restarted, all requests to your site (or when you use After the command, it is a virtual host) will be handled by Djanog.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.