Use the same Apache instance to run Django and Media files

Source: Internet
Author: User
This article describes how to use the same Apache instance to run Django and Media files. Django is the most popular Pythonweb development framework, if you need media files, you can refer to Django which does not need to serve media files. leave this work to the network server you choose. We recommend that you use a separate network server (that is, one that does not run Django) to serve media. For more information, see the following section.

However, if you have no other options, you can only serve media files on Apache VirtualHost like Django. here you can disable mod_python for specific parts of this site:

 
  
    SetHandler None
 
 

将 Location 改成你的media文件所处的根目录。

你也可以使用 来匹配正则表达式。 比如,下面的写法将Django定义到网站的根目录,并且显式地将 media 子目录以及任何以 .jpg , .gif , 或者 .png 结尾的URL屏蔽掉:

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

 

 
  
    SetHandler None
 
 
 
 
  
    SetHandler None
 
 

在所有这些例子中,你必须设置 DocumentRoot ,这样apache才能知道你存放静态文件的位

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.