Reputation: 37
When I deploy my django app in azure with sql database, it is showing me The page cannot be displayed because an internal server error has occurred
.
But when I deploy it without sql database it works fine. What is the problem?
error log
Most likely causes:
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.
Upvotes: 0
Views: 1682
Reputation: 23792
I tried to reproduce your issue but failed. I deploy my django app to azure with sqlserver database by using django-mssql successfully.
Please refer to the steps I did:
Step 1: Add configuration in settings.py
DATABASES = {
'default': {
'NAME': '***',
'ENGINE': 'sqlserver_ado',
'HOST': '***.database.windows.net',
'USER': '***',
'PASSWORD': '***',
'OPTIONS': {
'provider': 'SQLOLEDB',
'use_legacy_date_fields': 'True'
}
}
}
Step 2: Add test code to query results:
from django.db import connection
def my_custom_sql():
with connection.cursor() as cursor:
cursor.execute("SELECT * FROM ***")
row = cursor.fetchone()
return row
Step 3: Install django-mssql
package and dependency on KUDU.
Step 4: Deploy django app to azure and access url in browser.
Hope it helps you.
Update Answer:
Firstly , the error as below when you tried to build django with django-mssql because your version of django is too high.
From the django-mssql doc , you could see : Django 1.8 is supported by the current release
and your django version is 1.11.8
.
Secondly, the django-pyodbc
package which you mentioned in your comment just supports django 1.10
. You could refer to this doc.
So, I suggest you to use django-pyodbc-azure package which supports django 1.11
by now.
You could follow the tutorial in above doc.
Configuration in settings.py
DATABASES = {
'default': {
'NAME': '***',
'ENGINE': 'sql_server.pyodbc',
'HOST': '***.database.windows.net',
'USER': '***',
'PASSWORD': '***',
'OPTIONS': {
'driver': 'ODBC Driver 13 for SQL Server',
}
}
}
My django version is as same as you and it works for me.
Any concern please let me know.
Update Answer2 :
I just used Visual Studio 2017 python django template.
My view.py :
"""
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,
}
)
Please note the my_custom_sql()
function.
My about.html:
{% extends "app/layout.html" %}
{% block content %}
<h2>{{ title }}.</h2>
<h3>{{ message }}</h3>
<p>Test Something!</p>
{% endblock %}
And the pyodbc
settings in the settings.py
just refer to my previous update answer.
Upvotes: 1
Reputation: 15694
Please enable Diagnostics Logging for debugging your application and determine the real cause of your application is not working. This blog post may also help you troubleshooting-logging your application.
Upvotes: 0