此命令可能需要花费几分钟时间完成。 运行此命令时,它提供以下相关信息:创建资源组、应用服务计划、应用资源、配置日志记录以及执行 ZIP 部署。 然后,它会显示消息“可以通过 http://<app-name>.chinacloudsites.cn 启动应用”(该网址是 Azure 上应用的 URL)。
The webapp '<app-name>' doesn't exist
Creating Resource group '<group-name>' ...
Resource group creation complete
Creating AppServicePlan '<app-service-plan-name>' ...
Creating webapp '<app-name>' ...
Configuring default logging for the app, if not already enabled
Creating zip with contents of dir /home/cephas/myExpressApp ...
Getting scm site credentials for zip deployment
Starting zip deployment. This operation can take a while to complete ...
Deployment endpoint responded with status code 202
You can launch the app at http://<app-name>.chinacloudsites.cn
{
"URL": "http://<app-name>.chinacloudsites.cn",
"appserviceplan": "<app-service-plan-name>",
"location": "chinaeast",
"name": "<app-name>",
"os": "<os-type>",
"resourcegroup": "<group-name>",
"runtime_version": "python|3.9",
"runtime_version_detected": "0.0",
"sku": "FREE",
"src_path": "<your-folder-location>"
}
# Change these values to the ones used to create the App Service.
RESOURCE_GROUP_NAME='msdocs-python-webapp-quickstart'
APP_SERVICE_NAME='msdocs-python-webapp-quickstart-123'
az webapp deployment source config-local-git \
--name $APP_SERVICE_NAME \
--resource-group $RESOURCE_GROUP_NAME \
--output tsv
# Change these values to the ones used to create the App Service.
$RESOURCE_GROUP_NAME='msdocs-python-webapp-quickstart'
$APP_SERVICE_NAME='msdocs-python-webapp-quickstart-123'
az webapp deployment source config-local-git `
--name $APP_SERVICE_NAME `
--resource-group $RESOURCE_GROUP_NAME `
--output tsv
# Change these values to the ones used to create the App Service.
RESOURCE_GROUP_NAME='msdocs-python-webapp-quickstart'
APP_SERVICE_NAME='msdocs-python-webapp-quickstart-123'
az webapp config appsettings set \
--resource-group $RESOURCE_GROUP_NAME \
--name $APP_SERVICE_NAME \
--settings SCM_DO_BUILD_DURING_DEPLOYMENT=true
# Change these values to the ones used to create the App Service.
$resourceGroupName='msdocs-python-webapp-quickstart'
$appServiceName='msdocs-python-webapp-quickstart-123'
az webapp config appsettings set `
--resource-group $resourceGroupName `
--name $appServiceName `
--settings SCM_DO_BUILD_DURING_DEPLOYMENT=true
创建应用程序的 ZIP 文件
接下来,创建应用程序的 ZIP 文件。 你只需要包括应用程序本身的组件。 不需要包括任何以句点 (.) 开头的文件或目录,例如 .venv、.gitignore、.github 或 .vscode。
# Change these values to the ones used to create the App Service.
RESOURCE_GROUP_NAME='msdocs-python-webapp-quickstart'
APP_SERVICE_NAME='msdocs-python-webapp-quickstart-123'
az webapp deploy \
--name $APP_SERVICE_NAME \
--resource-group $RESOURCE_GROUP_NAME \
--src-path <zip-file-path>
# Change these values to the ones used to create the App Service.
$resourceGroupName='msdocs-python-webapp-quickstart'
$appServiceName='msdocs-python-webapp-quickstart-123'
az webapp deploy `
--name $appServiceName `
--resource-group $resourceGroupName `
--src-path <zip-file-path>
若要使用 Postman 将 ZIP 文件上传到 Azure,需要获取应用服务的部署用户名和密码。 可以从 Azure 门户获取这些凭据。
在 Web 应用的页面上,从页面左侧的菜单中选择“部署中心”。
选择“FTPS 凭据”选项卡。
“用户名”和“密码”显示在“应用程序范围”标题下。 对于 zip 文件部署,请仅使用用户名中 \ 字符后面的、以 $ 开头的部分,例如 $msdocs-python-webapp-quickstart-123。 使用 Postman 上传 zip 文件时需要这些凭据。
在 Postman 中,使用以下步骤上传文件。
说明
屏幕快照
单击加号 (+) 图标以创建新请求。
选择“POST”作为请求类型。
输入 URL https://\<app-name\>.scm.chinacloudsites.cn/api/zipdeploy,其中 <app-name> 是 Web 应用的名称。 此 URL 是用于将 ZIP 文件部署到 Azure 服务的终结点。
@app.route('/')
def index():
print('Request for index page received')
return render_template('index.html')
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'),
'favicon.ico', mimetype='image/vnd.microsoft.icon')
@app.route('/hello', methods=['POST'])
def hello():
name = request.form.get('name')
if name:
print('Request for hello page received with name=%s' % name)
return render_template('hello.html', name = name)
else:
print('Request for hello page received with no name or blank name -- redirecting')
return redirect(url_for('index'))
def index(request):
print('Request for index page received')
return render(request, 'hello_azure/index.html')
@csrf_exempt
def hello(request):
if request.method == 'POST':
name = request.POST.get('name')
if name is None or name == '':
print("Request for hello page received with no name or blank name -- redirecting")
return redirect('index')
else:
print("Request for hello page received with name=%s" % name)
context = {'name': name }
return render(request, 'hello_azure/hello.html', context)
else:
@app.get("/", response_class=HTMLResponse)
async def index(request: Request):
print('Request for index page received')
return templates.TemplateResponse('index.html', {"request": request})
@app.get('/favicon.ico')
async def favicon():
file_name = 'favicon.ico'
file_path = './static/' + file_name
return FileResponse(path=file_path, headers={'mimetype': 'image/vnd.microsoft.icon'})
@app.post('/hello', response_class=HTMLResponse)
async def hello(request: Request, name: str = Form(...)):
if name:
print('Request for hello page received with name=%s' % name)
return templates.TemplateResponse('hello.html', {"request": request, 'name':name})
else:
print('Request for hello page received with no name or blank name -- redirecting')
return RedirectResponse(request.url_for("index"), status_code=status.HTTP_302_FOUND)