Windows Azure Web Sites

New in PTVS 2.0 Alpha

PTVS includes support for quickly deploying your Django application to a Windows Azure Web Site. Windows Azure Web Sites provides shared hosting in the cloud and together with Django you can quickly develop and deploy web sites and enable them to scale when needed. This support is integrated with the new virtual env support which lets you easily configure the packages your web site depends upon.

To follow these steps you’ll first need Python 2.7 with virtualenv installed.

To get started first create a new Django application from within Visual Studio. You can do this by doing File->New Project.

clip_image002

Press OK and you’ll see your newly created project:

clip_image004

The next step is to create a new virtual environment and install Django. Right click on the Virtual Environments node in Solution Explorer and select “Create virtual environment…”.

clip_image005

Currently Windows Azure Web Sites supports Python 2.7, so make sure that the correct base interpreter is selected. Press OK to create the new virtual environment. Next we’ll install Django into the virtual environment. To do this right click on the “env” tree node and select “Install Python Package…” Type “django” for the package name and click OK.

clip_image006

Once Django is successfully installed you’ll see a new node in Solution Explorer below env, you can also see the output from running the installation in the Visual Studio output window.

clip_image007

Now we just need to activate the virtual environment, we can do this by right clicking on the “env” node and selecting “Activate virtual environment…”

clip_image008

At this point you can run your web site locally by pressing F5 and you’ll get the Django “It worked!” page. Next we’ll want to configure Windows Azure so we’ll need to switch to the Windows Azure Portal web site to create a new Windows Azure Web Site. First we’ll click on the “NEW” button in the bottom left hand corner and select “QUICK CREATE” for a “WEB SITE”:

clip_image010

Give your new site a new and click Create. Next you’ll need to configure your new site so that it’s setup to run your Django application. This is currently a limitation in PTVS 2.0 Alpha and the next release will automatically configure your site for you when you publish. But for now click on the CONFIGURE tab at the top scroll down to the “app settings” area, and enter the following settings:

clip_image012

The first two of these settings are boilerplate settings for a Django application. We’ll be using the Django FastCGI handler, and we’ll tell Python to include your web site directory on its path. The 3rd setting needs to specify your Django applications settings module, so if you named your application something other than “MyDjangoApp” you’ll need to use that name here.

Next we need to configure a “handler mapping” to tell the web server how to process Python requests:

clip_image014

Here we are pointing at the python.exe which is part of the deployed virtual environment. This virtual environment includes the Django web framework and any other packages you depend upon and is deployed with your site. By pointing at the virtual env’s python.exe instead of the system-wide python.exe these libraries will also be available to your application. For the arguments we point at the standard wfastcgi.py handler which is available on all Windows Azure Web Sites web servers.

At this point we’re all ready to publish our site to Windows Azure. We just need to download our publish profile and publish from within Visual Studio. To download the publish file go to the “DASHBOARD” tab and along the right hand side you’ll see Download publish profile:

clip_image016

Now switch back to Visual Studio and right click on your project in solution explorer and select Publish:

clip_image017

Then click Import and navigate to the publish profile you just downloaded:

clip_image019

And finally press publish:

clip_image021

Your site will then be uploaded to Windows Azure and a new browser window will open when it completes. In the future as you update your app only the changed files will get updated and pushed to Windows Azure giving you fast and easy deployments.

clip_image022

Last edited Mar 7, 2013 at 11:49 PM by Ptools, version 4

Comments

No comments yet.