Python Web Sites With Django - Azure Tutorial



Comments



Description

Python Web Sites with Django - Azure tutorial1 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 Discover more resources for these services: Web Sites (/en-us/documentation/services/web-sites/) Discover more resources: Compute (/en-us/develop/python/compute/) Data Services (/en-us/develop/python/data-services/) App Services (/en-us/develop/python/app-services/) Creating Web Sites with Django This tutorial describes how to get started running Python on Azure Web Sites. Azure Web Sites provide limited free hosting and rapid deployment, and now, you can use Python! As your app grows, you can switch to paid hosting, and you can also integrate with all of the other Azure services. This tutorial shows you how to deploy an application built using the Django web framework. The tutorial walks through the steps of deploying your application and any required libraries, including Django. You will put this all into a Git repository which makes it quick and simple to push updates to your web site. And finally, you will configure the newly created site via Azure so that it runs your Python application. 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. Web Site Creation on Portal The first step in creating your app is to create the web site via the Azure Management Portal. To do this, you will need to login to the portal and click the NEW button in the bottom left corner. A window will appear. Click Quick Create, enter a URL, and select Create Web Site. 23/07/2014 13:34 Azure tutorial http://azure..com/en-us/documentation/articles/web-sites-pyth.Python Web Sites with Django . From the Set up deployment dialog.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. MY ACCOUNT (/EN-US/ACCOUNT/) PORTAL (HTTPS://MANAGE. This can be done by choosing Set up deployment from source control.WINDOWSAZURE..microsoft. Click the right arrow to continue. you will add support for publishing via Git. 23/07/2014 13:34 . scroll down and select the Local Git option. .microsoft. MY ACCOUNT (/EN-US/ACCOUNT/) PORTAL (HTTPS://MANAGE.com/en-us/documentation/articles/web-sites-pyth. When the repo is ready. you will momentarily see a page informing you the repo is being created.Azure tutorial http://azure. you will start filling it in with the web site from your local machine. The deployments tab includes instructions on how to connect..Python Web Sites with Django . you will be taken to the deployments tab.WINDOWSAZURE. The first step is to clone the existing empty site using the url provided: 23/07/2014 13:34 . Web Site Development Now that you have created your Git repository in Azure.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. First.bin.com/en-us/documentation/articles/web-sites-pyth. MY ACCOUNT (/EN-US/ACCOUNT/) PORTAL (HTTPS://MANAGE.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. 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\* . If there are libraries that are not used by your web site. Option 1: To create the new project from the command line. You can do this just as you would create any other Django application from the command line. 2. Include the Django application code. Include the Django library and other libraries that you will be using to run the web site. create a new directory called site-packages.exe -m django.Azure tutorial http://azure.com/) to create the project. run the following command..django-admin startproject DjangoApplication 23/07/2014 13:34 .microsoft. These commands copy all the libraries located in site-packages. or you can use Python Tools for Visual Studio (http://pytools. you are ready to setup the enlistment with the web site. You will need to do a few things: 1.Python Web Sites with Django . To do this.codeplex. include the Django library.WINDOWSAZURE. including Django. The command creates the Django application in the DjangoApplication folder: C:\Python27\python. Both options are shown here.. create your initial Django application. feel free to remove them. Next. The second command will commit the files you just added into the repository. 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.com/en-us/documentation/articles/web-sites-pyth.Python Web Sites with Django . To do this. MY ACCOUNT (/EN-US/ACCOUNT/) PORTAL (HTTPS://MANAGE. Enter DjangoApplication for the name of the project. The third command adds a remote with the name azure for your repository. run these commands: git add DjangoApplication site-packages git commit -m "Initial site" git remote add azure https://dinov@pythonwebsite. drill into the Python projects and select Django Application..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.scm.Azure tutorial http://azure. The final command takes the changes and pushes them to the remote repository.WINDOWSAZURE..git git push azure master The first command will add your untracked files to be tracked. you should see a result similar to this: 23/07/2014 13:34 . Under Other Languages.net/PythonWebSite. 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.microsoft. Start Visual Studio with Python Tools for Visual Studio installed and select File->New Project. Now. This last command will also start the deployment. you just need to add all of the files you have just added and push the site to Git. After doing this.azurewebsites. For example. Add parentheses to indicate that the attribute should be called. you could assign these here and pick them up out of the environment. To do this. All of the settings that are set here will turn into environment variables during the actual request. you need to create three environment variables. you can click on the Configure tab along the top of the screen. Sometimes you will want to set something which is a path to a file in your web site. To set up a Django application.. The first is DJANGO_SETTINGS_MODULE. mypackage. The third is WSGI_HANDLER. your web site will live in D:\home\site\wwwroot. When running as an Azure web site.microsoft.mymodule. you will see the Azure portal refresh and display the active deployment: Web Site Configuration Now you need to configure the web site so that it will know about your Django project and use the wfastcgi handler.com/en-us/documentation/articles/web-sites-pyth. The second is the PYTHONPATH environment variable that specifies the package that the settings module lives in.handler).Azure tutorial http://azure. This means that you can use this to configure the DJANGO_SETTINGS_MODULE environment variable as well as PYTHONPATH and WSGI_HANDLER. and then scroll down to the bottom half of the page which contains the app settings and handler mappings sections. MY ACCOUNT (/EN-US/ACCOUNT/) PORTAL (HTTPS://MANAGE. This variable is a module/package name. which provides the module name of the Django application which will be used for configuration. So for these variables. followed by the attribute in the module to be used (for example. set them up as: 23/07/2014 13:34 . you will want to do this for PYTHONPATH.Python Web Sites with Django .. If your application has other configuration values.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.WINDOWSAZURE. so you can use that in any location where you need a full path to a file on disk. com/) for development. run the command git status to see the newly added files. 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.COM) PYTHONPATH D:\home\site\wwwroot\DjangoApplication.windowsazure. register the handler for all extensions.WSGIHandler() Community Downloads (/en-us/downloads/) Support FREE TRIAL (/en-us/pricing /free-trial/) Now you need to configure your handler mapping.. After you copy the files.microsoft. If you are using Python Tools for Visual Studio (http://pytools.handlers.py script: EXTENSION * SCRIPT PROCESSOR PATH ADDITIONAL ARGUMENTS D:\python27\python. you will likely want to install VisualGit (http://code.com/p/visualgit/) to get source control integration from within Visual Studio. Finally.py as you typically would to start adding new 23/07/2014 13:34 .codeplex. For example. which deploys the updated web site to Azure. you can click the Save button at the bottom. and git add followed by git commit to commit the changes to the repo.com/en-us/develop/python/). Your app may have dependencies beyond Python and Django. Click the link and open your new Django site. you can continue the development of your Django application by using the tools you are already using. For this. you can do a git push.wsgi.settings MY ACCOUNT (/EN-US/ACCOUNT/) PORTAL (HTTPS://MANAGE. Now you can go into the DjangoApplication directory and use manage.Python Web Sites with Django .com/en-us/develop/python/ (http://www.Azure tutorial http://azure.google. which will look like this: Next Steps From here.core.windowsazure.exe D:\python27\scripts\wfastcgi.D:\home\site\wwwroot \site-packages ) WSGI_HANDLER Pricing Documentation (/en-us/documentation/) /en-us/gallery/) 7 of 10 django. go back to the Dashboard. using the path to the Python interpreter and the path to the wfastcgi.com/en-us/documentation/articles/web-sites-pyth. you will already have PIP installed and can use this to quickly add new dependencies. Go down to the SITE URL on the left hand side.WINDOWSAZURE.. to install the Natural Language toolkit and all of its dependencies. Finally.py At this point. DJANGO_SETTINGS_MODULE DjangoApplication. If you installed Python by using the installer at http://www. .microsoft.com/WindowsAzure/azure-content/blob/master/articles/web-sites-python-create-deploy-djangoapp.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 (https://github. MY ACCOUNT PORTAL (HTTPS://MANAGE. 23/07/2014 13:34 .Azure tutorial http://azure.md) using GitHub.. applications to your Django(/EN-US/ACCOUNT/) project.com/en-us/documentation/articles/web-sites-pyth.Python Web Sites with Django .WINDOWSAZURE. but django couldn't find static files..Python Web Sites with Django .db.com/jacalata/op.. sql I've double checked all my settings variables. which is why a generic website was created in this tut..WINDOWSAZURE. • • Sascha Gottfried • Those guys are neither Django nor Pyramid experts. 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.. any suggestions? • Jac Fitzgerald • • After following this tutorial. Now that there is. In case it is. saying they also got a 500 internal server error after following this tutorial.. so hopefully it's not just me. and it looks right.. but it seems like when this was written.com/quest. it says my deployment was successful but I still see nothing but the "it worked" page. MY ACCOUNT (/EN-US/ACCOUNT/) ) PORTAL (HTTPS://MANAGE. 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.com and hire a huge tutorial cleanup. calling django-admin. there wars no Django Application in the gallery.models import signals.. but i'm kind of new on web dev. • • Zevendagenzonderzorgen HELLLLPPPP • 23/07/2014 13:34 .Azure tutorial http://azure. no virtualenv. are all the environment variables still needed? I have an existing Django app on my Mac and when I try to push it. Same situation like 18 months ago. this tutorial is seriously weird to anyone used to develop with Django! No pip mention. Dude.py by direct module?? Please mail anyone at djangoproject.py" in module 5.microsoft. 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. is at https://github. my code so far. from django.. although all auto-generated so not very interesting. Did you notice you can contribute to this article hosted as Markdown on GitHub? Go on! • Kazik117 • • I'm deploy application like in tutorial. 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.COM) FREE TRIAL 19 Comments Pricing Documentation (/en-us/documentation/) /en-us/gallery/) 9 of 10 Community Downloads (/en-us/downloads/) Support Alessandro Lange D'Aquino (/en-us/pricing /free-trial/) • Sorry.com/en-us/documentation/articles/web-sites-pyth.. A lot changed in PTVS since then and the python web frameworks addressed by PTVS as well. • • Jac Fitzgerald • fixed: found a rogue 'sql' entry in my gitignore file that was ignoring the whole relevant folder. azure.com/contactus/?ws=mscom) Trademarks (http://go.microsoft..windowsazure.com Calculator (/en-us/pricing /events/) /profile/) Documentation (/en-us/documentation/) Community Facebook Support (http://go. MY ACCOUNT (/EN-US/ACCOUNT/) PORTAL (HTTPS://MANAGE.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) ) FREE TRIAL Pricing /en-us/gallery/) 10 of 10 Go Social Microsoft Azure (/en-us/) Community Account Features (/en-us/solutions/) (http://go..com) Services (/en-us/services/) /?linkid=394285&clcid=0x409) (/en-us/pricing Subscriptions /free-trial/) Regions (/en-us/regions/) Blogs (/blog/) (https://account.microsoft.com/) /?sdk=net) Forums (/en-us/support/forums/) Gallery (/en-us/gallery/) Service Dashboard Microsoft Azure in China (http://status.com/fwlink/p/?linkid=131004&clcid=0x409) Feedback (http://feedback.com Case Studies (/en-us/case- Service Updates (/en-us/updates/) /subscriptions/) /fwlink/?linkid=306390& studies/) Forums (/en-us/support/forums/) Profile clcid=0x409) Pricing (/en-us/pricing/overview/) Events (/en-us/community (https://account.microsoft.microsoft.com/fwlink (https://account.microsoft.microsoft.cn/zh-cn/) Support (/en-us/support /trust-center/) /options/) Security (/en-us/support/trust- (http://go.microsoft.com) Trust Center (/en-us/support (http://windowsazure. English (http://www.com /fwlink/?linkid=306391& clcid=0x409) Rss Downloads (/en-us/downloads/) /calculator/) Preview Features (/en-us/services Documentation (/en-us /preview/) /documentation/) Support (/en-us/support Management Portal Downloads (/en-us/downloads /options/) (https://manage.WINDOWSAZURE.Python Web Sites with Django .Azure tutorial http://azure.com/) 23/07/2014 13:34 .windowsazure.com /fwlink/?linkid=306393& clcid=0x409) Hello from Seattle.microsoft.azure.microsoft.windowsazure.windowsazure.com) EUR © 2014 Microsoft Contact Us (http://support.com/en-us/documentation/articles/web-sites-pyth.com Twitter (http://go.com/fwlink/p/?linkid=222682&clcid=0x409) Privacy & Cookies (http://go.
Copyright © 2024 DOKUMEN.SITE Inc.