Django installation and start, Django installation and start
1. Install django
Download the latest website of djangoon http://www.djangoproject.com/download. When downloading, make sure that the django version matches the Python version installed on the local machine. In this example.
After the download, decompress the package and install it. The specific installation command is as follows:
Tar xzvf Django-1.9.1.tar.gz
Cd Django-1.9.1
Sudo python setup. py install
2. Test django Installation
After installing django, first test whether django is successfully installed. Open the Python notebook and enter the following command:
>>> import django >>> django.VERSION (1, 9, 1, 'final', 0)
You can get the installed django version to prove that django has been installed successfully.
3. Start a project
Create a directory, and then create a django project under the directory. The command is as follows:
Mkdir djangocode
Cd djangocode/
Django-admin.py startproject mysite
In this way, a mysite directory is created under the current directory. The directory structure is as follows:
Mysite/
Manage. py
Mysite/
_ Init _. py
Settings. py
Urls. py
Wsgi. py
Manage. py: a command line tool that allows you to interact with this django project in multiple ways.
_ Init _. py: Let Python treat this directory as a file required by the Development Kit.
Settings. py: configuration file of this django project.
Urls. py: the URL setting file of the django project.
Wsgi. py: wsgi is a simple and common interface between a web server defined in the Python language and a web service program or framework.
4. Run the django Service
Run the following command to start the django service:
Python manage. py runserver
By default, a local server is started on port 8000. Visit http: // 127.0.0.1: 8000/in the browser on the local machine. A django welcome page is displayed, indicating that the server is successfully started.
If you want other computers to access this page, run the following command:
Python manage. py runserver 0.0.0.0: 8000
The IP address 0.0.0.0 tells the server to listen for any network interface. In this way, other computers in the local network can access the page through the Server IP address in the browser.