First, Django Introduction
Django is an open-source Web application framework written by Python. The MVC framework pattern was adopted, i.e. model M, view V and Controller C. It was originally developed to manage some of the news content-based websites of the Lawrence Publishing Group, namely CMS (Content management system) software. and was released in July 2005 under the BSD license. The framework is named after the Belgian gypsy jazz guitarist Django Reinhardt.
Second, the Django framework
650) this.width=650; "Src=" https://gss1.bdstatic.com/-vo3dSag_xI4khGkpoWK1HF6hhy/baike/c0%3Dbaike80%2C5%2C5%2C80 %2c26/sign=8bccb1563b87e950561afb3e71513826/738b4710b912c8fcfe024858fd039245d78821b5.jpg "width=" 463 "height=" 538 "alt=" 738b4710b912c8fcfe024858fd039245d78821b5 "/>
Third, Django installation
Since Django is a Python web framework, you must first install Python to run the Django program.
Django-supported Python versions:
Django Version |
python version |
1.8 |
2.7,3.2 (until the end of 2016), 3.3,3.4,3.5 |
1.9,1.10 |
2.7,3.4,3.5 |
Installation:
1) using the Python PIP installation module, if you want to install the Django1.8.1 version, command: Pip install django==1.8.1
Verify:
You can import the Django module test on the Python command line interface, and if the installation is successful, the following information is displayed:
>>> Import django>>> Print (Django.get_version ()) 1.8.1
Note: The following issues may occur when you enter django-admin at the command prompt after the Windows installation has completed Django
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/08/65/wKiom1ngohDzaVWTAAAJnbPYOwQ893.png "title=" Qq20171013192107.png "alt=" Wkiom1ngohdzavwtaaajnbpyowq893.png "/>
Workaround: View My Computer Properties Open "Advanced system Settings"-"Environment variables" on the left
Choose to include the path of django-admin in the path variable, restart the command prompt in the input django-admin.py can see django-admin.py script can run
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/A7/1C/wKioL1ngn8fhBLnoAAEZfZ4B73w230.png "title=" Qq20171013192233.png "alt=" Wkiol1ngn8fhblnoaaezfz4b73w230.png "/>
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/08/65/wKiom1ngorLDWjvSAAA7YrK60Kk368.png "title=" Qq20171013192350.png "alt=" Wkiom1ngorldwjvsaaa7yrk60kk368.png "/>
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/08/65/wKiom1ngo8LCg3PSAAA9qZiMWgI882.png "title=" Qq20171013192647.png "alt=" Wkiom1ngo8lcg3psaaa9qzimwgi882.png "/>
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/08/65/wKiom1ngo-qz-oMKAAA5VLxeUc8562.png "title=" Qq20171013192908.png "alt=" Wkiom1ngo-qz-omkaaa5vlxeuc8562.png "/>
Iv. creating a simple Web site with Django
Django creates a site that is quick and easy and requires only a few simple commands, and a basic website is created.
1) Create MySite Project
c:\users\administrator>django-admin.py Startproject mysitec:\users\administrator>
After the command is complete, you can see a new MySite directory, the MySite directory tree as follows:
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/08/65/wKiom1ngpMrwOb4eAAAH3Akp0s0823.png "title=" Qq20171013193253.png "alt=" Wkiom1ngpmrwob4eaaah3akp0s0823.png "/>
File Description:
django-admin.py: is a Django command-line tool for managing tasks
Manage.py:Django Project Management command-line tools are automatically generated for each project you create.
manage.py is a simple package for django-admin.py, and it helps us do two things in addition:
-
It puts your project's package in the Sys.path
It sets the Django_settings_module environment variable to the location of your project's setting.py file.
Urls.py:python the processing mechanism of URL matching
settings.py: Site project configuration file, you can configure the site language, database connection, static content path and so on.
2) Use manage.py to create an application (app) for MySite, Mysite_app
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/A7/1C/wKioL1ngo0iiuu5qAAAf1oK_wmw357.png "title=" Untitled. png "alt=" Wkiol1ngo0iiuu5qaaaf1ok_wmw357.png "/>
3) At this point, a simple site is created to complete, next test site can not access
To run the server:
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/08/65/wKiom1ngpn7CBnZrAAAZQqngy9w835.png "title=" Runserver.png "alt=" Wkiom1ngpn7cbnzraaazqqngy9w835.png "/>
From the output of the program you can see that the Web server has been created successfully, running on port 8000 of 127.0.0.1
Access Server (127.0.0.1:8000):
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/08/66/wKiom1ngpuqC_7elAABt1oIi1t8925.png "title=" Access.png "alt=" Wkiom1ngpuqc_7elaabt1oii1t8925.png "/>
If you see the above hint, the Web site has been created successfully! Next, you can add your own HTML content .... Perfect site, stop service please press CTRL + C to stop the service at the command prompt
Reference Documentation:
Baidu Encyclopedia-django
faq:installation | Django Documentation | Django
Various features of the Django manage.py
This article from "Lonely No Worry" blog, please be sure to keep this source http://jlnetc.blog.51cto.com/10920149/1972216
Python Web framework-Getting started with Django