如何在我的电脑中托管django网站并在另一台电脑中查看它? [英] How to host a django website in my pc and view it in another pc?
问题描述
我的PC中有一个django项目。
I have a django project in my pc.
在终端中,我运行了 python3 manage.py runserver< my ipaddress> ;: 8001
当我尝试在另一台PC中打开链接时,它显示错误页面,内容为:
When I try to open the link in another pc, it is showing error page which says:
Invalid HTTP_HOST header: '<my ipaddress>:8001'. You may need to add '<my ipaddress>' to ALLOWED_HOSTS.
我该怎么办?
此外,是否可以在网址中放置一些文本代替ipaddress?
例如,我想将其托管为 myproject /
而不是该复杂的URL。
And moreover is it possible to put some text in place of ipaddress in the url?
For example, I want to host it as myproject/
instead of that complex url.
推荐答案
在一种情况下,这将起作用
On one condition this will work
如果两台计算机都位于本地热点或相同热点的同一网络上
LAN网络
if both computers are on the same network like local Hotspot or same LAN network
步骤:
- 在允许的主机中的django项目的设置文件中添加 *,它看起来像是
ALLOWED_HOSTS = ['*']
ALLOWED_HOSTS = ['*']
- 在此ip上运行服务器
0.0.0.0
并使用此命令移植任何8000
- run your server on this ip
0.0.0.0
and port any like8000
using this command
manage.py运行服务器0.0.0.0:8000
manage.py runserver 0.0.0.0:8000
-
如果使用的是Linux,则运行
ifconfig
(如果使用的是Windows)ipconfig
将获得您服务器的IP地址
run
ifconfig
if you are using linuxipconfig
if windows then you will get your ip address of your server
在anothe中打开浏览器r计算机并输入第3步中显示的服务器ip,端口为 8000
Open browser in another computer and enter the ip of server shown in 3rd step with port as 8000
这篇关于如何在我的电脑中托管django网站并在另一台电脑中查看它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!