Environment:
A, CentOS 5.6 x64
B, Python 2.7
C, Django 1.6
1. Create a project
#python django-admin.py Startproject test01
2. Create a View
#vim views.py
#-*-Coding:utf-8-*-
From django.http import HttpResponse
def test_page (Request):
Return HttpResponse ("<p> my_test_project</p>")
3. Create an App
#python manage.py Startapp App1
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/84/39/wKiom1eInnzyN6WoAABDLHu0ukw519.jpg-wh_500x0-wm_3 -wmp_4-s_3930023145.jpg "title=" cmtxk_y61oy9b%2k6tsp%9v.jpg "alt=" Wkiom1einnzyn6woaabdlhu0ukw519.jpg-wh_50 "/>
4. Add a page to App1
#vim setting.py
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/84/39/wKioL1eInsjhnhlyAABmvYx8RlU125.jpg-wh_500x0-wm_3 -wmp_4-s_104361112.jpg "title=" 46Q@QVD) ib{ds[p5pq}jsy0.jpg "alt=" Wkiol1einsjhnhlyaabmvyx8rlu125.jpg-wh_50 "/>
5, Add the following in the URL of test01
Remove comments from Import admin
From Django.contrib Import admin
Add to
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/84/39/wKioL1eInvWTtA6cAABENzWO6qk160.jpg-wh_500x0-wm_3 -wmp_4-s_3710685060.jpg "title=" 1%l51}yl_v (Q3 (4MU] ' 5k{q.jpg "alt=" Wkiol1einvwtta6caabenzwo6qk160.jpg-wh_50 "/>
Urlpatterns = Patterns ("',
URL (r ' ^admin/', include (Admin.site.urls)),
URL (r ' ^$ ', ' test01.views.test_page '),
URL (r ' ^app1/', include (' App1.urls ')),
)
6, Add in App1 's URLs
#vim app1/urls.py
From django.conf.urls import patterns,include, url
From Django.contrib Import admin
Urlpatterns = Patterns ("',
URL (r ' ^$ ', ' app1.views.first_page '),
)
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/84/39/wKiom1eInz_iT_EXAAAehlBgD5I867.png-wh_500x0-wm_3 -wmp_4-s_3584912741.png "title=" Image.png "alt=" Wkiom1einz_it_exaaaehlbgd5i867.png-wh_50 "/>
7. Create an views view of the app
Vim app1/views.py
#-*-Coding:utf-8-*-
From django.http import HttpResponse
def first_page (Request):
Return HttpResponse ("<p>app1 test successfuly!</p>")
8. Test Access
#python manage.py Runserver 0.0.0.0:8000
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/84/39/wKioL1eIn3uwO0OrAABC8qGNccE042.png-wh_500x0-wm_3 -wmp_4-s_4118173600.png "title=" Image.png "alt=" Wkiol1ein3uwo0oraabc8qgncce042.png-wh_50 "/>
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/84/39/wKioL1eIn_3Qr_0GAABDdtredg0360.png-wh_500x0-wm_3 -wmp_4-s_497023896.png "title=" Image.png "alt=" Wkiol1ein_3qr_0gaabddtredg0360.png-wh_50 "/>
9. Configuration database
A: Create a database Django
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/84/39/wKiom1eIoCWBtdUaAAATeUVICjk614.png-wh_500x0-wm_3 -wmp_4-s_970423951.png "title=" Image.png "alt=" Wkiom1eiocwbtduaaaateuvicjk614.png-wh_50 "/>
#create database Django default CharSet UTF8;
Authorized to Soul Users
To modify the database link information in setting
#vim setting
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/84/39/wKioL1eIoFKCltEwAAAp1Jp4He4607.png-wh_500x0-wm_3 -wmp_4-s_2253368592.png "title=" Image.png "alt=" Wkiol1eiofkcltewaaap1jp4he4607.png-wh_50 "/>
#python manage.py syncdb
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/84/39/wKioL1eIoHqDly00AACiRczIOXk766.png-wh_500x0-wm_3 -wmp_4-s_3852523711.png "title=" Image.png "alt=" Wkiol1eiohqdly00aacirczioxk766.png-wh_50 "/>
Database Django will automatically add some more data tables
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/84/39/wKiom1eIoJ_i4ZKWAAAa7fMnHLU673.png-wh_500x0-wm_3 -wmp_4-s_916587543.png "title=" Image.png "alt=" Wkiom1eioj_i4zkwaaaa7fmnhlu673.png-wh_50 "/>
Test to access a bit
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/84/39/wKiom1eIoOewQRyXAABnk6BFLPs265.png-wh_500x0-wm_3 -wmp_4-s_3848412383.png "title=" Image.png "alt=" Wkiom1eiooewqryxaabnk6bflps265.png-wh_50 "/>
Successful landing
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/84/39/wKiom1eIoQPxsWAkAABO6xCRoH0734.png-wh_500x0-wm_3 -wmp_4-s_370655833.png "title=" Image.png "alt=" Wkiom1eioqpxswakaabo6xcroh0734.png-wh_50 "/>
Add Chinese language
#vim: /test01/settings.py
Add ' Django.middleware.locale.LocaleMiddleware ',
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/84/39/wKioL1eIoSmQR7-bAABTyuUA7e4228.png-wh_500x0-wm_3 -wmp_4-s_2207086808.png "title=" Image.png "alt=" Wkiol1eiosmqr7-baabtyuua7e4228.png-wh_50 "/>
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/84/39/wKioL1eIoWGSmI5SAAAZdRNNKkU927.png-wh_500x0-wm_3 -wmp_4-s_3993110636.png "title=" Image.png "alt=" Wkiol1eiowgsmi5saaazdrnnkku927.png-wh_50 "/>
10, create the independent model (need to inherit models. Model)
Vim app1/models.py
From django.db import Models
From Django.contrib.auth.models import User
Class Student (models. Model):
title = models. Charfield (max_length=18, Null=true)
Name = models. Charfield (max_length=128)
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/84/39/wKiom1eIob-BRX_JAAAmOkf99EA191.png-wh_500x0-wm_3 -wmp_4-s_2107927508.png "title=" Image.png "alt=" Wkiom1eiob-brx_jaaamokf99ea191.png-wh_50 "/>
Then run #python manage.py syncdb
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/84/39/wKioL1eIod-CIfvhAAAkuuwlGYE783.png-wh_500x0-wm_3 -wmp_4-s_1001956041.png "title=" Image.png "alt=" Wkiol1eiod-cifvhaaakuuwlgye783.png-wh_50 "/>
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/84/39/wKiom1eIof-QFTr1AAAPrF_XmtI707.png-wh_500x0-wm_3 -wmp_4-s_3159633229.png "title=" Image.png "alt=" Wkiom1eiof-qftr1aaaprf_xmti707.png-wh_50 "/>
Try it again.
#vim app1/models.py
Enter the following
Class author (models. Model):
Book = models. Charfield (MAX_LENGTH=32)
Author = models. Charfield (MAX_LENGTH=32)
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/84/39/wKiom1eIolLj2CpXAAA9AYVO4Mw816.png-wh_500x0-wm_3 -wmp_4-s_649631098.png "title=" Image.png "alt=" Wkiom1eiollj2cpxaaa9ayvo4mw816.png-wh_50 "/>
#然后运行 #python manage.py syncdb
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/84/39/wKiom1eIooijf4GhAAAcD5CwSII851.png-wh_500x0-wm_3 -wmp_4-s_2611137228.png "title=" Image.png "alt=" Wkiom1eiooijf4ghaaacd5cwsii851.png-wh_50 "/>
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/84/39/wKiom1eIopjxI1KRAAAjdovlSpc862.png-wh_500x0-wm_3 -wmp_4-s_1479240609.png "title=" Image.png "alt=" Wkiom1eiopjxi1kraaajdovlspc862.png-wh_50 "/>
Automatic generation of author tables
One of the most basic Web admin frameworks has been practiced here, followed by 、、、、、、、、
This article is from the "My_soul" blog, make sure to keep this source http://soul455879510.blog.51cto.com/6180012/1826774
Python Django Web Management Interface Admin Tool simple deployment