我正在尝试使用此存储库中的 github 操作进行部署: https://github.com/ViniciusDevelopment/test-deployment
这基本上是对 Microsoft 提供的用于测试和学习的标准项目的修改(link azure):
git clone https://github.com/Azure-Samples/msdocs-python-django-webapp-quickstart
公司提供的基地项目表现良好。但是,当添加另一个应用程序并执行提交时,会出现几个错误,从网关到错误 500
日志流没有给我任何相关信息
我尝试了你的代码,做了一些更改,并且能够将其部署到 Azure,没有任何问题。
确保您的
wsgi.py
正确地将 DJANGO_SETTINGS_MODULE 设置为“Quickproject.settings”,并确保您的项目结构一致。确保您的软件包是最新的。
设置.py:
import os
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = '1234567890'
DEBUG = True
APPEND_SLASH = False
ALLOWED_HOSTS = ['*']
INSTALLED_APPS = [
"whitenoise.runserver_nostatic",
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'hello_azure',
'AppPlanEx',
]
MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware',
# Add whitenoise middleware after the security middleware
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'quickstartproject.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'quickstartproject.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
快速启动项目/urls.py:
from django.contrib import admin
from django.urls import include, path
from quickstartproject import settings
from django.conf.urls.static import static
urlpatterns = [
path('', include('hello_azure.urls')),
path('appplanex/', include('AppPlanEx.urls')),
path('ttt/', include('hello_azure.urls')),
path('admin/', admin.site.urls),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
hello_azure/urls.py:
from django.urls import path
from . import views
from quickstartproject import settings
from django.conf.urls.static import static
urlpatterns = [
path('', views.index, name='index'),
path('hello/', views.hello, name='hello'),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
hello_azure/views.py:
from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
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 -- 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:
return redirect('index')
AppPlanEx/urls.py:
from django.urls import path
from . import views
from quickstartproject import settings
from django.conf.urls.static import static
urlpatterns = [
path('', views.Home, name="Home"),
path('appplanex/', views.Home, name="appplanex"),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
这是本地输出:
通过对代码进行上述更改,我能够使用 GitHub 操作成功将应用程序部署到 Azure 应用程序服务。
这是输出: