简体   繁体   English

本地托管 Django 项目

[英]Locally hosting Django project

So I'm trying to locally host a Django project that I am working on.所以我试图在本地托管一个我正在处理的 Django 项目。

I'm looking to have the ability to have all computers who are connected to the local network be able to access this django app/webapp.我希望能够让所有连接到本地网络的计算机都能够访问这个 django 应用程序/webapp。 Sort of like a central, internal, local only website/hub.有点像一个中央的、内部的、仅限本地的网站/中心。 And I was wondering how I could go about setting up my project to be able to do this.我想知道如何设置我的项目才能做到这一点。

Would I need to setup a webserver to accomplish this functionality?我需要设置一个网络服务器来完成这个功能吗? If so would you be able to recommend any?如果是这样你能推荐任何吗? Can I do this within Django itself using the dev server?我可以使用开发服务器在 Django 内部执行此操作吗? Any help would be greatly appreciated.任何帮助将不胜感激。

Thank you for your time.感谢您的时间。

I'll try answering to this to the best of my knowledge.我会尽我所知尝试回答这个问题。 I have two Django apps(separate projects) which is accessible only through LAN or like as you said central,internal,local only website/hub.我有两个 Django 应用程序(单独的项目),它们只能通过 LAN 或像你说的中央、内部、本地网站/集线器一样访问。 My company uses it for different applications.我的公司将它用于不同的应用程序。 You don't need any webserver because the Django does it all.您不需要任何网络服务器,因为 Django 已完成这一切。 About setting up your project you can use your PC as local server but if you think traffic is gonna be much then you need a fairly powerful machine (I mean to say dedicated separate PC with better specs) which can handle all the traffic (We actually use same PC for running both the Django apps so its possible).关于设置您的项目,您可以将您的 PC 用作本地服务器,但是如果您认为流量会很大,那么您需要一台功能相当强大的机器(我的意思是说具有更好规格的专用独立 PC)可以处理所有流量(我们实际上使用同一台 PC 来运行这两个 Django 应用程序,因此它是可能的)。 For installation guide visit here and for more clear information visit here and here .有关安装指南,请访问此处,有关更清晰的信息,请访问此处此处

You can run server by python manage.py runserver which runs only on your machine which you can use while developing the app (none can access it though you will be connected to internet or LAN)你可以通过python manage.py runserver运行服务器,它只在你的机器上运行,你可以在开发应用程序时使用它(尽管你将连接到互联网或局域网,但没有人可以访问它)

You can also run server by python manage.py runserver your ip address:port number .您还可以通过python manage.py runserver your ip address:port number运行服务器。 eg.例如。 python manage.py runserver 192.168.12.1:8000

Now when you have two projects running in same machine (as in my case) you need to keep the ip same but just change the port number.现在,当您在同一台机器上运行两个项目时(如我的情况),您需要保持 ip 不变,但只需更改端口号。 Example is as shown below.示例如下所示。

for first Django server对于第一个 Django 服务器

python manage.py runserver 192.168.12.1:8000

for second Django server用于第二个 Django 服务器

python manage.py runserver 192.168.12.1:1234

Of course it can be done.当然可以做到。 When you run the django project, pass on the server ip address and port (if you are not using the default port).运行django项目时,传入服务器ip地址和端口(如果你没有使用默认端口)。

python manage.py runserver x.x.x.x:8080

Where xxxx is the ip and 8080 is the port.其中xxxx是 ip, 8080是端口。

Now all you need is to enter xxxx:8080 in browser on the network connected device.现在您只需要在联网设备的浏览器中输入xxxx:8080即可。

For more details read this document有关更多详细信息,请阅读此文档

from the django official documentation. 来自django官方文档。

https://docs.djangoproject.com/en/1.11/ref/django-admin/ https://docs.djangoproject.com/en/1.11/ref/django-admin/

"DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that's how it's gonna stay. We're in the business of making Web frameworks, not Web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)" “不要在生产设置中使用这个服务器。它没有经过安全审核或性能测试。(这就是它将如何保留。我们的业务是制作Web框架,而不是Web服务器,因此将此服务器改进为能够处理生产环境超出了Django的范围。)“

I have tried hosting on django development server, later noticed that the server goes down frequently. 我曾尝试在django开发服务器上托管,后来发现服务器经常出现故障。 Its better to use servers like apache for production. 最好使用像apache这样的服务器进行生产。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM