? ? 這兩天又試著在一個新平臺Pythonanywhere上部署了項目叶骨,現(xiàn)在此記錄一下過程,主要是強化一下記憶,要是能幫上其他人就再好不過了六敬。
GitHub
我想程序員對這個網(wǎng)站再熟悉不過了,我也不多介紹了驾荣,在整個過程中外构,GitHub的作用是當做一個中介平臺,我先把本地的項目push到GitHub的倉庫里播掷,然后在第三方服務器上進行克隆和部署审编。
Pythonanywhere
我這里就直接截取一段維基上的介紹吧
PythonAnywhere is an online Integrated Development Environment (IDE) and Web hosting service based on the Python programming language.[1] It provides in-browser access to server-based Python and Bash Command-line interfaces, along with a code editor with Syntax highlighting. Program files can be transferred to and from the service using the user's browser. Web applications hosted by the service can be written using any WSGI-based application framework.
首先注冊一個免費賬號,雖然功能有限歧匈,但是作為實驗夠用了垒酬,登陸之后打開一個bash,然后克隆GitHub的項目
git clone https://github.com//yourrepo.git
然后可以創(chuàng)建虛擬環(huán)境件炉,這樣可以并存多個項目勘究。接著安裝Django象迎。接著運行
python manage.py migrate? ? ?python manage.py createsuperuser??
注意環(huán)境里Python2和python3兩個版本拴孤,根據(jù)你的需要使用,接下來就可以發(fā)布項目了带迟,注意不要選擇默認的Django設置磕蛇,要選擇手動的設置景描。
wsgi
接下來就該配置wsgi文件了十办,wsgi實際上是一個協(xié)議規(guī)范,規(guī)定了web服務器和web應用之間的接口超棺。
import os
import sys
path = os.path.expanduser('~/yourdir')
if path not in sys.path:
? ? sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'your.settings'
from django.core.wsgi import get_wsgi_application
from django.contrib.staticfiles.handlers import StaticFilesHandler
application = StaticFilesHandler(get_wsgi_application())
配置好以后reload項目向族,如果正常的話應該就可以啟動了。如果沒有正常啟動说搅,那么你應該看看你的日志文件炸枣。
總結(jié)
這是一個簡單的部署活動适肠,但是其他的項目也八九不離十,重要的是這樣一種開發(fā)方式候引,本地開發(fā)侯养,測試好以后直接push到生產(chǎn)環(huán)境。