Home Backend Development Python Tutorial 将Django框架和遗留的Web应用集成的方法

将Django框架和遗留的Web应用集成的方法

Jun 06, 2016 am 11:13 AM
django

同由其他技术驱动的应用一样,在相同的Web服务器上运行Django应用也是可行的。 最简单直接的办法就是利用Apaches配置文件httpd.conf,将不同的URL类型分发至不同的技术。

关键在于只有在您的httpd.conf文件中进行了相关定义,Django对某个特定的URL类型的驱动才会被激活。

<Location "/">
  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE mysite.settings
  PythonDebug On
</Location>

Copy after login

这里, 这一行表示用Django处理每个以根开头的URL.

精妙之处在于Django将指令值限定于一个特定的目录树上。 举个例子,比如说您有一个在某个域中驱动大多数页面的遗留PHP应用,并且您希望不中断PHP代码的运行而在../admin/位置安装一个Django域。 要做到这一点,您只需将值设置为/admin/即可。

<Location "/admin/">
  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE mysite.settings
  PythonDebug On
</Location>

Copy after login

有了这样的设置,只有那些以/admin/开头的URL地址才会触发Django去进行处理。 其他页面会使用已存在的设置。

请注意,把Diango绑定到的合格的URL(比如在本章例子中的 /admin/ )并不会影响其对URL的解析。 绝对路径对Django才是有效的(例如 /admin/people/person/add/ ),而非截断后的URL(例如 /people/person/add/ )。这意味着你的根URLconf必须包含前缀 /admin/ 。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to check django version How to check django version Dec 01, 2023 pm 02:25 PM

How to check django version

Django vs. Flask: A comparative analysis of Python web frameworks Django vs. Flask: A comparative analysis of Python web frameworks Jan 19, 2024 am 08:36 AM

Django vs. Flask: A comparative analysis of Python web frameworks

How to check django version How to check django version Nov 30, 2023 pm 03:08 PM

How to check django version

Django Framework Pros and Cons: Everything You Need to Know Django Framework Pros and Cons: Everything You Need to Know Jan 19, 2024 am 09:09 AM

Django Framework Pros and Cons: Everything You Need to Know

How to upgrade Django version: steps and considerations How to upgrade Django version: steps and considerations Jan 19, 2024 am 10:16 AM

How to upgrade Django version: steps and considerations

What is the difference between django versions? What is the difference between django versions? Nov 20, 2023 pm 04:33 PM

What is the difference between django versions?

Is django front-end or back-end? Is django front-end or back-end? Nov 21, 2023 pm 02:36 PM

Is django front-end or back-end?

Is Django front-end or back-end? check it out! Is Django front-end or back-end? check it out! Jan 19, 2024 am 08:37 AM

Is Django front-end or back-end? check it out!

See all articles