Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
django中的azure web应用部署不工作_Django_Azure Sql Database_Azure Web App Service - Fatal编程技术网

django中的azure web应用部署不工作

django中的azure web应用部署不工作,django,azure-sql-database,azure-web-app-service,Django,Azure Sql Database,Azure Web App Service,当我使用sql数据库在azure中部署django应用程序时,它向我显示页面无法显示,因为发生了内部服务器错误 但当我在没有sql数据库的情况下部署它时,它工作得很好。有什么问题 错误日志 最可能的原因: IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which m

当我使用sql数据库在azure中部署django应用程序时,它向我显示页面无法显示,因为发生了内部服务器错误

但当我在没有sql数据库的情况下部署它时,它工作得很好。有什么问题

错误日志

最可能的原因:

IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
IIS was not able to process configuration for the Web site or application.
The authenticated user does not have permission to use this DLL.
The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.

请启用以调试应用程序,并确定应用程序不工作的真正原因。博客文章还可以帮助您排除记录应用程序的故障。

我试图重现您的问题,但失败了。我通过使用成功地将django应用程序部署到带有sqlserver数据库的azure

请参考我所做的步骤:

步骤1:在settings.py中添加配置

DATABASES = {
    'default': {
        'NAME': '***',
        'ENGINE': 'sql_server.pyodbc',
        'HOST': '***.database.windows.net',
        'USER': '***',
        'PASSWORD': '***',
        'OPTIONS': {
            'driver': 'ODBC Driver 13 for SQL Server',
        }
    }
}
步骤2:将测试代码添加到查询结果中:

from django.db import connection

def my_custom_sql():
    with connection.cursor() as cursor:
        cursor.execute("SELECT * FROM ***")
        row = cursor.fetchone()
    return row
步骤3:在KUDU上安装django mssql包和依赖项

步骤4:将django应用程序部署到azure并访问浏览器中的url

希望对你有帮助

更新答案:

首先,当您尝试使用django mssql构建django时,出现如下错误,因为您的django版本太高

从中,您可以看到:当前版本支持Django 1.8,您的Django版本是1.11.8

其次,您在评论中提到的django pyodbc包只支持django 1.10。你可以参考这个

所以,我建议您现在使用支持django 1.11的包

您可以按照上面文档中的教程进行操作

settings.py中的配置

DATABASES = {
    'default': {
        'NAME': '***',
        'ENGINE': 'sql_server.pyodbc',
        'HOST': '***.database.windows.net',
        'USER': '***',
        'PASSWORD': '***',
        'OPTIONS': {
            'driver': 'ODBC Driver 13 for SQL Server',
        }
    }
}
我的django版本和你的一样,它对我很有用

有什么问题请告诉我

更新答案2:

我刚刚使用了Visual Studio 2017 python django模板

My view.py:

请注意my_custom_sql函数

My about.html:


而settings.py中的pyodbc设置只是参考我以前的更新答案。

请检查Kudu上的跟踪日志,然后将其发布到这里好吗?此外您正在使用的django版本是什么?谢谢您的帮助,但是引擎在我的机器上不工作,而且在我的机器上也不工作azure@Robel您遵循了我的步骤,然后出现了您在帖子中提到的错误?当我使用sqlserver\u ado引擎时,它向我显示了这个错误self.client=self.client\u classself-TypeError:“NoneType”对象不是可调用,但使用sql_server.pyodbc,它在我的计算机中工作,而不是在azure@Robel啊,我也遇到了错误:TypeError:“NoneType”对象不可调用。原因是django版本太高或django mssql的依赖包丢失。文件D:\home\site\wwwroot\env\Lib\site packages\django\apps\registry.py,第78行,in populate raise RuntimeErrorpopulate不可重入运行时错误:populate不可重入2018-01-23 13:33:40.095000:wfastcgi.py 2.1.1关闭
"""
Definition of views.
"""

from django.shortcuts import render
from django.http import HttpRequest
from django.template import RequestContext
from datetime import datetime
from django.db import connection

def my_custom_sql():
    with connection.cursor() as cursor:
        cursor.execute("SELECT * FROM dbo.student")
        row = cursor.fetchone()
    return row

def home(request):
    """Renders the home page."""
    assert isinstance(request, HttpRequest)
    return render(
        request,
        'app/index.html',
        {
            'title':'Home Page',
            'year':datetime.now().year,
        }
    )

def contact(request):
    """Renders the contact page."""
    assert isinstance(request, HttpRequest)
    return render(
        request,
        'app/contact.html',
        {
            'title':'Contact',
            'message':'Your contact page.',
            'year':datetime.now().year,
        }
    )

def about(request):
    row = my_custom_sql()
    """Renders the about page."""
    assert isinstance(request, HttpRequest)
    return render(
        request,
        'app/about.html',
        {
            'title': row,
            'message':'Your application description page.',
            'year':datetime.now().year,
        }
    )
{% extends "app/layout.html" %}

{% block content %}

<h2>{{ title }}.</h2>
<h3>{{ message }}</h3>

<p>Test Something!</p>

{% endblock %}