Azure Fctions与Visual Studio Code结合连接django简单配置

一、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

在这里插入图片描述
在这里插入图片描述
完成!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值