 Hey everyone, welcome to Microsoft Connect. My name is Nina Zakarenko. I'm a senior Cloud Developer Advocate at Microsoft focusing on Python. Today, I'm going to show you how to build productive Python web applications with Visual Studio Code, Azure, and Azure DevOps. Let's get started. I've set up a repository that has all the code and the steps that you need to follow along. Just grab it from the URL git.io slash connectpy. I've already set up my local development environment. I've cloned this repository. I've also set up a virtual environment by running Python 3-mvnvnv and then activating that virtual environment by running source nvbin activate. If I do pip freeze, we'll see that I've already installed all the packages from requirements.txt in this environment. Let's take a look at this project in Visual Studio Code. Code has an amazing and easy shortcut that lets us open up a whole workspace at once. All we need to do is type code dot in the directory. We'll see I have all my files here. If I look here at the bottom, I'll notice something interesting. VS Code has automatically picked up my Python virtual environment. I didn't have to do anything. To get this app running locally, you're going to have to set up a few secrets. The guidelines for that live in the .m-sample file. Here you'll see everything that you need to set up in order to get this app working in production. I've already set up a Postgres database. I've run my migrations on it. I've loaded in a little bit of fixture data. Let's make sure that our app runs locally. To do that, hit control and back tick. To open up the Python terminal, we'll see that VS Code automatically activates the virtual environment for us. We didn't have to do anything. To check out our app locally, we'll need to run Python manage.py run server to bring up the Django web server. And that's kicking off now. Let's take a look. Cool. We'll see we have a local Twitter application. We have our tweets. We can even say a new tweet if we'd like. Hello, Connect. Everything is working as expected. Now, if we run into issues, how do we debug our Django app? Going back to VS Code, let's kill our development server for now. Let's take a look and see what our request looks like by setting a breakpoint. Tap to the left of the line number to create a red breakpoint dot in the gutter. Next, open the debug panel. We'll see that we have no configurations here. All we need to do is click Add Configuration. And VS Code knows that we have a Python project open. It creates a new Python configuration for us. Super easy. If we want to debug our Django, what we need to do now is select the Python Django debug configuration and then hit this green button right here. As our debugger starts, we'll see that the bottom bar has turned orange instead of blue. Now, if we hit our URL again, we'll see that the debugger has stopped at the breakpoint. We have a few options here. We can continue. We can step over. We can step into or step out. But I want to show you one of my favorite features. And that's the debug console. If we click here to the left of the terminal, we'll see this little window pop open. And I have a fully featured debug environment here. I have Auto Complete. If I wanted to take a look at the request, I can just type that in there. I can also interactively work with this object. I can click on the arrow here. I can take a look at the body, any of the content parameters, examine anything that I want to about the request. I can also take a look at our user Bob and check out any attributes about him. I'm going to continue here. That's great. But what about debugging Django templates? Our templates can get really complex and hard to navigate. Thankfully, VS Code provides that too. Let's open up our index.html. We'll see some template code here. All I have to do is click to the left of that. And we'll see that our debugger breakpoint triggered here. I can look at the user in the debug console like I did before. I can also set up watched variables here. So every time a breakpoint stops, these watched variables will populate. I don't have to do anything. I always want to see what user is coming up on my index view. I can set up the user ID or the user in the watch here. Super easy. It makes debugging Python web applications a complete breeze. Now, we've got everything working locally. What if we want to deploy our application to the cloud? Well, thankfully, VS Code has an answer for that too. Check out the extensions tab here on the left-hand side. In order to kick this off, you'll need to install a handful of them, the Python extension, of course, along with Azure account to sign into your Azure account and Azure app service to do the deployment. Once you have these extensions installed, you'll see on the left-hand side here a new icon, the Azure icon. If you click into that, you'll see your app service subscription. All I need to do to set up a new deploy is hit this plus button right here. I need to enter a globally unique name. And I'm going to select an operating system, Linux, along with the Python 3.7 runtime. We'll see in the corner here that the web app is being created. If a resource group isn't found, it'll create one, along with an app service plan. Let's just give this a few minutes to run. Here, I have a pre-existing deployment. What did I need to do to get this going? I needed to configure our application settings. So our production environment needs to know how to connect to this database. You can set these application settings straight from VS Code. If you right-click here, you'll see all the ones that I've set. You can even right-click on an individual setting and hit Edit, Rename, Delete it. Or you can do it from the portal. To easily access the portal component of this application, all we need to do is right-click and hit Open in Portal. And that'll pop open the portal for us and open up the specific app service. Once my deployment is completed, to set up that deployment, I would want to right-click and configure the deployment source. I would want the deployment source to be local Git. All I need to do is right-click again and hit Deploy to Web App. That's it. Just a few clicks, and you have an application running. Let's take a look at my existing app. I right-click and hit Browse Website, and it'll go straight to that URL for me. Here we'll see our Twitter application running in the cloud on azurewebsites.net. This is great for smaller applications, smaller uses. Maybe you're doing a little bit of work in development or QA. What if we wanted to set up a CINCD pipeline for our application? We can do that with Azure DevOps Pipelines. To set those up, go to dev.azure.com. Here I have an existing Azure DevOps project with a few pipelines set up. I have two individual pipelines, one for my continuous integration, one for my continuous deployment. Let's take a look at the continuous integration one. If I edit it here, we'll see that there is a YAML file path, azure-ci-pipeline.yaml. That exists in our Git repository. We can take a quick look at that here. So this YAML file describes everything that we need to do. We're going to be using an Ubuntu image. We're going to be using Python 3.7. We're going to install all of our requirements. And then we're going to run our tests and make sure that those pass before continuing onwards with a deploy. Going back to our pipelines, let's take a look at the continuous deployment pipeline. This is also configured with another YAML file. This one is also in the repository. Right here, the deploy pipeline. We're using Ubuntu again, setting up our Python version, and then setting up a few environment variables, our deployment URL, our deployment username, and a deployment password. We set those up in the portal, going back to our project here, opening it in the portal, going to our deployment center. And grabbing those environment variables from here, we're going to grab this Git clone URL. And then we're also going to make a set of user deployment credentials, setting a username and password that we're then going to configure in our pipeline. Another important thing about this pipeline is the triggers. Here, we'll see that we're disabling continuous integration for our deployment pipeline. But we're depending on the build completion step of our CI task. Having set this up, once I deploy to master, my CI build kicks off. If it goes successfully, I get a deployment super quick, easy, and really understandable. That's all I have to show you today. If you want to learn more about Python on Azure, check out this URL. You can also take a look at the Django on Visual Studio Code tutorial, or take a look at the demo repo. All the steps that you need are right there, all laid out. And I hope you all have an excellent connect. It was great talking to you today. Bye.