PyCharm+python3+django+vue 开发环境搭建

一:版本

1: 请自行安装Pycharm + Python3
1>pycharm 官方文件下载地址,请根据自己的电脑自行选择对应的软件下载 点击进入pycharm官方下载
pycharm激活码(PS:可以在里面找到所有软件的激活码)点击获得激活码
2>python3 进入Python官方网站下载安装包点击进入官方下载地址
3>安装了pip

二,环境搭建

1>安装项目虚拟环境:找到自己的Python3 安装路径,并打开终端,输入:(本人Python3 安装路径为:D:\Python3\python.exe ,mxshop为自己命名):
终端: mkvirtualenv -p D:\Python3\python.exe mxshop

C:\Users\win 10>mkvirtualenv -p D:\Python3\python.exe mxshop
Running virtualenv with interpreter D:\Python3\python.exe
Using base prefix 'D:\\Python3'
New python executable in D:\envs\mxshop\Scripts\python.exe
Installing setuptools, pip, wheel...
done.

2>安装 djangorestframework(点击查看官方文档):
终端:pip install djangorestframework

(mxshop) C:\Users\win 10>pip install djangorestframework
Collecting djangorestframework
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/djangorestframework/
  Downloading https://files.pythonhosted.org/packages/1b/fe/fcebec2a98fbd1548da1c12ce8d7f634a02a9cce350833fa227a625ec624/djangorestframework-3.9.4-py2.py3-none-any.whl (911kB)
     |████████████████████████████████| 921kB 139kB/s
Installing collected packages: djangorestframework
Successfully installed djangorestframework-3.9.4

3>加速安装 django :
终端: pip install -i https://pypi.douban.com/simple django

(mxshop) C:\Users\win 10>pip install -i https://pypi.douban.com/simple django
Looking in indexes: https://pypi.douban.com/simple
Collecting django
  Downloading https://pypi.doubanio.com/packages/b1/1d/2476110614367adfb079a9bc718621f9fc8351e9214e1750cae1832d4090/Django-2.2.1-py3-none-any.whl (7.4MB)
     |████████████████████████████████| 7.5MB ...
Collecting sqlparse (from django)
  Downloading https://pypi.doubanio.com/packages/ef/53/900f7d2a54557c6a37886585a91336520e5539e3ae2423ff1102daf4f3a7/sqlparse-0.3.0-py2.py3-none-any.whl
Collecting pytz (from django)
  Downloading https://pypi.doubanio.com/packages/3d/73/fe30c2daaaa0713420d0382b16fbb761409f532c56bdcc514bf7b6262bb6/pytz-2019.1-py2.py3-none-any.whl (510kB)
     |████████████████████████████████| 512kB ...
Installing collected packages: sqlparse, pytz, django
Successfully installed django-2.2.1 pytz-2019.1 sqlparse-0.3.0

4>安装:markdown
终端:pip install markdown

(mxshop) C:\Users\win 10>pip install markdown
Collecting markdown
  Downloading https://files.pythonhosted.org/packages/c0/4e/fd492e91abdc2d2fcb70ef453064d980688762079397f779758e055f6575/Markdown-3.1.1-py2.py3-none-any.whl (87kB)
     |████████████████████████████████| 92kB 122kB/s
Requirement already satisfied: setuptools>=36 in d:\envs\mxshop\lib\site-packages (from markdown) (41.0.1)
Installing collected packages: markdown
Successfully installed markdown-3.1.1

5>安装django-filter
终端:pip install django-filter

(mxshop) C:\Users\win 10>pip install django-filter
Collecting django-filter
  Downloading https://files.pythonhosted.org/packages/48/b4/7d52fb480108c9af88a4af520b371ac2ada55eac9970e025f147d0131b64/django_filter-2.1.0-py3-none-any.whl (69kB)
     |████████████████████████████████| 71kB 99kB/s
Requirement already satisfied: Django>=1.11 in d:\envs\mxshop\lib\site-packages (from django-filter) (2.2.1)
Requirement already satisfied: sqlparse in d:\envs\mxshop\lib\site-packages (from Django>=1.11->django-filter) (0.3.0)
Requirement already satisfied: pytz in d:\envs\mxshop\lib\site-packages (from Django>=1.11->django-filter) (2019.1)
Installing collected packages: django-filter
Successfully installed django-filter-2.1.0

6>查询安装版本:pip list

