after deployment internal server error on my web app

Rowdy van Frederikslust 0 Reputation points
2023-03-21T22:11:44.36+00:00

When i develop my django web app everything works fine on my local machine. But when i deploy the web app it gives a server error and on the log streem it doesnt show me anything. How is this possible? How can i figure out what to fix?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,931 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. brtrach-MSFT 17,731 Reputation points Microsoft Employee Moderator
    2023-03-23T01:57:52.5233333+00:00

    There could be several reasons why you are getting an internal server error after deploying your Django web app. One possible reason could be that there is an issue with your database connection. You can check the logs of your web app to see if there are any errors related to the database connection. You can try to add more logging to your code to see if you can get more information about the error.

    Here are the steps to add logging to your Django web app:

    1. Install the django-logging-json package by running the following command in your terminal:
    pip install django-logging-json
    
    
    1. Add the following code to your settings.py file:
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'handlers': {
            'console': {
                'class': 'logging.StreamHandler',
            },
        },
        'loggers': {
            'django': {
                'handlers': ['console'],
                'level': 'DEBUG',
            },
        },
    }
    
    

    This will configure Django to log all messages with a level of DEBUG or higher to the console.

    1. Add the following code to your views.py file:
    import logging
    
    logger = logging.getLogger(__name__)
    
    def my_view(request):
        logger.debug('This is a debug message')
        logger.info('This is an info message')
        logger.warning('This is a warning message')
        logger.error('This is an error message')
        logger.critical('This is a critical message')
        # Your code here
    
    

    This will log messages at different levels to the console when the my_view function is called.

    1. Deploy your web app to Azure and navigate to the "Log stream" tab in the Azure portal to view the logs.

    You should see the log messages that you added to your code in the log stream.

    I hope this helps! Let me know if you have any further questions.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.