2015-05-12

django compressor 找不到 offline manifest 問題解法

如果你用 django compressor,而且你用的是 offline compress
COMPRESS_ENABLED = True
COMPRESS_OFFLINE = True
那麼你有可能會遇到以下錯誤訊息

  1. You have offline compression enabled but key "70be2d0f8286eb3a32bfe94a55518c8f" is missing from offline manifest. You may need to run "python manage.py compress".
這代表你的 compress tag 包夾的內容含有動態性的資料
因為 compressor 是用內容 hash 成 hash code 去 lookup cached javascript
所以 offline compress 的東西產生的 hash code 會跟你線上得到的 code 不一樣
例如以下這個例子,拿掉{{user.email}}即可正常
  1. {% compress js %}
  2. ......
  3. formData.append('email', '{{ user.email }}');
  4. ......
  5. {% endcompress %}
請確保你的 compress 是壓縮最內層、乾淨的「靜態」資料

2015-05-01

javascript 中文字長度判斷

因為現在網頁幾乎都是 utf8, 所以以往中文字會被判斷成2 bytes的問題現在都變成1了
例如
var s="中"
alert(s.length)
結果會顯示 1

那麼你若想要判斷 byte 的長度怎麼辦? (因為有時資料庫長度限制需求)
這裡有個網路上網友提供的好方法,速度快,又不用 regular express 或 encodeURIComponent 

2015-04-29

django template 樣版引擎 語法與其它工具衝突的解法


使用 {% verbatim %}
例如底下的字串 '<div><strong>{{value}}</strong> – {{year}}</div>' 中的 {{value}}, {{year}}你不想 django template解譯


你可以:

2015-04-28

MySQL 相關問題

問題:lost connection to mysql server during query
原因可能是由於與 mysql 網路連線過慢或者資料量過大需要較長的讀取/insert(if indexed) 時間
試著設定系統變數 net_read_timeout
mysql -u username -p
...
...

2015-04-24

centos 6 上的 avahi 與 nss-mdns 安裝


avahi 是 mdns 的 server, 用來廣播通知他人我的 ip (利用.local)
nss-mdns 是解析它人 .local 位址
這兩個服務通稱 zeroconfig service, 詳情點這裡


別人 ping 不到你時是 server 有問題
[Server : avahi]
to broadcat to others who I am (myname.local)

安裝:
#yum install avahi

================================================================


你 ping 不到別人時,是你有問題
[Client : nss-mdns]
to resolve others (others_name.local)

安裝:
#wget http://dl.atrpms.net/el6-x86_64/atrpms/stable/nss-mdns-0.10-2.el6.x86_64.rpm
#rpm -i nss-mdns-0.10-2.el6.x86_64.rpm

再到 /etc/nsswitch.conf, 找到 hosts: , 設成以下:

hosts:      files mdns4_minimal mdns4 [NOTFOUND=return] dns

安裝完成後 ping 別人看看
[user@somewhere var]# ping foo.local
PING foo.local (192.168.1.45) 56(84) bytes of data.
64 bytes from foo.local (192.168.1.45): icmp_seq=1 ttl=64 time=0.368 ms
64 bytes from foo.local (192.168.1.45): icmp_seq=2 ttl=64 time=0.154 ms
64 bytes from foo.local (192.168.1.45): icmp_seq=3 ttl=64 time=0.154 ms



你的 avahi 每一段時間會停止? 是 firewall 問題,請看這篇

centos6 每過一段時間 avahi 就會停止的解決方法

你有沒有發現 Centos6 上的 avahi service 每過一段時間就會停止
從其它電腦無法  ping ?

原因是 iptables firewall 造成的
解決方法是:

2015-04-21

判斷 IE版本的方法

因為各版本的 IE 有各版本的問題
所以 IE 很多需要 '向下' 相容
於是 microsoft 新版的 IE 就提供以下這語法來判斷 IE 的版本又不致於影響其它人
我們都知道 <!--  這是註解   -->  是 html 裡面的註解,基本上browser直接會忽略。
但是  IE 對以下的標籤則會去判斷它


        <!--[if lt IE 9]> IE9以下的 include 底下
            <script src="http://your.domain.com/js/jquery-1.11.2.min.js"></script>
        <![endif]-->
        <!--[if (gte IE 9) | (!IE)]><!-->    非 IE 及 IE9以上的 include 底下
            <script src="http://your.domain.com/js/jquery-2.1.1.min.js"></script>
        <!--<![endif]-->      


說明:
  1. lte  : 小於或等於
  2. lt     : 小於
  3. gte: 大於或等於
  4. gt   : 大於
  5. !      : 不等於、例如 : [if !IE] 瀏覽器不等於IE