Академический Документы
Профессиональный Документы
Культура Документы
1 of 10
http://azure.microsoft.com/en-us/documentation/articles/web-sites-pyth...
MY ACCOUNT (/EN-US/ACCOUNT/)
PORTAL (HTTPS://MANAGE.WINDOWSAZURE.COM)
(/en-us/)
Features
FREE TRIAL
Pricing
Documentation (/en-us/documentation/)
Gallery (/en-us/gallery/)
Community
Downloads (/en-us/downloads/)
Support
Like
22
(/en-us/pricing
/free-trial/)
Tweet 4
NOTE:
To complete this tutorial, you need an Azure account. You can activate your MSDN subscriber benefits (/en-us
/pricing/member-offers/msdn-benefits-details/) or sign up for a free trial (/en-us/pricing/free-trial/).
This tutorial uses Python 2.7 and Django 1.4. You can either get these on your own, or you can quickly and easily install these
by using the Windows Installer link on http://www.windowsazure.com/en-us/develop/python/ (http://www.windowsazure.com
/en-us/develop/python/).
Note: Azure web sites now come with Python (2.7.3 or 3.4.0, your choice) and wfastcgi handler pre-installed. However, web
frameworks such as Django are not included. You can still use a different Python interpreter if you prefer. You just need to
include it in the Git repository and configure the web site to use that interpreter instead of the Python 2.7 interpreter already
installed.
NOTE:
You can now select the version of Python that you want to use in the Azure Web Sites portal by opening the
Configure tab of your web site and changing the Python Version setting.
You will also need to install a deployment option for pushing the site to Azure. There are various deployment tools available,
but this tutorial uses Git. We recommend msysgit (http://code.google.com/p/msysgit/).
Note: TFS publishing is currently not supported for Python projects.
Once you have Python, Django, and Git installed, you will have everything you need to get started.
23/07/2014 13:34
http://azure.microsoft.com/en-us/documentation/articles/web-sites-pyth...
MY ACCOUNT (/EN-US/ACCOUNT/)
PORTAL (HTTPS://MANAGE.WINDOWSAZURE.COM)
FREE TRIAL
Pricing
Documentation (/en-us/documentation/)
/en-us/gallery/)
2 of 10
Community
Support
Downloads (/en-us/downloads/)
(/en-us/pricing
/free-trial/)
The site will be quickly set up. Next, you will add support for publishing via Git. This can be done by choosing Set up
deployment from source control.
From the Set up deployment dialog, scroll down and select the Local Git option. Click the right arrow to continue.
23/07/2014 13:34
http://azure.microsoft.com/en-us/documentation/articles/web-sites-pyth...
MY ACCOUNT (/EN-US/ACCOUNT/)
PORTAL (HTTPS://MANAGE.WINDOWSAZURE.COM)
FREE TRIAL
Pricing
Documentation (/en-us/documentation/)
/en-us/gallery/)
3 of 10
Community
Downloads (/en-us/downloads/)
Support
(/en-us/pricing
/free-trial/)
After setting up Git publishing, you will momentarily see a page informing you the repo is being created. When the repo is
ready, you will be taken to the deployments tab. The deployments tab includes instructions on how to connect.
23/07/2014 13:34
http://azure.microsoft.com/en-us/documentation/articles/web-sites-pyth...
MY ACCOUNT (/EN-US/ACCOUNT/)
PORTAL (HTTPS://MANAGE.WINDOWSAZURE.COM)
FREE TRIAL
Pricing
Documentation (/en-us/documentation/)
/en-us/gallery/)
4 of 10
Community
Downloads (/en-us/downloads/)
Support
(/en-us/pricing
/free-trial/)
From here, you are ready to setup the enlistment with the web site. You will need to do a few things:
1. Include the Django library and other libraries that you will be using to run the web site.
2. Include the Django application code.
First, include the Django library. To do this, create a new directory called site-packages, and copy your installed version of
Django there by using these commands:
mkdir site-packages
cd site-packages
xcopy /s C:\Python27\lib\site-packages\* .
These commands copy all the libraries located in site-packages, including Django. If there are libraries that are not used by
your web site, feel free to remove them.
Next, create your initial Django application. You can do this just as you would create any other Django application from the
command line, or you can use Python Tools for Visual Studio (http://pytools.codeplex.com/) to create the project. Both
options are shown here.
Option 1: To create the new project from the command line, run the following command. The command creates the Django
application in the DjangoApplication folder:
C:\Python27\python.exe -m django.bin.django-admin startproject DjangoApplication
23/07/2014 13:34
http://azure.microsoft.com/en-us/documentation/articles/web-sites-pyth...
MY ACCOUNT (/EN-US/ACCOUNT/)
PORTAL (HTTPS://MANAGE.WINDOWSAZURE.COM)
FREE TRIAL
Pricing
Documentation (/en-us/documentation/)
/en-us/gallery/)
5 of 10
Community
Downloads (/en-us/downloads/)
Support
(/en-us/pricing
/free-trial/)
Option 2:
You can also create your new site using Python Tools for Visual Studio. Start Visual Studio with Python Tools for Visual Studio
installed and select File->New Project. Under Other Languages, drill into the Python projects and select Django Application.
Enter DjangoApplication for the name of the project, and make sure that Create directory for solution is unchecked to get
the exact same directory structure as when you create a Django application from the command line. This option will set you
up with a Visual Studio solution and project file that give you a great local development experience that includes template
debugging and intellisense.
Now, you just need to add all of the files you have just added and push the site to Git. To do this, run these commands:
git add DjangoApplication site-packages
git commit -m "Initial site"
git remote add azure https://dinov@pythonwebsite.scm.azurewebsites.net/PythonWebSite.git
git push azure master
The first command will add your untracked files to be tracked. The second command will commit the files you just added into
the repository. The third command adds a remote with the name azure for your repository. The final command takes the
changes and pushes them to the remote repository. This last command will also start the deployment. After doing this, you
should see a result similar to this:
23/07/2014 13:34
http://azure.microsoft.com/en-us/documentation/articles/web-sites-pyth...
MY ACCOUNT (/EN-US/ACCOUNT/)
PORTAL (HTTPS://MANAGE.WINDOWSAZURE.COM)
FREE TRIAL
Pricing
Documentation (/en-us/documentation/)
/en-us/gallery/)
6 of 10
Community
Downloads (/en-us/downloads/)
Support
(/en-us/pricing
/free-trial/)
After doing the push, you will see the Azure portal refresh and display the active deployment:
23/07/2014 13:34
http://azure.microsoft.com/en-us/documentation/articles/web-sites-pyth...
DJANGO_SETTINGS_MODULE
DjangoApplication.settings
MY ACCOUNT (/EN-US/ACCOUNT/)
PORTAL (HTTPS://MANAGE.WINDOWSAZURE.COM)
PYTHONPATH
D:\home\site\wwwroot\DjangoApplication;D:\home\site\wwwroot
\site-packages
WSGI_HANDLER
Pricing
Documentation (/en-us/documentation/)
/en-us/gallery/)
7 of 10
django.core.handlers.wsgi.WSGIHandler()
Community
Downloads (/en-us/downloads/)
Support
FREE TRIAL
(/en-us/pricing
/free-trial/)
Now you need to configure your handler mapping. For this, register the handler for all extensions, using the path to the
Python interpreter and the path to the wfastcgi.py script:
EXTENSION
D:\python27\python.exe
D:\python27\scripts\wfastcgi.py
At this point, you can click the Save button at the bottom.
Finally, go back to the Dashboard. Go down to the SITE URL on the left hand side. Click the link and open your new Django
site, which will look like this:
Next Steps
From here, you can continue the development of your Django application by using the tools you are already using. If you are
using Python Tools for Visual Studio (http://pytools.codeplex.com/) for development, you will likely want to install VisualGit
(http://code.google.com/p/visualgit/) to get source control integration from within Visual Studio.
Your app may have dependencies beyond Python and Django. If you installed Python by using the installer at
http://www.windowsazure.com/en-us/develop/python/ (http://www.windowsazure.com/en-us/develop/python/), you will
already have PIP installed and can use this to quickly add new dependencies. For example, to install the Natural Language
toolkit and all of its dependencies, type:
pip install nltk
You then need to update the site-packages directory by copying the files from C:\Python27\Lib\site-packages into your local
site-packages directory.
After you copy the files, run the command git status to see the newly added files, and git add followed by git commit to
commit the changes to the repo. Finally, you can do a git push, which deploys the updated web site to Azure.
Now you can go into the DjangoApplication directory and use manage.py as you typically would to start adding new
23/07/2014 13:34
http://azure.microsoft.com/en-us/documentation/articles/web-sites-pyth...
applications to your
Django(/EN-US/ACCOUNT/)
project.
MY ACCOUNT
PORTAL (HTTPS://MANAGE.WINDOWSAZURE.COM)
FREE TRIAL
Pricing
/en-us/gallery/)
8 of 10
(/en-us/pricing
Community
Support
/free-trial/)
Want to edit or suggest changes to this content? You can edit and submit changes
to this article
Documentation Contribute
(/en-us/documentation/)
to this
Downloads (/en-us/downloads/)
article
23/07/2014 13:34
http://azure.microsoft.com/en-us/documentation/articles/web-sites-pyth...
MY ACCOUNT (/EN-US/ACCOUNT/)
PORTAL (HTTPS://MANAGE.WINDOWSAZURE.COM)
FREE TRIAL
19 Comments
Pricing
Documentation (/en-us/documentation/)
/en-us/gallery/)
9 of 10
Community
Downloads (/en-us/downloads/)
Support
(/en-us/pricing
/free-trial/)
Sorry, but i'm kind of new on web dev. Isn't it necessary to have a web server like apache or nginx?Or
Azure does all that for you?
I'm in doubt if i use VS for a web app development and deployment or a old fashion but powerfull text/code
editor?
alanjds
Not intended to be rude here but... Dude, this tutorial is seriously weird to anyone used to develop with
Django! No pip mention, no virtualenv, calling django-admin.py by direct module?? Please mail anyone at
djangoproject.com and hire a huge tutorial cleanup.
Sascha Gottfried
Those guys are neither Django nor Pyramid experts. Same situation like 18 months ago. A lot
changed in PTVS since then and the python web frameworks addressed by PTVS as well. Did you
notice you can contribute to this article hosted as Markdown on GitHub? Go on!
Kazik117
I'm deploy application like in tutorial, but django couldn't find static files. How to configure settings to serve
with static files?
Sahas Katta
Avatar
Did you end-up finding a solution?
progger
Correct me if i'm wrong, but it seems like when this was written, there wars no Django Application in the
gallery, which is why a generic website was created in this tut. Now that there is, are all the environment
variables still needed? I have an existing Django app on my Mac and when I try to push it, it says my
deployment was successful but I still see nothing but the "it worked" page. any suggestions?
Jac Fitzgerald
After following this tutorial, I saw a 500 internal server error instead of the Django welcome page. Enabling
detailed error logs told me that the error was
Exception Type: ImportError at /
Exception Value: cannot import name sql
File "D:\home\site\wwwroot\site-packages\django\db\models\deletion.py" in module
5. from django.db.models import signals, sql
I've double checked all my settings variables, and it looks right. Any idea what could be wrong? Is the
version of Django in the install kit outdated or something? I saw a comment from one other user at
http://stackoverflow.com/quest... saying they also got a 500 internal server error after following this
tutorial, so hopefully it's not just me. In case it is, my code so far, although all auto-generated so not very
interesting, is at https://github.com/jacalata/op....
Jac Fitzgerald
fixed: found a rogue 'sql' entry in my gitignore file that was ignoring the whole relevant folder.
Zevendagenzonderzorgen
HELLLLPPPP
23/07/2014 13:34
http://azure.microsoft.com/en-us/documentation/articles/web-sites-pyth...
MY ACCOUNT (/EN-US/ACCOUNT/)
PORTAL (HTTPS://MANAGE.WINDOWSAZURE.COM)
FREE TRIAL
Pricing
/en-us/gallery/)
10 of 10
Go Social
Community
Account
Features (/en-us/solutions/)
(http://go.microsoft.com/fwlink
(https://account.windowsazure.com)
Services (/en-us/services/)
/?linkid=394285&clcid=0x409)
(/en-us/pricing
Subscriptions
/free-trial/)
Regions (/en-us/regions/)
Blogs (/blog/)
(https://account.windowsazure.com
/fwlink/?linkid=306390&
studies/)
clcid=0x409)
Pricing (/en-us/pricing/overview/)
Events (/en-us/community
(https://account.windowsazure.com
Calculator (/en-us/pricing
/events/)
/profile/)
Documentation (/en-us/documentation/)
Community
Facebook Support
(http://go.microsoft.com
Twitter
(http://go.microsoft.com
/fwlink/?linkid=306391&
clcid=0x409)
Rss
Downloads (/en-us/downloads/)
/calculator/)
Documentation (/en-us
/preview/)
/documentation/)
Support (/en-us/support
Management Portal
Downloads (/en-us/downloads
/options/)
(https://manage.windowsazure.com/)
/?sdk=net)
Forums (/en-us/support/forums/)
Gallery (/en-us/gallery/)
Service Dashboard
(http://status.azure.com)
(http://windowsazure.cn/zh-cn/)
Support (/en-us/support
/trust-center/)
/options/)
Security (/en-us/support/trust-
(http://go.microsoft.com
center/security/)
/fwlink/?linkid=306392&
Privacy (/en-us/support/trustclcid=0x409)
center/privacy/)
Compliance (/en-us/support/trust-
Newsletter
center/compliance/)
(http://go.microsoft.com
/fwlink/?linkid=306393&
clcid=0x409)
English
(http://www.microsoft.com)
EUR
2014 Microsoft
Contact Us (http://support.microsoft.com/contactus/?ws=mscom)
Trademarks (http://go.microsoft.com/fwlink/p/?linkid=222682&clcid=0x409)
Privacy & Cookies (http://go.microsoft.com/fwlink/p/?linkid=131004&clcid=0x409) Feedback (http://feedback.azure.com/)
23/07/2014 13:34