# messageboard **Repository Path**: miali/messageboard ## Basic Information - **Project Name**: messageboard - **Description**: A Flask entry level WEB application: Users can create a message on the website after entering the content and name. - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-08-10 - **Last Updated**: 2023-09-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Message Board #### 介绍 留言板程序包含留言表单及留言列表两部分。用户在留言板程序中输入姓名以及留言之后选择提交,即可将留言发布到下方的留言列表中。 ![1.png](.md/1.png) ![2.png](.md/2.png) #### 软件架构 ![3.png](.md/3.png) 留言板的核心组件均位于名为 `messageboard` 的程序包中,程序包中的组件和结构以表格的形式列出: | 组件 | 说明 | | -------------------------- | ------------------------------------ | | `messageboard/` | 包名称 | | `messageboard/__init__.py` | 构造文件(实例化 Flask 应用实例) | | `messageboard/models.py` | 定义所有数据库模型 | | `messageboard/forms.py` | 定义所有表单类 | | `messageboard/view.py` | 定义视图函数 | | `messageboard/errors.py` | 定义错误处理函数 | | `messageboard/commands.py` | 自定义的 Flask 命令 | | `messageboard/settings.py` | 配置文件 | | `messageboard/templates` | 模板 | | `messageboard/static` | 存储静态资源(`css/js/favicon.ico`) | #### 安装依赖 本项目中使用 `pipenv` 管理虚拟环境和依赖包,默认情况下 `pipenv` 将统一管理所有虚拟环境。通常情况下,我们会将虚拟环境文件夹创建在项目根目录下,有两种方式可以选择。 **方法一** 在项目根目录下手动创建 `.venv` **方法二** 设置环境变量 `PIPENV_VENV_IN_PROJECT=1 ` `WORKON_HOME=PIPENV_VENV_IN_PROJECT` 接下来就可以运行 `pipenv` 命令创建虚拟环境并安装 `Pipfile` 中的依赖包了: ```powershell pipenv install # pipenv install --dev 将安装包括开发环境在内的依赖包 ``` #### 运行步骤 > 注:一下命令均在项目根目录下运行。 1、查看 `flask` 帮助信息: ```powershell $ pipenv run flask --help Loading .env environment variables... ... Commands: forge Create messages list init-db Initialize the database. routes Show the routes for the app. run Run a development server. shell Run a shell in the app context. ``` 2、运行自定义命令,初始化数据库 `SQLite3`: ```powershell $ pipenv run flask init-db --drop Loading .env environment variables... This operation will delete the database, do you want to continue? [y/N]: y Drop tables ok. Initialized database ok. ``` 3、产生测试数据: ```powershell $ pipenv run flask forge Loading .env environment variables... Create messages record. Create 20 messages OK. ``` 4、启动开发服务器: ```powershell $ pipenv run flask run Loading .env environment variables... * Serving Flask app 'messageboard' * Debug mode: on WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on http://127.0.0.1:5000 Press CTRL+C to quit * Restarting with watchdog (windowsapi) * Debugger is active! * Debugger PIN: 119-462-221 ```