This commit is contained in:
李渊博
2023-04-11 12:05:10 +08:00
commit 558a8febef
6 changed files with 453 additions and 0 deletions

10
.vscode/preview.yml vendored Normal file
View File

@@ -0,0 +1,10 @@
# .vscode/preview.yml
autoOpen: true # 打开工作空间时是否自动开启所有应用的预览
apps:
- port: 5000 # 应用的端口
run: pip install -i https://mirrors.tencent.com/pypi/simple/ -r ./requirements.txt && bash /usr/bin/start-vnc-session.sh && python ./app.py # 应用的启动命令
root: ./web # 应用的启动目录
name: Python Cloud Studio Demo # 应用名称
description: Python Cloud Studio Demo Project # 应用描述
autoOpen: true # 打开工作空间时是否自动运行命令(优先级高于根级 autoOpen
autoPreview: true # 是否自动打开预览, 若无则默认为true

38
README.md Normal file
View File

@@ -0,0 +1,38 @@
## 欢迎来到 Cloud Studio ##
这是一个展现 Cloud Studio 功能的 Python 示例。
## 自动预览 ##
之所以自动运行了这个应用并打开了预览窗口,是因为有 `.vscode/preview.yml` 文件存在。
该文件的格式说明如下:
```yml
# .vscode/preview.yml
autoOpen: false
apps:
- port: 5000
run: 'pip install -i https://mirrors.tencent.com/pypi/simple/ -r ./requirements.txt && python ./app.py'
root: ./web
name: Python Cloud Studio Demo
description: Python Cloud Studio Demo Project
autoOpen: true
```
### 生成预览配置文件 ###
如果你想生成该文件,可以按下 <kbd>CMD+Shift+P</kbd>,打开命令面板,输入 `preview`,在命令列表中点击 **Preview: Generate Preview Config File**
### 启动预览窗口 ###
有了这个文件后,你可以自己启动预览窗口。按下 <kbd>CMD+Shift+P</kbd>,打开命令面板,输入 `preview`,在命令列表中点击 **Preview: Open Preview Tab**
## 手动开启预览调试 ##
1. 先进入到 `web` 目录,然后在终端直接运行 `pip install -i https://mirrors.tencent.com/pypi/simple/ -r ./requirements.txt && python ./app.py` 启动服务。
2. 完全启动之后,打开命令面板(`Command + Shift + P``Ctrl + Shift + P`) 并输入 `open preview tab`, 回车。
![](./static/img2.png)
3. 输入端口号 `5000`,回车后将自动打开预览窗口。

BIN
static/img2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

14
web/app.py Normal file
View File

@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
from flask import Flask
from flask import render_template
app = Flask(__name__)
@app.route('/')
@app.route('/<name>')
def hello(name=None):
return render_template('index.html', name=name)
if __name__ == '__main__':
app.run(host='0.0.0.0')

1
web/requirements.txt Normal file
View File

@@ -0,0 +1 @@
Flask==2.0.1

390
web/templates/index.html Normal file
View File

