在多个端口上运行Django [英] Run Django on multiple ports

查看:316
本文介绍了在多个端口上运行Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何在两个端口上同时运行Django吗?默认的Django配置仅在端口8000上侦听。我也想在端口xxxx上运行另一个实例。我想将所有请求重定向到第二个端口,并将其重定向到Django应用程序中的特定应用程序。

Could someone tell me how I can run Django on two ports simultaneously? The default Django configuration only listens on port 8000. I'd like to run another instance on port xxxx as well. I'd like to redirect all requests to this second port to a particular app in my Django application.

我需要使用默认的Django安装来完成此操作,而不是使用nginx,Apache等网络服务器。

I need to accomplish this with the default Django installation and not by using a webserver like nginx, Apache, etc.

谢谢

假设我在Django应用程序中有两个应用程序。现在,我的意思不是两个单独的Django应用程序,而是 app目录中的单独文件夹。我们称这个 app1 app2

Let's say I two applications in my Django application. Now i don't mean two separate Django applications but the separate folders inside the 'app' directory. Let's call this app1 and app2

我想要全部端口8000上的请求转到 app1 ,端口XXXX上的所有请求转到 app2

I want all requests on port 8000 to go to app1 and all requests on port XXXX to go to app2

HTH。

推荐答案

只需运行两个实例。 .py runserver 。您可以通过直接指定端口来设置端口: ./ manage.py runserver 8002 来监听端口8002。

Just run two instances of ./manage.py runserver. You can set a port by simply specifying it directly: ./manage.py runserver 8002 to listen on port 8002.

编辑,我不太了解为什么要这么做。如果要让两个服务器为站点的不同部分提供服务,则实际上有两个站点,这将需要两个单独的 settings.py url。 py 文件。然后,您将分别运行一个 runserver 实例,并适当地传递设置标志: ./ manage.py runserver 8002 --settings = app1。设置

Edit I don't really understand why you want to do this. If you want two servers serving different parts of your site, then you have in effect two sites, which will need two separate settings.py and urls.py files. You'd then run one instance of runserver with each, passing the settings flag appropriately: ./manage.py runserver 8002 --settings=app1.settings

这篇关于在多个端口上运行Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