2016年2月11日 星期四

Django REST framework

最近想開發RESTful service, 想說看看Python的solution,就找到了Django REST fraemwork…
Authentication type:
  • Basic authentication

  • Token authentication

  • JWT authentication

  • json web token authentication
    一種較Oauth輕量化的方式,利用json的格式,儲存token,
    使用者登入後,利用帳號、密碼,取得一個全新的token,預設在5分鐘後即會過期,
    過期後,可利用已過期的token,取得新的token,
    如此便解決不用重複傳送username與password的風險,且token會一直更新。

  • OAuth2 authentication

  • django-oauth-toolkit

  • Session authentication

  • 使用此方法,需注意跨站台偽造攻擊的CSRF token處理,
    詳見:AJAX X-CSRFToken
http://www.django-rest-framework.org/

2016年1月24日 星期日

CentOS 7.2 安裝Python 3.4 + Django 1.9

安裝完成PostgreSQL後,接下來的重點,
就是要安裝Python 3.4 + Django + Django REST framework…
●安裝Python 3.4
sudo yum install Python34

sudo加在yum命令前,是用來讓安裝這個套件的動作,
取得super user的安裝套件權限,這樣一來就不用切換到root帳戶,可降低系統風險

2016年1月23日 星期六

CentOS 7.2 安裝 PostgreSQL 9.4

最近在使用CentOS 7.2 build 1511, 之後會用到django rest framework + postgreSQL
於是今天就嘗試安裝相關的環境,這篇就只記錄安裝 postgreSQL 9.4的部份…
首先,使用yum 安裝 postgreSQL 套件
postgreSQL 目前支援的linux作業系統與版本可以到官網上查詢,提供查詢網址如下:
http://yum.postgresql.org/repopackages.php
裡面有不同版本對應作業系統的Repository

2015年11月26日 星期四

[RWD] Google maps

RWD with Google maps…

reference:
http://webomnizz.com/how-to-make-responsive-google-map-with-google-map-api/

方法一:css
HTML內容:

<div class="map-canvas" id="map-canvas">

<iframe frameborder="0" height="350" marginheight="0" marginwidth="0" scrolling="no" src="https://www.google.com.tw/maps/@24.7655142,121.0162967,15z?hl=zh-TW" width="425"></iframe>

</div>



2015年11月23日 星期一

Python學習筆記(四) - Advanced Django models management

Django裡,model的資料操作與查詢,可進階寫成Manager,整個詳細過程記錄如下…

一、定義Manager class:
class TempleManager(models.Manager):
    def create_temple(self,name,locateRegion,religiousBelief,masterGod,address,latitude,longitude,phone1,phone2):
        temple = self.create(name = name, locateRegion = locateRegion, religiousBelief = religiousBelief, masterGod = masterGod, address = address, latitude = latitude, longitude = longitude, phone1 = phone1, phone2 = phone2)
        return temple

    def filter_temple(self,name,locateRegion,masterGod,address):
        temple = self.filter(name = name, locateRegion = locateRegion,  masterGod = masterGod, address = address)
        return temple

    def filterByMasterGod(self, masterGod):
        temple = self.filter(masterGod = masterGod)
        return temple

    def filterByRegion(self, locateRegion):
        temple = self.filter(locateRegion = locateRegion)
        return temple