commit 3f16c2940ce08cc81987030456655921098e3565 Author: sityliu Date: Tue Feb 13 01:39:16 2024 +0800 init Python code ! diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..359bb53 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..1ccec8f --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,15 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f6104af --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..eb070f1 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/python_code.iml b/.idea/python_code.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/python_code.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6acaa92 --- /dev/null +++ b/README.md @@ -0,0 +1,71 @@ +## Python项目结构示例 + + + +### 典型的Python项目的项目结构: + +```py +myproject/ +├── myproject/ +│ ├── __init__.py +│ ├── module1.py +│ ├── module2.py +│ └── ... +├── tests/ +│ ├── __init__.py +│ ├── test_module1.py +│ ├── test_module2.py +│ └── ... +├── docs/ +├── README.md +├── requirements.txt +└── setup.py +``` + +- `myproject/`:项目的根目录,也是Python包的根目录。 +- `myproject/__init__.py`:一个空的`__init__.py`文件,用于将`myproject`目录标记为一个Python包。 +- `myproject/module1.py`、`myproject/module2.py`等:项目的模块文件,包含项目的核心代码。 +- `tests/`:测试目录,包含用于测试项目代码的测试文件。 +- `docs/`:文档目录,包含项目的文档文件。 +- `README.md`:项目的说明文档,通常使用Markdown格式编写。 +- `requirements.txt`:项目的依赖文件,列出了项目所需的所有依赖包及其版本号。 +- `setup.py`:项目的安装文件,用于将项目打包为可安装的Python包。 + +这只是一个基本的项目结构示例,实际项目的结构可能会根据具体需求有所不同。 + + + + + +### 示例:一个典型的flask项目目录结构 + +```py +myflaskproject/ +├── app/ +│ ├── __init__.py +│ ├── models.py +│ ├── views.py +│ ├── templates/ +│ │ ├── base.html +│ │ ├── home.html +│ │ └── ... +│ └── static/ +│ ├── css/ +│ ├── js/ +│ └── ... +├── config.py +├── requirements.txt +├── run.py +└── README.md +``` + +- `app/`:应用程序目录,包含应用程序的核心代码。 +- `app/__init__.py`:应用程序的初始化文件,创建Flask应用对象并配置应用程序。 +- `app/models.py`:应用程序的模型文件,包含数据库模型定义。 +- `app/views.py`:应用程序的视图文件,包含路由和视图函数的定义。 +- `app/templates/`:模板目录,包含应用程序的HTML模板文件。 +- `app/static/`:静态文件目录,包含应用程序的静态资源文件,如CSS、JavaScript等。 +- `config.py`:配置文件,包含应用程序的配置信息。 +- `requirements.txt`:项目的依赖文件,列出了项目所需的所有依赖包及其版本号。 +- `run.py`:应用程序的入口文件,用于启动应用程序。 +- `README.md`:项目的说明文档,通常使用Markdown格式编写。 diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/models.py b/app/models.py new file mode 100644 index 0000000..e69de29 diff --git a/app/resources/__init__.py b/app/resources/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/resources/post.py b/app/resources/post.py new file mode 100644 index 0000000..e69de29 diff --git a/app/resources/user.py b/app/resources/user.py new file mode 100644 index 0000000..e69de29 diff --git a/app/routes.py b/app/routes.py new file mode 100644 index 0000000..e69de29 diff --git a/app/utils.py b/app/utils.py new file mode 100644 index 0000000..e69de29 diff --git a/config.py b/config.py new file mode 100644 index 0000000..8730ec2 --- /dev/null +++ b/config.py @@ -0,0 +1,3 @@ +class Config: + SQLALCHEMY_DATABASE_URI = 'sqlite:///app.db' + SQLALCHEMY_TRACK_MODIFICATIONS = False diff --git a/docs/需求文档.docx b/docs/需求文档.docx new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d7339f7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +-i https://pypi.tuna.tsinghua.edu.cn/simple +Flask +Flask-RESTful \ No newline at end of file diff --git a/run.py b/run.py new file mode 100644 index 0000000..3a43937 --- /dev/null +++ b/run.py @@ -0,0 +1,4 @@ +from app import app + +if __name__ == '__main__': + app.run() diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_post.py b/tests/test_post.py new file mode 100644 index 0000000..a47006b --- /dev/null +++ b/tests/test_post.py @@ -0,0 +1,13 @@ +import unittest +from app import app + +class UserTestCase(unittest.TestCase): + def setUp(self): + self.app = app.test_client() + + def test_get_user(self): + response = self.app.get('/users/1') + data = response.get_json() + self.assertEqual(response.status_code, 200) + self.assertEqual(data['username'], 'john') + self.assertEqual(data['email'], 'john@example.com') diff --git a/tests/test_user.py b/tests/test_user.py new file mode 100644 index 0000000..f301245 --- /dev/null +++ b/tests/test_user.py @@ -0,0 +1 @@ +print("Hello World!")