關於伺服器 安裝配置django

2021-09-01 20:01:51 字數 4526 閱讀 8470

django是乙個基於python語言的伺服器框架,能夠幫助我們輕易開發乙個web應用,下面記錄一些簡單的安裝使用方法。

sudo pip install django==1.5.1

建立乙個新的web服務(mysite,可以進行路由路徑配置,資料庫配置等)

django-admin.py startproject mysite

建立乙個新的web應用(books,具體**實現)

類似mvc框架,django提供model,view等模組供我們使用(不過django的model更類似於資料庫定義,view類似mvc中的controller,template才是mvc中的view)編輯**如下

books/models.py

from django.db import models

# create your models here.

class publisher(models.model):

name = models.charfield(max_length=30)

address = models.charfield(max_length=50)

city = models.charfield(max_length=60)

state_province = models.charfield(max_length=30)

country = models.charfield(max_length=50)

website = models.urlfield()

def __unicode__(self):

return self.name

#class author(models.model):

# first_name = models.charfield(max_length=30)

# last_name = models.charfield(max_length=40)

# email = models.emailfield()

## def __unicode__(self):

# return u'%s %s' % (self.first_name, self.last_name)

#class book(models.model):

# title = models.charfield(max_length=100)

# authors = models.manytomanyfield(author)

# publisher = models.foreignkey(publisher)

# publication_date = models.datefield()

## def __unicode__(self):

# return self.title

books/views.py

# create your views here.

from django.shortcuts import render_to_response

from books.models import publisher

def list_publishers(request):

publishers = publisher.objects.all()

return render_to_response('list_publishers.html', )

templates/list_publishers.html

id #}

name #}

自定義配置web,設定資料庫連線等

mysite/settings.py

'books',

)databases =

}template_dirs = (

'/home/ciaos/mysite/templates',)

mysite/urls.py(利用python強大的正規表示式配置路由)

urlpatterns = patterns('',

# examples:

# url(r'^$', 'mysite.views.home', name='home'),

# url(r'^mysite/', include('mysite.foo.urls')),

# uncomment the admin/doc line below to enable admin documentation:

# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# uncomment the next line to enable the admin:

url(r'^publishers/',list_publishers)

)

python manager.py syncdb同步models到資料庫

通過python manage.py shell簡單操作查詢資料庫

執行資料庫如下(如果要後台執行可以使用nohup)

python manage.py runserver

用ab測試

ciaos@linux-53dr:~/mysite> sudo /usr/sbin/ab2 -c 10 -n 10000 

this is apachebench, version 2.3 <$revision: 655654 $>

licensed to the apache software foundation,

benchmarking 127.0.0.1 (be patient)

completed 1000 requests

completed 2000 requests

completed 3000 requests

completed 4000 requests

completed 5000 requests

completed 6000 requests

completed 7000 requests

completed 8000 requests

completed 9000 requests

completed 10000 requests

finished 10000 requests

server software: wsgiserver/0.1

server hostname: 127.0.0.1

server port: 8000

document path: /publishers/

document length: 69 bytes

concurrency level: 10

time taken for tests: 49.311 seconds

complete requests: 10000

failed requests: 0

write errors: 0

total transferred: 2020000 bytes

html transferred: 690000 bytes

requests per second: 202.80 [#/sec] (mean)

time per request: 49.311 [ms] (mean)

time per request: 4.931 [ms] (mean, across all concurrent requests)

transfer rate: 40.00 [kbytes/sec] received

connection times (ms)

min mean[+/-sd] median max

connect: 0 2 38.6 0 1001

processing: 22 47 82.8 36 2562

waiting: 6 41 82.7 31 2553

total: 22 49 91.3 36 2562

percentage of the requests served within a certain time (ms)

50% 36

66% 39

75% 41

80% 42

90% 52

95% 63

98% 100

99% 428

100% 2562 (longest request)

併發資料等沒有參考意義,因為是在我筆記本的虛擬機器上測試的,主要是與tornado伺服器做對比。用django實現乙個簡易的web應用還是非常方便的。

伺服器安裝配置摘要

配置伺服器網絡卡 防火牆設定 vi ect sysconfig iptables 新增伺服器對外服務埠 重啟防火牆 同步伺服器時間 設定vim etc resolv.conf dns配置檔案 解決終端 gedit 顯示亂碼 配置網絡卡檔案 vi etc sysconfig network scrip...

ejabberd伺服器安裝配置

以下安裝步驟在linux centos上進行。安裝erlang編譯環境 tar xzvf otp src r14b04.tar.gz configure make make install 執行erl,成功說明安裝沒問題。如果缺少依賴庫 yum install ncurses devel yum i...

svn伺服器安裝配置

yum install subversion 建立svn版本庫目錄 mkdir p var svn svnrepos 建立版本庫 svnadmin create var svn svnrepos 進入conf目錄 該svn版本庫配置檔案 authz檔案是許可權控制檔案 passwd是帳號密碼檔案 s...