Some requests require no session, auth, locale, csrf check, message, or many other middlewares. Especially, there are some useless db connection in django_session for some requests. Exclude unnecessary middlewares can make the requests go much faster.
但是這個作法的還是只有部分選擇性,一次必須跳過所有再內層的的 middleware,另外,如果想用讓某幾個 view 使用某些 middleware 且為數較少的話,應該使用 decorator_from_middleware
另外即使跳過 process_view or process_request 也無法跳過 process_response ,必須另外做處理
2014年2月5日
2013年10月7日
Django syncdb Error
Django MySql syncdb Error
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/path/to/venv/2.6/lib/python2.6/site-packages/_mysql.so, 2): no suitable image found. Did find:
/path/to/venv/2.6/lib/python2.6/site-packages/_mysql.so: mach-o, but wrong architecture
Sqlite3 syncdb Error
sqlite3.OperationalError: unable to open database file
What's the problem?
Chancese are that you tried to use same database with different python environment.
EnvironmentError: mysql_config not found on Mac
pip install MySQL-python
Got this error
EnvironmentError: mysql_config not found
Complete output from command python setup.py egg_info:
sh: mysql_config: command not found
The configuration in venv/build/MySQL-python/site.cfg points to a wrong executable of mysql_config.
The way to solve it
1. Change the site.cfg
2. Add /usr/local/mysql/bin to PATH
3. ln
sudo ln -s /usr/local/mysql/bin/mysql_config /usr/local/bin/mysql_config
If it's on Ubuntu
sudo apt-get install libmysqlclient-dev
2013年8月15日
使用 Django fixtures 一些特點
Django fixtures 比較常用在建立初期資料以及做測試時使用
initial_data.json 不論在django flush, syncdb 之後都會自動建立
fixtures 可以藉由 TestCase 的繼承來達到繼承和共用
fixtures 通常是比較乾淨的作法,但是也相對不靈活,我最後還是拿掉了大部分的 fixtures ,寧願自己建立 creation / deployement process
如果 fixtures 包含 auth.user 則在 syncdb 之後相對應的 auth.permission 會被自動建立。
在使用不同 database engine 的時候可以避免使用 auth.permissions fixtures 以避免 id 衝突 IntegrityError: columns content_type_id, codename are not unique ,如果有自設的 permissions 也可以讓資料先在 sqlite3 建立後再 dump 出來,這樣在用 sqlite3 做測試的時候才不會發生以上問題。
使用範例:
initial_data.json 不論在django flush, syncdb 之後都會自動建立
fixtures 可以藉由 TestCase 的繼承來達到繼承和共用
fixtures 通常是比較乾淨的作法,但是也相對不靈活,我最後還是拿掉了大部分的 fixtures ,寧願自己建立 creation / deployement process
如果 fixtures 包含 auth.user 則在 syncdb 之後相對應的 auth.permission 會被自動建立。
在使用不同 database engine 的時候可以避免使用 auth.permissions fixtures 以避免 id 衝突 IntegrityError: columns content_type_id, codename are not unique ,如果有自設的 permissions 也可以讓資料先在 sqlite3 建立後再 dump 出來,這樣在用 sqlite3 做測試的時候才不會發生以上問題。
使用範例:
python manage.py dumpdata --indent 4 -n -e contenttypes -e auth.permission -e session > initial_data.json
2013年7月29日
Django Jenkins 筆記
由於老闆不給放程式碼到 github ,我們只好來用 Jenkins ,其實相當方便
1. http://jenkins-ci.org/ download jenkins.war
2. java -jar jenkins.war to launch jenkins
3. goto http://localhost:8080 to setup a new project
4. install plugin Violations for pylint report and Cobertura for coverage report.
5. install Git plugin and restart
6.
Install jenkins on a new RedHat/CentOS server
https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+RedHat+distributions
sudo yum install java-1.6.0-openjdk
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
sudo yum install jenkins
Run jenkins service
sudo service jenkins start/stop/restart
1. http://jenkins-ci.org/ download jenkins.war
2. java -jar jenkins.war to launch jenkins
3. goto http://localhost:8080 to setup a new project
4. install plugin Violations for pylint report and Cobertura for coverage report.
5. install Git plugin and restart
6.
Install jenkins on a new RedHat/CentOS server
https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+RedHat+distributions
sudo yum install java-1.6.0-openjdk
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
sudo yum install jenkins
Run jenkins service
sudo service jenkins start/stop/restart
2012年5月6日
Aptana, Eclipse Zen-Coding 讓你寫html比打MSN還快
最近朋友去了一間對於寫code要求很變態的公司,多變態呢?基本上你的coding速度要比聊天打字還快才有機會過試用期。
雖然寫程式速度加快不代表產品週期就可以減短,但是為了讓碼農能夠在無良資方當道的世代生存下去,我開始尋找增加寫程式速度的方法,我認為主要可以分成兩種:
一個是語言的提升,讓碼農能夠直接寫一個語言的核心
另一種是工具的提升,讓碼農能夠用更好的工具來所減少非決策性或重複性的工作
今天要介紹Zen Coding真的是一個很屌的東西,基本上他同時有兩種特性
他是一個編輯器外掛,目前許多編輯器都有支援,如果你是用Aptana or Eclipse
可以到help > install software 從 http://zen-coding.ru/eclipse/updates/ 更新
使用方式非常簡單
當你寫html的時候打上
div#myid.myclass
然後tab或command+E
Zen Coding會自動幫你轉換成
<div class="myclass" id="myid">
</div>
完全是css selector的方式
再來使用
div#page>div.logo+ul#navigation>li*5>a可以自動轉換成
<div id="page">
<div class="logo"></div>
<ul id="navigation">
<li><a href=""></a></li>
<li><a href=""></a></li>
<li><a href=""></a></li>
<li><a href=""></a></li>
<li><a href=""></a></li>
</ul>
</div>
Zen coding還可以用$字號帶入數字序列,還可以有擴展功能來支援各種template的語法
比如說打入
djb#body>div#header
可以自訂格式讓他成為
{% block body %}
<div id='header'>
</div>
{% endblock %} 此外還有圖片大小自動輸出command+i
對選取的html做修改command+shift+a等等
Zen coding讓你寫程式比打MSN還快不再是夢想
趕快裝起來玩玩吧!!
2011年11月14日
python, django, mongodb
from http://www.chrisumbel.com/article/django_python_mongodb_engine_mongo
MongoDB - I guess this is somewhat self explanatory, but you'll need MongoDB itself.
django-norel - is a special version of django designed for use with non-relational database engines in general.
django tooblox - a general purpose utility library upon which django-mongodb-engine depends
django-mongodb-engine - the MongoDB driver for django.
安裝mongodb
1.http://www.mongodb.org/downloads
2.http://www.mongodb.org/display/docs/quickstart
建立/data/db或C:\data\db
執行mongodb
download django-norel and install
MongoDB - I guess this is somewhat self explanatory, but you'll need MongoDB itself.
django-norel - is a special version of django designed for use with non-relational database engines in general.
django tooblox - a general purpose utility library upon which django-mongodb-engine depends
django-mongodb-engine - the MongoDB driver for django.
安裝mongodb
1.http://www.mongodb.org/downloads
2.http://www.mongodb.org/display/docs/quickstart
brew update
brew install mongodb
建立/data/db或C:\data\db
執行mongodb
/usr/local/Cellar/mongodb/2.0.1-x86_64/bin/mongo/mongod #db server
/usr/local/Cellar/mongodb/2.0.1-x86_64/bin/mongo/mongo #db interactive console
easy_install pymongo
download django-norel and install
cd django-norel
sudo python setup.py install
easy_install djangotoolbox
easy_install django-mongodb-engine
2011年10月26日
django for loop 筆記
有時後建好了多個list之後在顯示時需要同時尋訪每個list的第一個值、第二個值…
這時你可能要考慮在一開使的時候就建立一個物件,讓其變成物件一個list而非多個獨立的list
或是使用zip來建立tuple list
尋訪時使用
這時你可能要考慮在一開使的時候就建立一個物件,讓其變成物件一個list而非多個獨立的list
或是使用zip來建立tuple list
newlist = zip(list1, list2)
尋訪時使用
{% for i1, i2 in newlist %}
{{i1}} {{i2}}
{% endfor %}
訂閱:
文章 (Atom)