Use mod to configure the Django framework running on Apache

Source: Internet
Author: User
In order to configure Mod_python-based Django, first install the Apache with the available Mod_python module. This usually means that 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 this 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 project in Django_settings_module with the content that corresponds to your site.

It tells Apache that any URLs after the/this path are handled using Django's mod_python. It passes the value of django_settings_module, so that Mod_python knows which configuration to use at this point.

Note that the "" command is used instead of "". 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.
     
      
    
     
   
    
  
   
 
  

A URL location that points to a Web site. ````

  System MESSAGE:WARNING/2 (
 
  
   
  , line 405), backlink  Inline literal start-string without end-string.< C25/>system MESSAGE:WARNING/2 (
  
   
    
   , line 405); backlink  Inline literal start-string without end-string.
  
   
 
  

Apache may not only run in an environment where you are normally logged in, but will also run in a different user environment, or there may 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. View the Mod_python documentation for a detailed list of instructions.

Note that you should set Pythondebug OFF on the production server. If you use Pythondebug on, your users will see ugly (and exposed) Python backtracking information when the program generates an error. If you put the pythondebug on, when there are some errors in Mod_python, your users will see the ugly (and also revealing) Python's error tracking information.

All requests to your site (or the virtual host after you use the command) will be processed by Djanog after restarting Apache.

  • Related Article

    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.