(mxshop) C:\Users\win 10>pip list
Package             Version
------------------- -------
Django              2.2.1
django-filter       2.1.0
djangorestframework 3.9.4
Markdown            3.1.1
pip                 19.1.1
pytz                2019.1
setuptools          41.0.1
sqlparse            0.3.0
wheel               0.33.4

7>安装mysqlclient(两种方式)
1>终端:pip install mysqlclient (此法如果出错,可以换第二种方法安装)
2>根据自己电脑版本下载文件对应版本mysqlclient文件(点击进入下载地址)
终端进入该文件存放的绝对路径安装:pip install D:\envs\mxshop\Scripts\mysqlclient-1.4.2-cp37-cp37m-win32.whl

(mxshop) C:\Users\win 10>pip install D:\envs\mxshop\Scripts\mysqlclient-1.4.2-cp37-cp37m-win32.whl
Processing d:\envs\mxshop\scripts\mysqlclient-1.4.2-cp37-cp37m-win32.whl
Installing collected packages: mysqlclient
Successfully installed mysqlclient-1.4.2

8>安装pillow
终端:pip install pillow

(mxshop) C:\Users\win 10>pip install pillow
Collecting pillow
  Using cached https://files.pythonhosted.org/packages/70/21/04723e78916eff8e09901dbb7dc9705f4de8a0dfe7882a9ed56982bd128e/Pillow-6.0.0-cp37-cp37m-win32.whl
Installing collected packages: pillow
Successfully installed pillow-6.0.0

9:Pycharm 创建新的项目
PyCharm+python3+django+vue 开发环境搭建_第1张图片

10:创建数据库,并且在settings.py 文件里 添加数据库

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': "mxshop",
        'USER': 'root',
        'PASSWORD': "333333",
        'HOST': "127.0.0.1",
        'OPTIONS': {'init_command': 'SET storage_engine=INNODB;'}
    }
}

11:在项目中创建apps和extra_apps,右键单击文件夹,将二者都Mark Direact as 成 Source root…同时在settings.py 文件中添加代码,将二者加入到项目的根搜索路径之下。。。

import os
import sys
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0,BASE_DIR)
sys.path.insert(0,os.path.join(BASE_DIR,'apps'))
sys.path.insert(0,os.path.join(BASE_DIR,'extra_apps'))

12:右键单击 Tools -run manage.py 然后在下边窗口输入 startapp user_operation 创建需要的app:如:user_operation(用户操作),goods(商品),trade(订单)等等,并整理目录,将新创立的app放入apps包下

manage.py@loveYou > startapp user_operation

13:操作user model:分析需求,创建合适的model,并将设计好的model 放入系统用户:在setting.py 文件中放入设计好的model

from datetime import datetime
from django.db import models
from django.contrib.auth.models import AbstractUser

# Create your models here.
class UserProfile(AbstractUser):
    """
    用户
    """
    name=models.CharField(max_length=30,null=True,blank=True,verbose_name="姓名")
    birthday=models.DateTimeField(null=True,blank=True,verbose_name="出生年月")
    mobile=models.CharField(max_length=11,verbose_name="手机号")
    gender=models.CharField(max_length=6,choices=(("male",u"男"),("female","女")),default=True,verbose_name="性别")
    authority=models.CharField(max_length=6,choices=(("0","超级管理员"),("1","一级管理员"),("2","二级管理员"),("3","普通会员")),default=True,verbose_name="用户权限")
    identification=models.CharField(max_length=11,null=True,verbose_name="身份证号")
    add_time=models.DateTimeField(default=datetime.now,verbose_name="添加时间")
    up_time = models.DateTimeField(default=datetime.now, verbose_name="信息更改时间")

setting.py 文件中

AUTH_USER_MODEL="users.UserProfile"

14:设计好所有app的model ,并且将所有的app都加入到settings.py中(设计model 时 DjangoUeditor附文本描述,拷贝原项目的DjangoUeditor文件放入extra_apps文件夹中,并将该文件添加到settings.py中,后可以import使用该文件)

from DjangoUeditor.models import UEditorField
goods_desc = UEditorField(verbose_name=u"内容", imagePath="goods/images/", width=1000, height=300,
                              filePath="goods/files/", default='')

settings.py文件中

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'apps.users.apps.UsersConfig',
    'DjangoUeditor'
    'goods'
    'trade'
    'user_operation'
    'users'
]

你可能感兴趣的:(Python)