前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >2.寻光集后台管理系统-创建项目

2.寻光集后台管理系统-创建项目

作者头像
zx钟
发布2022-12-02 15:38:26
3720
发布2022-12-02 15:38:26
举报
文章被收录于专栏:测试游记

创建Django项目

新建一个文件夹LightSeeking

由于是个全新的项目,所以创建一个虚拟环境来管理环境

当然本地需要先安装好python3

安装虚拟环境包

代码语言:javascript
复制
pip3 install virtualenv

创建虚拟环境

代码语言:javascript
复制
virtualenv venv

运行后会提示创建成功和使用的python版本

代码语言:javascript
复制
(base) zhongxin:LightSeeking zhongxin$ virtualenv venv
created virtual environment CPython3.9.1.final.0-64 in 1328ms
  creator CPython3Posix(dest=/Users/zhongxin/gitproject/LightSeeking/venv, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/zhongxin/Library/Application Support/virtualenv)
    added seed packages: pip==22.2.2, setuptools==63.4.1, wheel==0.37.1
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator

进入虚拟环境

  • windows
代码语言:javascript
复制
运行 venv\Scripts\activate
  • Mac,linux 运行命令
代码语言:javascript
复制
source venv/bin/activate

可以看到命令行前面增加了虚拟环境的标识(venv)

代码语言:javascript
复制
(base) zhongxin:LightSeeking zhongxin$ source venv/bin/activate
(venv) (base) zhongxin:LightSeeking zhongxin$

后面默认都是在虚拟环境中进行操作

安装Django

在虚拟环境中运行

代码语言:javascript
复制
pip install django==3.2.11

创建django项目

代码语言:javascript
复制
django-admin startproject LightSeeking

这时候的项目结构如下,因为虽然代码是前后端分离的,但是人只有一个,所以后面会把前后端代码放到一个项目里面,把文件夹名称修改为backend

运行项目

进入项目路径

运行python manage.py runserver

代码语言:javascript
复制
(venv) (base) zhongxin:LightSeeking zhongxin$ cd LightSeeking/
(venv) (base) zhongxin:LightSeeking zhongxin$ python manage.py runserver 
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
August 16, 2022 - 07:31:51
Django version 3.2.11, using settings 'LightSeeking.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

访问http://127.0.0.1:8000/

Pycharm配置项目

注意需要使用Pycharm专业版

选择运行环境

如果pycharm没有自动识别到虚拟环境的话需要手动添加

如果识别到了就不需要操作了

右下角点击解释器设置

在弹出的设置中点击「全部显示」

添加刚刚创建的虚拟环境

添加Django服务器运行配置
点击「修复」设置django路径
进入`偏好设置`后选择`Django项目根`和`设置`文件的路径
再次测试pycharm运行django项目

点击运行后再次访问http://127.0.0.1:8000/

创建前端项目

克隆代码

将代码克隆到根路径的frontend文件夹中

代码语言:javascript
复制
git clone https://gitee.com/lolicode/scui.git frontend

删除前端项目的代码管理

使用ls -al查看全部文件(包含隐藏文件)

删除.git文件夹

代码语言:javascript
复制
(base) (venv) zhongxin:frontend zhongxin$ ls -al
total 80
drwxr-xr-x  16 zhongxin  staff   512  8 16 15:40 .
drwxr-xr-x   6 zhongxin  staff   192  8 16 15:40 ..
-rw-r--r--   1 zhongxin  staff   186  8 16 15:40 .editorconfig
-rw-r--r--   1 zhongxin  staff   258  8 16 15:40 .env.development
-rw-r--r--   1 zhongxin  staff   173  8 16 15:40 .env.production
drwxr-xr-x  12 zhongxin  staff   384  8 16 15:40 .git
drwxr-xr-x   4 zhongxin  staff   128  8 16 15:40 .gitee
-rw-r--r--   1 zhongxin  staff   250  8 16 15:40 .gitignore
-rw-r--r--   1 zhongxin  staff  1063  8 16 15:40 LICENSE
-rw-r--r--   1 zhongxin  staff  2220  8 16 15:40 README.md
-rw-r--r--   1 zhongxin  staff    73  8 16 15:40 babel.config.js
-rw-r--r--   1 zhongxin  staff   230  8 16 15:40 jsconfig.json
-rw-r--r--   1 zhongxin  staff  1498  8 16 15:40 package.json
drwxr-xr-x   8 zhongxin  staff   256  8 16 15:40 public
drwxr-xr-x  17 zhongxin  staff   544  8 16 15:40 src
-rw-r--r--   1 zhongxin  staff  1688  8 16 15:40 vue.config.js
(base) (venv) zhongxin:frontend zhongxin$ rm -rf .git

安装前端环境依赖

需要电脑中已经安装好了node环境

使用淘宝源来加快下载速度

代码语言:javascript
复制
npm i --registry=https://registry.npmmirror.com

运行项目

代码语言:javascript
复制
npm run serve

等待一段时间后

代码语言:javascript
复制
 DONE  Compiled successfully in 199451ms                             下午3:50:54


  App running at:
  - Local:   http://localhost:2800 
  - Network: http://172.28.56.35:2800

  Note that the development build is not optimized.
  To create a production build, run npm run build.

访问http://localhost:2800

使用git管理项目

在项目根路径输入

代码语言:javascript
复制
git init

新建一个.gitignore文件来忽略不需要的文件

代码语言:javascript
复制
/venv/
.idea
/logs/logging.log

.DS_Store
node_modules
/dist

# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Editor directories and files
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

/package-lock.json

提交项目

代码语言:javascript
复制
$ git add .
$ git commit -m "项目创建"

推送项目

在gitee上新建了一个仓库:https://gitee.com/zx660644/light-seeking

将代码推送到gitee上

代码语言:javascript
复制
git remote add origin https://gitee.com/zx660644/light-seeking.git
git push -u origin "master"
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-08-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 测试游记 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 创建Django项目
    • 安装虚拟环境包
      • 创建虚拟环境
        • 进入虚拟环境
          • 安装Django
            • 创建django项目
              • 运行项目
                • Pycharm配置项目
                  • 选择运行环境
                  • 添加Django服务器运行配置
                  • 点击「修复」设置django路径
                  • 进入`偏好设置`后选择`Django项目根`和`设置`文件的路径
                  • 再次测试pycharm运行django项目
              • 创建前端项目
                • 克隆代码
                  • 删除前端项目的代码管理
                    • 安装前端环境依赖
                      • 运行项目
                      • 使用git管理项目
                      领券
                      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档