init Python code !

This commit is contained in:
sityliu 2024-02-13 01:39:16 +08:00
commit 3f16c2940c
21 changed files with 142 additions and 0 deletions

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# 默认忽略的文件
/shelf/
/workspace.xml

View File

@ -0,0 +1,15 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="2">
<item index="0" class="java.lang.String" itemvalue="uiautomator2" />
<item index="1" class="java.lang.String" itemvalue="requests" />
</list>
</value>
</option>
</inspection_tool>
</profile>
</component>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/python_code.iml" filepath="$PROJECT_DIR$/.idea/python_code.iml" />
</modules>
</component>
</project>

8
.idea/python_code.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

71
README.md Normal file
View File

@ -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格式编写。

0
app/__init__.py Normal file
View File

0
app/models.py Normal file
View File

View File

0
app/resources/post.py Normal file
View File

0
app/resources/user.py Normal file
View File

0
app/routes.py Normal file
View File

0
app/utils.py Normal file
View File

3
config.py Normal file
View File

@ -0,0 +1,3 @@
class Config:
SQLALCHEMY_DATABASE_URI = 'sqlite:///app.db'
SQLALCHEMY_TRACK_MODIFICATIONS = False

0
docs/需求文档.docx Normal file
View File

3
requirements.txt Normal file
View File

@ -0,0 +1,3 @@
-i https://pypi.tuna.tsinghua.edu.cn/simple
Flask
Flask-RESTful

4
run.py Normal file
View File

@ -0,0 +1,4 @@
from app import app
if __name__ == '__main__':
app.run()

0
tests/__init__.py Normal file
View File

13
tests/test_post.py Normal file
View File

@ -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')

1
tests/test_user.py Normal file
View File

@ -0,0 +1 @@
print("Hello World!")