@@ -0,0 +1,390 @@
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Python Web Demo | Cloud Studio</title>
<style>
body {
background: #fff;
padding: 0;
margin: 0;
font-family: "PingFang SC", "Helvetica Neue", "Hiragino Sans GB", "Segoe UI", "Microsoft YaHei", , sans-serif;
font-size: 16px;
}
a {
color: #0066FF;
text-decoration: none;
transition: all 0.4s;
}
a:hover {
color: #0047B1;
}
h2 {
font-size: 36px;
font-weight: 500;
}
.container {
width: 100%;
text-align: center;
}
.cover {
width: 100%;
height: 390px;
background: url("https://dn-coding-net-production-pp.qbox.me/8564b26a-9cba-4417-951a-ab0d6f735c77.png") no-repeat bottom;
background-size: 700px;
background-color: #1E1E1E;
color: #fff;
padding-top: 150px;
display: block;
}
.header {
position: absolute;
top: 0;
left: 0;
right: 0;
padding: 30px;
display: flex;
}
.header .nav {
display: flex;
flex: 1;
align-items: center;
list-style-type: none;
list-style-image: none;
margin: 0;
padding: 0;
}
.header .nav li {
padding-left: 30px;
}
.header .nav a {
font-size: 16px;
color: #fff;
text-decoration: none;
}
@media (max-width: 400px) {
.header {
padding: 24px 12px;
}
}
@media (max-width: 350px) {
.header .nav li {
padding-left: 16px;
}
}
#global_footer {
text-align: left;
}
#global_footer .record {
background: #232f40;
color: #76808e;
}
#global_footer .record_img_info img {
position: absolute;
max-width: 353px;
width: 220px;
height: auto;
}
#global_footer .record_info {
text-align: right;
font-size: 12px;
}
#global_footer .record_info p {
margin: 0;
height: 18px;
line-height: 18px;
}
#global_footer .record_info a {
color: #76808e;
text-decoration: none;
}
#global_footer .record_info a:hover {
color: #ddd;
}
#global_footer .record_img_info {
max-width: 1020px;
margin: auto;
padding: 30px 20px;
}
@media (max-width: 840px) {
#global_footer .record_img_info img {
position: relative;
margin-bottom: 20px;
}
#global_footer .record_img_info {
text-align: center;
}
#global_footer .record_info {
text-align: center;
}
}
.cover h1 {
font-size: 60;
margin-top: 0;
margin-bottom: 20px;
}
.dynamic {
width: 100%;
background: #F7FCFF;
padding: 60px 0;
font-weight: 500;
}
.dynamic .version {
color: #0066FF;
}
.cs-campaign {
padding: 80px 0;
}
.cs-campaign h2 {
margin: 0 auto 30px;
}
.cs-campaign a {
background: #fff;
padding: 12px 20px;
border-radius: 2px;
color: #FFF;
background: #0066FF;
border: 1px solid #0066FF;
}
.cs-campaign a.plugin-tutorial {
margin-left: 10px;
color: #0066FF;
background: transparent;
}
.cs-campaign a:hover {
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}
.cs-campaign a.plugin-tutorial:hover {
color: #FFF;
background: #0066FF;
box-shadow: none;
}
.cs-campaign p {
color: #425063;
max-width: 340px;
margin: 0 auto 30px;
}
.full-wide {
width: 100%;
height: 400px;
}
.half-wide {
width: 50%;
height: 400px;
float: left;
color: #fff;
}
.half-wide .content {
width: 520px;
height: 400px;
margin: 0 auto;
}
.half-wide .left {
width: 188px;
float: left;
text-align: left;
}
.half-wide .right {
width: 300px;
float: right;
height: 280px;
}
.half-wide h2 {
margin: 80px 0 40px;
text-align: left;
}
.half-wide a {
background: #fff;
padding: 12px 20px;
border-radius: 2px;
}
.half-wide a:hover {
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}
.coding-intro {
background: #267AF9;
}
.coding-intro a {
color: #267AF9;
}
.coding-intro .right {
background: url("https://dn-coding-net-production-pp.qbox.me/76fe0573-ef14-4670-9459-54186ca90a32.png") no-repeat;
background-size: 300px auto;
margin-top: 54px;
}
.invite-friend {
background: #F7931B;
}
.invite-friend a {
color: #F7931B;
}
.invite-friend .right {
background: url("https://dn-coding-net-production-pp.qbox.me/fa15d556-a008-4f11-8f4a-83d0fd849537.png") no-repeat;
background-size: 300px auto;
margin-top: 30px;
}
@media (min-width: 1600px) {
.half-wide .content {
width: 580px;
}
}
@media (max-width: 1140px) {
.half-wide .content {
width: 490px;
}
}
@media (max-width: 1040px) {
.full-wide {
width: 100%;
height: 800px;
}
.half-wide .content {
width: 580px;
}
.half-wide {
float: none;
width: 100%;
}
}
@media (max-width: 640px) {
.half-wide .content {
width: 490px;
}
}
@media (max-width: 520px) {
.full-wide {
height: auto;
}
.half-wide {
height: auto;
}
.half-wide .content {
height: auto;
width: 100%;
padding: 20px 0;
}
.half-wide .left {
float: none;
width: auto;
text-align: center;
padding: 40px 20px;
}
.invite-friend .left {
padding-bottom: 0;
}
.half-wide h2 {
text-align: center;
margin: 0 auto 40px;
}
.half-wide .right {
float: none;
margin: auto;
}
}
</style>
</head>
<body>
<div class="container">
<div class="cover">
<div class="header">
<img alt="Cloud Studio" height="30px;"
src="https://cs-res.codehub.cn/cloudstudio-home/images/menu/cs-logo.png"
/>
<ul class="nav">
<li>
<!-- <a href="https://help.coding.net/docs/cs/overview.html#pageTitle" target="_blank"
rel="noopener noreferrer">文档</a> -->
</li>
</ul>
</div>
<h1 class="title">欢迎使用 Cloud Studio</h1>
<p class="subtitle">这是一个 Python Web Demo</p>
</div>
<div class="dynamic">
{% if name %}
<h1>Hello {{ name }}!</h1>
{% else %}
<h1>Hello, Cloud Studio!</h1>
{% endif %}
<a href="/world">Say hello to the world</a>
</div>
<div id="global_footer">
<div class="record">
<div class="record_img_info">
<img src="https://dn-coding-net-production-pp.codehub.cn/114dd24b-7ac5-45ce-8af7-3c741a153d05.png"
width="120px">
<div class="record_info">
<p>
<a href="https://dev.tencent.com/privacy" target="_blank" rel="noopener noreferrer">隐私策略</a>
<a href="https://dev.tencent.com/terms" target="_blank" rel="noopener noreferrer">服务条款</a>
<a href="https://dev.tencent.com/security" target="_blank" rel="noopener noreferrer">安全策略</a>
</p>
<p>
Copyright © 2013-2020 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有 | 粤B2-20090059
</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>