init Python code !
This commit is contained in:
commit
3f16c2940c
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
15
.idea/inspectionProfiles/Project_Default.xml
Normal file
15
.idea/inspectionProfiles/Project_Default.xml
Normal 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>
|
||||
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal 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
7
.idea/misc.xml
Normal 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
8
.idea/modules.xml
Normal 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
8
.idea/python_code.iml
Normal 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
71
README.md
Normal 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
0
app/__init__.py
Normal file
0
app/models.py
Normal file
0
app/models.py
Normal file
0
app/resources/__init__.py
Normal file
0
app/resources/__init__.py
Normal file
0
app/resources/post.py
Normal file
0
app/resources/post.py
Normal file
0
app/resources/user.py
Normal file
0
app/resources/user.py
Normal file
0
app/routes.py
Normal file
0
app/routes.py
Normal file
0
app/utils.py
Normal file
0
app/utils.py
Normal file
3
config.py
Normal file
3
config.py
Normal file
@ -0,0 +1,3 @@
|
||||
class Config:
|
||||
SQLALCHEMY_DATABASE_URI = 'sqlite:///app.db'
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
0
docs/需求文档.docx
Normal file
0
docs/需求文档.docx
Normal file
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
-i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
Flask
|
||||
Flask-RESTful
|
||||
4
run.py
Normal file
4
run.py
Normal file
@ -0,0 +1,4 @@
|
||||
from app import app
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
13
tests/test_post.py
Normal file
13
tests/test_post.py
Normal 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
1
tests/test_user.py
Normal file
@ -0,0 +1 @@
|
||||
print("Hello World!")
|
||||
Loading…
Reference in New Issue
Block a user