一、host.json文件中,修改为
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
}
}
二、终端中使用net模块下载相关文件
func extensions install --package Microsoft.Azure.WebJobs.Extensions.Storage --version 4.0.2
#F5启动调试没问题后继续以下操作
二、django配置
一、在HttpTrigger1中function.json文件中配置加上
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
],
"route": "HttpTrigger1/{*path_info}" # <- ADD THIS LINE
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
二、HttpTrigger1-> init.py
import azure.functions as func
from djangoprject.wsgi import application
def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
return func.WsgiMiddleware(application).handle(req, context)
三、django下setting配置
第18行:
FUNCTION_APP_PATH = 'api/HttpTrigger1' # <- ADD THIS LINE
第29行:更改ALLOWED_HOSTS为:
ALLOWED_HOSTS = ['*']
第41行:INSTALLED_APPS下添加:
'whitenoise.runserver_nostatic', # <- Add this
第52行:MIDDLEWARE下添加:
'whitenoise.middleware.WhiteNoiseMiddleware', # <- Add this
第123行:更改STATIC_URL:
STATIC_URL = '/' + FUNCTION_APP_PATH + '/static/' # <- Add FUNCTION_APP_PATH here
四、django下url路径
from django.contrib import admin
from django.urls import path,include
from djangoproj.settings import FUNCTION_APP_PATH # <- import our FUNCTION_APP_PATH constant from settings.py file
urlpatterns = [
path(FUNCTION_APP_PATH + '/admin/', admin.site.urls), # <- change "path" to include FUNCITION_APP_PATH
path(FUNCTION_APP_PATH + app路由, include('app名称.urls')), # 其他路径
]
五、错误:ModuleNotFoundError: No module named ‘whitenoise’
pip install whitenoise
#一般会出现ModuleNotFoundError: No module named 'whitenoise’的问题
安装一下whitenoise模块即可
pip install whitenoise
完成!