简体   繁体   English

如何在本地托管 Django 项目?

[英]How to locally host a Django project?

I am trying to run a Django website, and I want the ability for all devices that are connected to the same router as my computer to be able to access the website.我正在尝试运行 Django 网站,并且我希望与我的计算机连接到同一路由器的所有设备都能够访问该网站。 I have looked in several places, and questions like this , or this .我看过几个地方,以及这样的问题,或者这个

In summary, the first links says that I should run my server with python manage.py runserver 0.0.0.0:8000 , and that will allow to access it from my cellphone.总之,第一个链接说我应该使用python manage.py runserver 0.0.0.0:8000运行我的服务器,这将允许从我的手机访问它。 The second link said the same thing, but instead of 0.0.0.0 , it said that I should use my own IP address while running the runserver command.第二个链接说同样的事情,但不是0.0.0.0 ,而是说我应该在运行runserver命令时使用我自己的 IP 地址。 Neither approaches worked.两种方法都不起作用。 I can access the website from my computer, but not from my cellphone, for example.例如,我可以从我的计算机访问该网站,但不能从我的手机访问。 (Both connected to 'X' network) (都连接到“X”网络)

I really don't know what to do since I can't find another answer, possibly because I am not searching for the question correctly, but I would love it if anyone could help me.我真的不知道该怎么做,因为我找不到另一个答案,可能是因为我没有正确搜索这个问题,但如果有人能帮助我,我会很高兴。

I tried sharing internet from my cellphone and using its IP address, and that worked.我尝试从我的手机共享互联网并使用它的 IP 地址,并且成功了。 I think this points out that it is maybe a problem with my router or internet provider.我认为这表明这可能是我的路由器或互联网提供商的问题。 I don't know.我不知道。

if you run the web on your computer you can do this python manage.py runserver 0.0.0.0:Computer-IP or localhost:Computer-IP, you can run the command ifconfig, find, eno and then you find inet 192.168.100.xx copy this如果您在计算机上运行 web,您可以执行此操作 python manage.py runserver 0.0.0.0:Computer-IP 或 localhost:Computer-IP,您可以运行命令 ifconfig,find,eno,然后找到 inet 192.168.100。 xx复制这个

don't forget to enter your application folder settings.py ALLOWED_HOSTS = [] change like this ALLOWED_HOSTS = ["*"]不要忘记输入您的应用程序文件夹 settings.py ALLOWED_HOSTS = [] 像这样更改 ALLOWED_HOSTS = ["*"]

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

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