Python automated operations Django Getting Started

Source: Internet
Author: User

as IT Operations technology is increasingly updated, operational automation has become more and more popular in recent years, and people who learn python are very hot, especially Python Automation operation and development, has been praised by many predecessors, especially the old boy training center, old boy teacher,Alex teacher, thank you very much here.

Here I also record the previous study Django a little bit of experience and methods, convenient to check their own later, if you can help beginners are the best! OK, the others don't say much, the blog is dripping.

First, the system combat environment

System version: CnetOS6.5 X86_64django version: Django-1.5.8mysql version: Mysql-5.1.73python version: python-2.6.6

Second, Django Installation Deployment

first go to the official website to download Django main package, Django The official: https://www.djangoproject.com/

File:

https://www.djangoproject.com/download/1.5.8/tarball/

1 , django-1.5.8.tar.gz Installation Method:

tar-xzf django-1.5.8.tar.gz&&cd Django-1.5.8; python setup.py Install

2 , MySQL Installation Method: yum install MySQL mysql-server–y installation can be done.

Note * If you have a hint Setuptools module can not be found, you need to install this module, the installation method is to download the source package, and then execute python setup.py Install can be.

Django installation success such as:650) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M00/4A/16/ Wkiol1qiq6bqqxlaaauy9ylsk3m766.jpg "title=" 2.jpg "alt=" Wkiol1qiq6bqqxlaaauy9ylsk3m766.jpg "/>

so the first thing we're going to do next is how to create to build a default Django program, how to operate it?

3 , First execute command: django-admin.py |tail-15 django-admin.py All parameters followed, with one startproject

4 django-admin.py startproject firstweb firstweb Such a project name, enter firstweb directory, the directory under which the file, for example, has a manage.py such a script file, also executes it has many parameters, how to start django What about using parameters runserver

5 , execute the command: python manage.py runserver 0.0.0.0:8080

Such as:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/4A/16/wKioL1QiRBzC2uf5AAIIO_gxBSk890.jpg "title=" 4.jpg " alt= "Wkiol1qirbzc2uf5aaiio_gxbsk890.jpg"/>

6 , and finally visit us in the browser Django The program, as shown, represents Django build success.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/4A/16/wKioL1QiRE6i_5tsAAJuZOm8KjA962.jpg "title=" 5.jpg " alt= "Wkiol1qire6i_5tsaajuzom8kja962.jpg"/>

Third, create WebSite :

through the above construction and deployment, we find that this is a default Django page, how to have our own website, we can use Django What do you want to do?

Next Create your own program, the function of the program is to print Hello World , displayed in Web interface.

1 , first enter and manage.py of Peers Firstweb directory, Firstweb The directory contains the following files:

__init__.py __init__.pyc settings.py settings.pyc urls.py urls.pyc wsgi.py wsgi.pyc

Notes to the main configuration file:

settings.py main functions: Django settings to use.

urls.py file main Features: Configuration URL access control.

2 , New views.py file, write the following content:

From django.http import httpresponsedef Hello (Request): Return HttpResponse ("Hello World")

content annotations: calling django.http inside the module HttpResponse the module returns data and then defines a Hello function, return returns the contents of the function.

3 , Configuration urls.py

default urls.py configuration file contents such as:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/4A/15/wKiom1QiRGnzREIXAAGf02oSEIA377.jpg "title=" 8.jpg " alt= "Wkiom1qirgnzreixaagf02oseia377.jpg"/>

add two lines of records to the configuration file and import our defined Hello module, and then configure URL access. such as:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/4A/16/wKioL1QiRKzjzMEtAAIZVknFVaQ838.jpg "title=" 10.jpg "alt=" wkiol1qirkzjzmetaaizvknfvaq838.jpg "width=" 788 "height=" 354 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width : 788px;height:354px; "/>

Two lines of records that need to be added are:

From firstweb.views Import Hello//import the Hello function inside the project module. URL (r ' ^hello/', hello),//config URL,/hello/level two directory access, jump to the return information of the Hello function defined in the views.py file.

4 , Access testing:

Restart Django , and then access through the browser, such as:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/4A/16/wKioL1QiROCB0OzzAAD1buxBqxs867.jpg "title=" 9.jpg " alt= "Wkiol1qirocb0ozzaad1buxbqxs867.jpg" width= "680" height= "0" border= "0" hspace= "0" vspace= "width : 680px;height:300px; "/>

This article is from the "Wu Guangko-focus on automated Operations" blog, please be sure to keep this source http://wgkgood.blog.51cto.com/1192594/1557652

Python automated operations Django Getting Started

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.