Access Django app from other computers

佐手、 提交于 2019-12-07 13:10:24

问题


I am developing a web application on my local computer in Django.

Now I want my webapp to be accessible to other computers on my network. We have a common network drive "F:/". Should I place my files on this drive or can I just write something like "python manage.py runserver test_my_app:8000" in the command prompt to let other computers in the network access the web server by writing "test_my_app:8000" in the browser address field? Do I have to open any ports and how can I do this?


回答1:


It is should be done with central system or server.

By default manage.py runserver will not give ip bind permission. So

Note that the default IP address, 127.0.0.1, is not accessible from other machines on your network. To make your development server viewable to other machines on the network, use its own IP address (e.g. 192.168.2.1) or 0.0.0.0 or :: (with IPv6 enabled).

If you want to check in your local machine then follow

python manage.py runserver 0.0.0.0:8000

Now go to your network computer and access your ip like 192.168.1.24:8000

Updated:

For Django version about 1.10 you should add your host to ALLOWED_HOSTS here




回答2:


Run the application with IP address then access it in other machines.

python manage.py runserver 192.168.56.22:1234

Both machines should be in same network, then only this will work.




回答3:


Just add your own IP Address to ALLOWED_HOSTS

ALLOWED_HOSTS = ['192.168.1.50', '127.0.0.1', 'localhost']

and run your server python manage.py runserver 192.168.1.50:8000

and access your own server to other computer in your network



来源:https://stackoverflow.com/questions/25550116/access-django-app-from-other-computers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!