Windows Azure Web Sites

New in PTVS 2.0

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.


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


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…”.


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.


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.


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…”


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”:


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:


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:


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 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:


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


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


And finally press publish:


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.


Last edited Oct 17, 2014 at 5:49 PM by RickWinter, version 5


hedson May 3, 2014 at 2:10 AM 
Yes, that was my problem; figured it out shortly after posting. Thanks for the speedy reply!

pminaev May 2, 2014 at 11:35 PM 
If the newly created environment is the first one in your project (i.e. you didn't have another virtual env, and you did not have any interpreter listed under "Python Environments"), then it will be automatically activated, and an active environment will have that option disabled. The active environment is also displayed in bold, so check for that.

If the environment is not active and yet cannot be activated, or if it's active but not bolded in Solution Explorer, please file a bug in the tracker.

hedson May 2, 2014 at 10:55 PM 
I am unable to activate my virtual environment (created using "Python Envionments..Create Virtual Environment"). It appears within my project under "Python Environments" (not Virtual Environments as shown in the screen shots). The right-click menu includes an option to Activate Environment, but that option is disabled. What might I be missing?