本文由 PurePeace 原创
Saleor系列教程之1、saleor介绍及后端GraphQL服务安装配置:
Saleor:基于Python、Django、GraphQL、React.js的开源免费无头电子商务平台saleor,介绍及安装配置详细教程(1)后端 GraphQL api 示例数据 管理员账号:https://blog.csdn.net/qq_26373925/article/details/104265313
Saleor系列教程之2、saleor前端安装配置教程:
Saleor:基于Python、Django、GraphQL、React.js的开源免费无头电子商务平台saleor,介绍及安装配置详细教程(2)前端 商城页面:https://blog.csdn.net/qq_26373925/article/details/104270046
Saleor系列教程之3、saleor Dashboard安装配置教程:
Saleor:基于Python、Django、GraphQL、React.js的开源免费无头电子商务平台saleor,介绍及安装配置详细教程(3)Dashboard 管理后台:https://blog.csdn.net/qq_26373925/article/details/104271600
项目:saleor
stars:6.7k
简介:开源的无头电子商务平台(商城&网店)
官网:https://saleor.io/
github(后端):https://github.com/mirumee/saleor
github(前端):https://github.com/mirumee/saleor-dashboard
github(dashboard):https://github.com/mirumee/saleor-dashboard
saleor文档(Next版):https://docs.saleor.io/docs/next/index.html
演示(商城):https://pwa.saleor.io/
后台演示(dashboard):https://pwa.saleor.io/dashboard/
saleor是这样介绍自己的:
A modular, high performance, headless e-commerce storefront built with
Python, GraphQL, Django, and ReactJS.
翻译过来大概就是:
无头电子商务是个名词,详细解释可以看这篇文章:https://zhuanlan.zhihu.com/p/92992305
这里我摘了几段话简单解释:
什么是无头电子商务(Headless eCommerce)? 无头电子商务(Headless eCommerce)本质上是指网站“前端与后端完全分离”的电子商务开发模式。
相较于传统电商(Traditional eCommerce),无头电商通过API独立调用网站前后端逻辑构架。消费者体验、多渠道可拓展性、内容维护与响应速度、开发难度与时间成本获得显著优化。目前品牌方正期待为用户提供独特、定制且整合的购物体验,而无头电商显著了消解了达到上述目标的难度。
最重要的是,无头电商模式下“API即服务”,因此他能够跨越任何渠道与设备并处理电子商务流程,包括但不仅限于如下渠道的无缝链接:官网、小程序、原生APP、智能与穿戴设备(如智能手表、车载仪表盘的订单系统)、ERP及门店订单管理系统等。
大概就是这样
官方文档(windows):https://docs.saleor.io/docs/next/getting-started/installation-windows/
官方文档(linux):https://docs.saleor.io/docs/next/getting-started/installation-linux/
官方文档(macos):https://docs.saleor.io/docs/next/getting-started/installation-macos/
接下来我选择在自己的windows10系统下安装,需要在其它系统下安装请看官方文档
git clone https://github.com/mirumee/saleor.git
接着进入克隆好的项目目录
cd saleor
此步骤请务必在虚拟环境下进行!以免出现未知问题
python -m pip install -r requirements.txt
# Make this unique, and don't share it with anybody.
SECRET_KEY = os.environ.get("SECRET_KEY")
可以看出,这里原本是在系统环境变量里找到 SECRET_KEY
并进行赋值的
SECRET_KEY
变量赋值,就不用改环境变量了,随便一个字符串即可,但最好要够安全settings.py
第50行处 DATABASES
字典修改数据库配置,改成你想要的密码DATABASES = {
"default": dj_database_url.config(
default="postgres://saleor:saleor@localhost:5432/saleor", conn_max_age=600
)
}
CREATE ROLE saleor WITH
LOGIN
SUPERUSER
CREATEDB
CREATEROLE
INHERIT
REPLICATION
CONNECTION LIMIT -1
PASSWORD 'saleor';
GRANT postgres TO saleor WITH ADMIN OPTION;
创建数据库
CREATE DATABASE saleor
WITH
OWNER = saleor
ENCODING = 'UTF8'
CONNECTION LIMIT = -1;
接着初始化数据库
python manage.py migrate
settings.py
中的数据库配置是否正确当然,这些数据表都是空的,所以接下来我们需要添加数据,并创建网站管理员账号
python manage.py createsuperuser
我们可以在数据库表 account_user
中看到刚才新建的管理员账号
python manage.py populatedb --createsuperuser
--createsuperuser
这个参数会额外创建一个管理员账户,[email protected]
,密码为 admin
同样地,可以打开数据库查看数据表,我就不发图了
在项目目录中打开命令行(cmd / powershell),执行
Node.js
的版本npm install
下面是无需执行的命令:
npm run build-assets
npm run build-emails
python manage.py runserver
接下来打开网页,http://127.0.0.1:8000/graphql/
看到这里,属于后端的GraphQL服务已经启动成功了
试试在页面左侧写入以下内容,然后点击网页上的箭头按钮:
query {
products(first: 3) {
edges {
node {
id
name
description
category {
name
}
}
}
}
}
{
"data": {
"products": {
"edges": [
{
"node": {
"id": "UHJvZHVjdDo3Mg==",
"name": "Apple Juice",
"description": "Fell straight from the tree, on to Newton’s head, then into the bottle. The autumn taste of English apples. Brought to you by gravity.",
"category": {
"name": "Juices"
}
}
},
{
"node": {
"id": "UHJvZHVjdDo3NA==",
"name": "Banana Juice",
"description": "Build your protein the natural way, with exotic banana juice made from ripe fruit and packed with all the goodness of the tropical sun.",
"category": {
"name": "Juices"
}
}
},
{
"node": {
"id": "UHJvZHVjdDo3OQ==",
"name": "Bean Juice",
"description": "Bean there, drunk that! The energy drink for the health-conscious. Brand new bean juice; from allotment to bottle in under 8 hours.",
"category": {
"name": "Juices"
}
}
}
]
}
}
}
{
"data": {
"products": {
"edges": []
}
}
}
搞定~
至此,saleor后端GraphQL服务及示例数据已经安装完毕,接下来安装前端和dashboard吧。
系列教程之1、saleor介绍及后端GraphQL服务安装配置:
Saleor:基于Python、Django、GraphQL、React.js的开源免费无头电子商务平台saleor,介绍及安装配置详细教程(1)后端 GraphQL api:https://blog.csdn.net/qq_26373925/article/details/104265313
系列教程之2、saleor前端安装配置教程:
Saleor:基于Python、Django、GraphQL、React.js的开源免费无头电子商务平台saleor,介绍及安装配置详细教程(2)前端 商城页面:https://blog.csdn.net/qq_26373925/article/details/104270046
系列教程之3、saleor Dashboard安装配置教程:
Saleor:基于Python、Django、GraphQL、React.js的开源免费无头电子商务平台saleor,介绍及安装配置详细教程(3)Dashboard 管理后台:https://blog.csdn.net/qq_26373925/article/details/104271600
2020年2月11日 PurePeace