1. Official website: http://www.djangoproject.com
2. If PIP is installed, enter the command in cmd: Pip install django==1.8.3
3. If Git is installed, enter it in cmd: Git clone https://github.com/django/django.git
4. Or you can download Django in the official website http://www.djangoproject.com,
Go to the downloaded folder and install it via the Python setup.py install command.
5.说明:(原网址来至于:http://www.th7.cn/Program/Python/201305/136301.shtml)
1, install under the command line:
Under Windows, Django can be placed in the same directory as Python, under DOS to enter the django-* directory, execute the python setup.py install, it takes about 1 minutes to complete the installation, Django will be installed in the Python installation directory "site-package" directory (c:/python27/lib/site-packages or/usr/lib/python2.7/site-packages), Of course, some dependent files are appended to the Python-related library, which is automatically installed.
2. Configure Environment variables
To configure environment variables or manually, add these directories to the system environment variable: c:/python27; C:/python27/lib/site-packages/django; C:/python27/scripts. Once added, you can use the Django django-admin.py command to create a new project.
3. Check whether the installation is successful
Some of the above errors may be that Python versions are incompatible with the Django version or are incompatible with computer support (such as 64-bit or 32-bit). You can then check if Django is installed successfully, enter the django-* directory under DOS, and look at the Django version:
Success shows that the Django version is 1.4.5, indicating that the Django installation was successful.
4. Creation of the first Django project
The Django environment is configured, you can create the first Django application at the command prompt, enter a directory, execute django-admin.py startproject myproject to create a project:
At this point in the MyProject directory there is a folder MyProject and a manage.py file, the MyProject directory has 4 files (4 important files):
__init__.py: Indicates that the directory is a python package
setting.py: Project Settings file
Urls.py:URL Mapping Management
manage.py: Commands for working with items
Wsgi.py:Python Web server Gateway Interface is an interface between a Python application or a framework and a Web server.
5. Start the Web server
After entering the MyProject directory, execute: manage.py runserver, to start the Django self-brought web server, (because the error cannot be reproduced, so used to create the MyTest project error) if lucky, The following 10013 error may not occur:
There is no need to panic, this is 8000 port is occupied by other applications, under DOS execute Netstat-ano to see the application port usage:
Then open the Task Manager to view the service inside to see what the PID 6328 service corresponds to what process, my 8000 port is the cool dog music occupied, so close after I re-executed after the manage.py runserver on it, then open a browser in the Address bar to enter: http ://127.0.0.1:8000, if the following interface appears, the Web service starts successfully:
The HTTP status is also returned under DOS when the page is refreshed: (I refreshed it 2 times)
Port 8000 is the default port number for the Djangoweb service, and you can also specify the port number yourself when you start the service: manage.py runserver 0.0.0.0:8888 (You can also write the port number directly, without adding IP)
haha ~ ~ At this time in the browser's address bar input: http://127.0.0.1:8888 also appears the default page:
At this point, you are ready to browse the site you created.
6. Create your own page (view and URL configuration)
Before, I was configured so that the default "It worked!" was displayed Web page, and now I want to write a webpage myself and then show it.
In the previously created MyProject directory (second MyProject), create a new views.py file with the following file contents:
Then, bind the URL with the View function, open the urls.py file, introduce the views and add (' ^hellodjango/$ ', Hellodjango), this line of code, urls.py file as follows:
At this point, I want to restart the Web service and set the port number to 2222 (manage.py runserver 2222), and then enter Localhost:2222/hellodjango in the address bar of the browser, and the following expected results appear:
To summarize: (note transformation related paths)
1. Django Installation
python setup.py Install
2. App Generation and startup
django-admin.py Startproject {PROJECT_NAME}
cd {PROJECT_NAME}
[manage.py Startapp {app name}]
3. Start the server
manage.py Runserver [[IP:] Port]
4. Open the URL with a browser
http://localhost: Port/[function name]
So, this is my first lesson in Django, very interesting, hehe ~ ~
Django's Windows installation