Home Backend Development Python Tutorial Django configuration to allow other computers to access the website

Django configuration to allow other computers to access the website

Oct 17, 2016 pm 02:36 PM

In fact, Django comes with a built-in lightweight web server that can be used during site development. We provide this server to allow you to quickly develop your site, which means there is no need to configure a production-level web server (such as Apache) before you are ready to release the product.

But in actual development, instead of one person developing, multiple people need to be able to access this machine. So how do we configure it? Let’s take a look:

1. Create a web project

Run the

django-admin.py startproject pytab
Copy after login

command to create a pytab directory in the current directory.

Note:

If you have a PHP programming background, you may be accustomed to placing your code in the document root directory of the Web server (such as /var/www). In Django, you can't do this. It's not a good idea to put any Python code in the document root of your web server because you run the risk of someone seeing the code directly through the page. This is not a good thing for security. So, place the code in some directory outside of the document root.

2. Run the built-in server

and let it run so that we can access

If you are not already in the mysite directory, go into it now and run the python manage.py runserver command. You will see the following output:

Validating models...

0 errors found

Django version 1.4.3, using settings 'mysite.settings'

Development server is running at http://127.0.0.1:8000 /

Quit the server with CONTROL-C.


After the above prompt appears, it will be in a waiting state. When an access comes in, some user access information will appear. For example:

[11/Jan/2013 00:47:58] "GET / HTTP/1.1" 200 1957

200 Description The request is successful, 1957 represents the size of the sent data, the unit is B.


Although this development server is great for development, be sure to avoid the idea of ​​using this server in a production-level environment. The server could only reliably handle a single request once at a time and was not subject to any kind of security auditing.

But in actual development, instead of one person developing, multiple people need to be able to access this machine. Django thinks of this problem for us. You can use the runserver command to solve this problem:

1. Change the listening port.

If you want to change the server port, you can pass the port as a command line parameter:

python manage.py runserver 8070

2. You can also change the IP address that the server monitors. This feature is especially useful if you want to share the same development site with other developers. The following command:

python manage.py runserver 0.0.0.0:8000

will cause Django to listen on all network interfaces and IP addresses, thus allowing other computers to connect to the development server.

Now that the server is running, you can now access http://192.168.1.111:8000/ using a web browser on other computers.


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? Apr 01, 2025 pm 11:15 PM

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics in project and problem-driven methods within 10 hours? How to teach computer novice programming basics in project and problem-driven methods within 10 hours? Apr 02, 2025 am 07:18 AM

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? Apr 02, 2025 am 07:15 AM

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

How does Uvicorn continuously listen for HTTP requests without serving_forever()? How does Uvicorn continuously listen for HTTP requests without serving_forever()? Apr 01, 2025 pm 10:51 PM

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

What are some popular Python libraries and their uses? What are some popular Python libraries and their uses? Mar 21, 2025 pm 06:46 PM

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H

How to dynamically create an object through a string and call its methods in Python? How to dynamically create an object through a string and call its methods in Python? Apr 01, 2025 pm 11:18 PM

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...

How to solve permission issues when using python --version command in Linux terminal? How to solve permission issues when using python --version command in Linux terminal? Apr 02, 2025 am 06:36 AM

Using python in Linux terminal...

See all articles