此文主要是爲了測試一款 django 的模板,名爲 django-react-template,包括了前端和後端
首先,安裝環境如下
系統: centos7
python==2.7.5
django==1.9.4
postgreSQL9.6.17
第一步,在 postgreSQL 新建數據庫和用戶名
su - postgres
psql -U postgres
CREATE DATABASE react;
CREATE USER react WITH PASSWORD 'react';
ALTER USER react WITH SUPERUSER;
ALTER ROLE react SET client_encoding TO 'utf8';
ALTER ROLE react SET default_transaction_isolation TO 'read committed';
ALTER ROLE react SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE react TO react;
\q
第二步,用 virtualenv 新建一個虛擬環境
virtualenv django-react-template
cd django-react-template
source bin/activate
git clone https://github.com/scottwoodall/django-react-template.git
cd django-react-template
第四步,對前端進行配置
前端相對簡單一點,使用的工具主要是 npm ,這裏的版本是 6.12.1
cd frontend
npm install
npm start
第五步,對後端進行配置
pip2 install django
vim backend/settings/devl.py
改變其中的 database 部分,將其設置成如下的內容
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'react',
'USER': 'react',
'PASSWORD': 'react',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
最後完成服務器的部署和啓動
python2 manage.py migrate
python2 manage.py loadtestdata users.EmailUser:100
python2 manage.py createsuperuser
python2 manage.py runserver
完成