For many systems, authentication mechanisms may already exist, especially for systems that are authenticated by an OAuth server.
In this article, I want to customize Django authentication without creating any user model...
2020年4月3日 星期五
2018年7月14日 星期六
Django 2.0.7 deploy to Heroku
I create a Django 2.0.7 app to deploy to Heroku.
https://devcenter.heroku.com/articles/django-app-configuration
settings.py
https://devcenter.heroku.com/articles/django-app-configuration
settings.py
import django_heroku .... .... # Activate Django-Heroku django_heroku.settings(locals())
And when I run it with debug mode in local web app, it's running well.
But it always shows error when I deploy it to Heroku.
"relation "auth_user" does not exist"
2016年5月28日 星期六
刪除終端機存取中斷的python debug web server
適用情況:
遠端登入建立virtual environment,並啟動web server後,終端機斷線
在這種狀況下,web server還是在running state,所以port被佔住,無法debug
解決方法:
pkill -f "python manage.py runserver"
遠端登入建立virtual environment,並啟動web server後,終端機斷線
在這種狀況下,web server還是在running state,所以port被佔住,無法debug
解決方法:
pkill -f "python manage.py runserver"
2016年2月11日 星期四
Django REST framework
最近想開發RESTful service, 想說看看Python的solution,就找到了Django REST fraemwork…
Authentication type:
- Basic authentication
- Token authentication
- JWT authentication
- OAuth2 authentication
- Session authentication
json web token authentication
一種較Oauth輕量化的方式,利用json的格式,儲存token,
使用者登入後,利用帳號、密碼,取得一個全新的token,預設在5分鐘後即會過期,
過期後,可利用已過期的token,取得新的token,
如此便解決不用重複傳送username與password的風險,且token會一直更新。
django-oauth-toolkit
使用此方法,需注意跨站台偽造攻擊的CSRF token處理,
詳見:AJAX X-CSRFToken
2016年1月24日 星期日
CentOS 7.2 安裝Python 3.4 + Django 1.9
安裝完成PostgreSQL後,接下來的重點,
就是要安裝Python 3.4 + Django + Django REST framework…
就是要安裝Python 3.4 + Django + Django REST framework…
●安裝Python 3.4
sudo yum install Python34
sudo加在yum命令前,是用來讓安裝這個套件的動作,
取得super user的安裝套件權限,這樣一來就不用切換到root帳戶,可降低系統風險
sudo yum install Python34
sudo加在yum命令前,是用來讓安裝這個套件的動作,
取得super user的安裝套件權限,這樣一來就不用切換到root帳戶,可降低系統風險
2015年11月23日 星期一
Python學習筆記(四) - Advanced Django models management
Django裡,model的資料操作與查詢,可進階寫成Manager,整個詳細過程記錄如下…
一、定義Manager class:
一、定義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
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
2015年11月13日 星期五
Python學習筆記(三) - 部署到Microsoft Azure
今天上了Microsoft Azure課程後,一直想做一件事,就是把已經寫好的demo site部署到azure上,在多次嘗試後,終於成功。當然必要條件是要先有一個Microsoft Azure的帳戶…
今天再為demo專案加入一個新的功能,就是輸入地址,轉換為經緯度的功能;透過google map api提供的功能,讓我們很輕鬆的完成這個功能。
2015年11月12日 星期四
Python學習筆記(二)....感動的JSON處理
雖然只是測試功能,但對 Python處理JSON字串留下深刻的印象,再度對Django框架有了更濃厚的興趣
建立django虛擬環境(virtualvenv):
ref - https://djangogirlstaipei.gitbooks.io/django-girls-taipei-tutorial/content/django/installation.html
我們可以直接開始安裝 Django,但實務上,大多數人都會搭配使用虛擬環境。使用虛擬環境有許多優點:
建立django虛擬環境(virtualvenv):
ref - https://djangogirlstaipei.gitbooks.io/django-girls-taipei-tutorial/content/django/installation.html
我們可以直接開始安裝 Django,但實務上,大多數人都會搭配使用虛擬環境。使用虛擬環境有許多優點:
- 你的專案會擁有一個專屬的獨立 Python 環境。
- 不需要 root 權限,就可以安裝新套件。
- 方便控管不同版本的套件,不用擔心升級套件會影響到其他專案。
- 如果需要多人協作或在不同機器上跑同一個專案時,使用虛擬環境也可以確保環境一致性。
2015年11月10日 星期二
Python學習筆記(一)
這幾天,終於把Python的線上課程(https://www.codecademy.com)上完了,基本的語法和函數都不難,比較難的反而是class的語法有點難懂,不過這部份應該多寫就能習慣…
接下來,進入Django的世界,首先就是很多種plugin要安裝(目前用到的有pip, easy_install, setuptools, Django, psycopg2)。
easy_install, setuptools和pip通常已經內建於Python安裝程式。
安裝開發環境:
OS: Windows 7 64bits
1. Visual Studio 2015 Community
2. Git Hub
3. Python 3.4.3
4. PostgreSQL 9.4
easy_install, setuptools和pip通常已經內建於Python安裝程式。
安裝開發環境:
OS: Windows 7 64bits
1. Visual Studio 2015 Community
2. Git Hub
3. Python 3.4.3
4. PostgreSQL 9.4
訂閱:
文章 (Atom)