Giter VIP home page Giter VIP logo

djangoapp's Introduction

services platforms author
app-service\web,app-service
python
cephalin

Django and PostgreSQL sample for Azure App Service

This samples is a simple Django app that connects to a PostgreSQL database. The sample is used in the tutorial https://learn.microsoft.com/azure/postgresql/flexible-server/tutorial-django-app-service-postgres](Deploy Django app with App Service and Azure Database for PostgreSQL - Flexible Server).

When deployed to Azure App Service, the database connection information is specified via environment variables DBHOST, DBPASS, DBUSER, and DBNAME. This app always uses the default PostgreSQL port. See the tutorials for more information.

Change log

  • 27 Oct 2020: Possible breaking change: removed use of the DJANGO_ENV environment variable to switch between local and production settings. The code instead triggers the selection using the WEBSITE_HOSTNAME environment variable, which is defined when the code is running inside the the Azure App Service container. See manage.py and azuresite/wsgi.py.

  • 12 Oct 2020: BREAKING CHANGE: The DBHOST environment variable is expected to contain only the server name, not the full URL, which is constructed at run time (see azuresite/production.py). Similarly, DBUSER is expected to contain only the user name, not username@servername as before, because using the simpler DBHOST the code can also construct the correct login form at run time (again in azuresite/production.py), avoiding failures that arise when DBUSER lacks the @servername portion.

Contributing

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

djangoapp's People

Contributors

cephalin avatar charris-msft avatar cmcclister avatar georgewallace avatar kraigb avatar microsoftopensource avatar msftgits avatar nosahama avatar pamelafox avatar snehaagrawal-msft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

djangoapp's Issues

Use blob storage and Azure CDN for static assets

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ x] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

It would be helpful to have an example and tutorial of deploying static assets to the Azure storages and CDN.

https://docs.djangoproject.com/en/3.1/howto/static-files/deployment/#serving-static-files-from-a-cloud-service-or-cdn

Minimal steps to reproduce

Any log messages given by the failure

Expected/desired behavior

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

Password contains $ is regarded as escape character in Linux

Please provide us with the following information:

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

  1. Deploy demo into app service with Linux, Python 3.7.7
  2. Set pwd in Application settings. The pwd contains $, like 123$123
  3. SSH to app service and run python manage.py migrate

Any log messages given by the failure

django.db.utils.OperationalError: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
FATAL: password authentication failed for user "xxx"

Expected/desired behavior

Should connect with DB successfully

OS and Version?

PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"

Versions

Mention any other details that might be useful

App itself can connect with db successfully. It seems caused by migrate command. If you try print variable from console, the following character will be escaped too.


Thanks! We'll be in touch soon.

Switch to Using WEBSITE_HOSTNAME Doesn't Align With Microsoft Docs Deploy a Django app Guide

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [x] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

With the adjustment of removing DJANGO_ENV in favor of WEBSITE_HOSTNAME in pull request #18, documentation shown on Microsoft Docs may no longer be correct as it still notes to configure a DJANGO_ENV variable in settings:
https://docs.microsoft.com/en-us/azure/postgresql/flexible-server/tutorial-django-app-service-postgres?tabs=clone

Any log messages given by the failure

Expected/desired behavior

In the Docs, the following command is to be issued in the Azure CLI:
az webapp config appsettings set --settings DJANGO_ENV="production" DBHOST=".postgres.database.azure.com" DBNAME="postgres" DBUSER="" DBPASS=""
This command, however, sets DJANGO_ENV and makes no mention of setting WEBSITE_HOSTNAME

OS and Version?

Any OS

Versions

Mention any other details that might be useful

I'm new to setting up Python/Django into Azure Web Apps, so my apologies if I'm missing something. I'm not sure te exact changes/commands necessary to swap out this configuration change.

DEBUG = False in production.py

Shouldn't the following line be in the production.py file since it is used to deploy to a public environment:
DEBUG = True

Replacing the Postgres db with Azure SQL Server?

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [X] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

I'm looking to connect with the regular Azure SQL Server db instead of the Postgres db, However I'm running into an issue regarding the ODBC connector. In VMs and local I'm able to install the required ODBC connector via the docs that are there which are complete and accurate. Is there a way to deploy the needed tools via the build_and_deploy.yaml template that you have? Or is the ODBC driver simply not available through the app service?

the specificic error is this:

django.db.utils.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 13 for SQL Server' : file not found (0) (SQLDriverConnect)")

But that's obvious given that the App Service never installed the ODBC driver. My question is: where does that step go and where in the deploy.yaml file would it go?

OS and Version?

ubuntu-latest

I'm basically using a clone of the deployment you have. The full code is here, but the deployment is the same.

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

Add Support for Azure in Django Cookiecutter

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ X] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

While this doesn't pertain to this repo exactly, it would be great to add support for Azure in cookiecutter-django. In addition to this example repo, it would be great to see an example / cookiecutter of a production ready django project on Azure.

https://github.com/pydanny/cookiecutter-django

Feel free to close this out, but wanted to raise this as I'm navigating how to deploy a prod django app on Azure.

psycopg-binary is not recommended for production

This repo is referenced in the Microsoft Azure doc, "Build a Python (Django) web app with PostgreSQL in Azure App Service". However, the requirements.txt file in this repo uses pyscopg2-binary which is not the recommended library for production. There is nothing in the doc that suggests that the pyscopg2-binary libary should be avoided for production which can give developers the impression that this is the standard library that should be used.

The problem is that pyscopg2 does not install on Azure App Service for Linux because the container doesn't have the dependency to build pyscopg2. So there is no choice but to use pyscopg2-binary. If there is a walk-through on the Azure docs to deploy a Django app with Postgres then the container that is used for Azure app service should be able to build psycopg2 which is the recommendation for production. I think it is very misleading otherwise.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.