此命令可能需要數分鐘才能完成。 此命令執行時會提供相關訊息,包括建立資源群組、App Service 方案和應用程式資源、設定記錄,以及執行 ZIP 部署。 接著會提供「您可以在 http://<app-name>.azurewebsites.net 啟動應用程式」的訊息,這是 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>.azurewebsites.net
{
"URL": "http://<app-name>.azurewebsites.net",
"appserviceplan": "<app-service-plan-name>",
"location": "centralus",
"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>
若要使用 cURL 將 ZIP 檔案上傳到 Azure,您需要 App Service 的部署使用者名稱和密碼。 這些認證可以在 Azure 入口網站取得。
App Service 會根據部署中存在的特定檔案,自動偵測應用程式是 Django 或 Flask 應用程式,然後執行預設步驟來執行您的應用程式。 針對以其他 Web 架構為基礎的應用程式,如 FastAPI,您必須設定 App Service 的啟動指令碼來執行您的應用程式;否則,App Service 會執行位於 opt/defaultsite 資料夾中的預設唯讀應用程式。
@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)
您可以使用 Azure CLI、VS Code 或 Azure 入口網站來檢閱 App Service 診斷記錄的內容。