
Available tools greatly simplify the development of applications for Windows Azure. The presentation of the material assumes that the user has no experience with Windows Azure. Performing all the steps in this tutorial will allow you to run a Django based application in the cloud.
From this guide, you will learn:
')
- How to create a basic Django application.
- How to run and debug Django applications locally using the Django test server.
- How to run Django applications locally in an emulator environment.
- How to publish and re-publish an application on Windows Azure platform.
By following these instructions, you will create a simple Hello World web application. The application will be placed in an instance of a web role that is hosted in a dedicated virtual machine on the Windows Azure platform.
A screenshot of the finished application is shown below:
Note. To complete the tasks described in this guide, you need a Windows Azure account. You can create a free trial account and activate features for preview only in a few minutes. For more information, see
Create a Windows Azure account and enable features for previewing .
Setting up the development environment
Before you start developing a Windows Azure application, you need to get development tools and set up a development environment. For more information about downloading and installing the Windows Azure SDK for Python, see
How to Install Python .
Note. Python 2.7 and Django 1.4 are required to complete the tasks described in this guide. These versions are included in the current Windows Azure SDK for Python.
Creating a Django Application
To create a Django application, start Visual Studio and create a project. To do this, select the menu item
File (File) -> New Project (New Project) . Click the Python tab located at the top level of the tabs or in the Other Languages area and select the Django Application template:
Click OK . Your first Django application is ready.

Let's turn to the development of the application Django. Right-click the project and select the
Add New Django app item to add a new application to the project:

Now you can specify the name of the application:

Enter a name and click
OK . Application added to the project:

Register the app in
settings.py . After this, Django will automatically detect the template files added to the Templates directory of the application. Add the application name to the INSTALLED_APPS section:
'DjangoApplication.MyFirstApp',
Add a code in the
views.py file that returns a simple template file:
from django.http import HttpResponse from django.template.loader import render_to_string def home(request): return HttpResponse(render_to_string( 'index.html', {'content': 'Hello World'} ))

Create a simple template file that will be displayed by the application when you open this window. Right-click the Templates directory and select
Add new Item :

Select Django HTML Template from the list of templates and specify the name of the
index.html file for it:

After that, the template will be added to the project and opened. You can see that the syntax highlighting of some template tags has begun:

You can continue to update the template by changing the processed HTML code. At the same time, IntelliSense provides a context-sensitive completion of input:

Tag capitalization does not affect the outcome of this task. Now you need to register the view URL templates in
urls.py. Add the following lines to the
urlpatterns template:
url (r '^ $', 'DjangoApplication.MyFirstApp.views.home', name = 'home'),
Local launch of the application on the test server
You have already created your first Django application. Now you can run it locally by simply
pressing the F5 key .

The Python interpreter will launch the Django
manage.py file for the test server. After successfully launching the test server, the website displayed by it will automatically open in the browser. Start using the F5 key through the debugger. This allows you to set breakpoints both in Python code and in template files:

You can now
click the Stop button and proceed to launch the application in the Windows Azure emulator.
Local launch of the application in the emulator
To run the application in the emulator, all you need to do is add the Windows Azure deployment project to the Django project solution. To do this, right-click the Django project node (Django Project) in Solution Explorer and select
Add Windows Azure Cloud Service Project (Add Windows Azure Cloud Service Project) :

After executing this command, the project will be added to the Solution Explorer:

The new project will be marked as being launched draft decision.
Restart Visual Studio as an administrator to run the application in the environment emulator. Now, to launch and deploy the application in the environment emulator, just
press the F5 key :

We see the same webpage, but now it has a different URL. Note: python.exe on the Django test server is not running. Instead, we launched Django via IIS using the FastCGI gateway, which is automatically installed and configured upon launch from Visual Studio.
When working in the emulator, the application can be changed on the fly — just switch to Visual Studio, change the application files, and refresh the page in the browser. Results will be visible immediately!
Deploying the application on Windows Azure platform
Now the project can be deployed on the Windows Azure platform. To do this, right-click on the Windows Azure deployment project (Deploy the project in Windows Azure) in Solution Explorer and select
Publish :

After that, you will be prompted to log in to Windows Azure. You can enter existing credentials or create a new account:

After entering the credentials, the publish settings window will open in Windows Azure. You can change the deployment options or just
click the Publish button :

Installation and deployment of the application may take some time.

After installation is complete, click the link under the DNS name to open the website running in the cloud environment.
Note: the video version of this guide is available on
the YouTube page .