如何在我的电脑中托管django网站并在另一台电脑中查看它? [英] How to host a django website in my pc and view it in another pc?

查看:113
本文介绍了如何在我的电脑中托管django网站并在另一台电脑中查看它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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

步骤:


  1. 在允许的主机中的django项目的设置文件中添加 *,它看起来像是




ALLOWED_HOSTS = ['*']

ALLOWED_HOSTS = ['*']




  1. 在此ip上运行服务器 0.0.0.0 并使用此命令移植任何 8000

  1. run your server on this ip 0.0.0.0 and port any like 8000 using this command




manage.py运行服务器0.0.0.0:8000

manage.py runserver 0.0.0.0:8000




  1. 如果使用的是Linux,则运行 ifconfig (如果使用的是Windows) ipconfig 将获得您服务器的IP地址

  1. run ifconfig if you are using linux ipconfig 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




http:// ip-of-server:8000

这篇关于如何在我的电脑中托管django网站并在另一台电脑中查看它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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