在IIS上部署Django 之 Microsoft Azure
来源:互联网 发布:渐飞研究报告行业数据 编辑:程序博客网 时间:2024/05/21 22:53
Django Hello World Web Application
- Creating and configuring an Azure virtual machine to host Django
- Setting up Python and Django
- Setting up IIS with FastCGI
- Creating a new Django application
- Shutting down your Azure virtual machine
- Comments
This tutorial describes how to host a Django-based website on Microsoft Azure using a Windows Server virtual machine. This tutorial assumes you have no prior experience using Azure. Upon completing this guide, you will have a Django-based application up and running in the cloud.
You will learn how to:
- Setup an Azure virtual machine to host Django. While this tutorial explains how to accomplish this under Windows Server, the same could also be done with a Linux VM hosted in Azure.
- Create a new Django application from Windows.
By following this tutorial, you will build a simple Hello World web application. The application will be hosted in an Azure virtual machine.
A screenshot of the completed application is below:
NOTE:
To complete this tutorial, you need an Azure account. You can activate your MSDN subscriber benefits or sign up for a free trial.
Creating and configuring an Azure virtual machine to host Django
Follow the instructions given here to create an Azure virtual machine of the Windows Server 2012 R2 Datacenter distribution.
Instruct Azure to direct port 80 traffic from the web to port 80 on the virtual machine:
- Navigate to your newly created virtual machine in the Azure Portal and click the ENDPOINTS tab.
- Click the ADD button at the bottom of the screen.
- Open up the TCP protocol's PUBLIC PORT 80 as PRIVATE PORT 80.
From the DASHBOARD tab, click CONNECT to use Remote Desktop to remotely log into the newly created Azure virtual machine.
Important Note: all instructions below assume you logged into the virtual machine correctly and are issuing commands there rather than your local machine!
Setting up Python and Django
Note: In order to download using Internet Explorer you may have to configure IE ESC settings (Start/Administrative Tools/Server Manager/Local Server, then click IE Enhanced Security Configuration, set to Off).
- Install Web Platform Installer.
- Install Python and WFastCGI using Web Platform Installer. This will install wfastcgi.py in your Python scripts folder.
- Start Web Platform Installer.
- Type WFastCGI in the search bar.
- Select the WFactCGI entry for the version of Python you wish to use (2.7 or 3.4). Note that this will install Python as a dependency of WFastCGI.
Install Django using pip.
Python 2.7:
c:\python27\scripts\pip install django
Python 3.4:
c:\python34\scripts\pip install django
Setting up IIS with FastCGI
Install IIS with FastCGI support. This may take several minutes to execute.
start /wait %windir%\System32\\PkgMgr.exe /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;IIS-RequestMonitor;IIS-Security;IIS-RequestFiltering;IIS-HttpCompressionStatic;IIS-WebServerManagementTools;IIS-ManagementConsole;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI;IIS-CGI
Python 2.7
Run these commands only if you are using Python 2.7.
Setup the Python Fast CGI Handler.
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCGI "/+[fullPath='c:\Python27\python.exe', arguments='C:\Python27\Scripts\wfastcgi.py']"
Register the handler for this site.
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers "/+[name='Python_via_FastCGI',path='*',verb='*',modules='FastCgiModule',scriptProcessor='c:\Python27\python.exe|C:\Python27\Scripts\wfastcgi.py',resourceType='Unspecified']"
Configure the handler to run your Django application.
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='C:\Python27\python.exe', arguments='C:\Python27\Scripts\wfastcgi.py'].environmentVariables.[name='DJANGO_SETTINGS_MODULE',value='helloworld.settings']" /commit:apphost
Configure PYTHONPATH so your Django app can be found by the Python interpreter.
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='C:\Python27\python.exe', arguments='C:\Python27\Scripts\wfastcgi.py'].environmentVariables.[name='PYTHONPATH',value='C:\inetpub\wwwroot\helloworld']" /commit:apphost
Tell the FastCGI to WSGI gateway which WSGI handler to use.
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='C:\Python27\python.exe', arguments='C:\Python27\Scripts\wfastcgi.py'].environmentVariables.[name='WSGI_HANDLER',value='django.core.handlers.wsgi.WSGIHandler()']" /commit:apphost
You should see the following:
Python 3.4
Run these commands only if you are using Python 3.4.
Setup the Python Fast CGI Handler.
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCGI "/+[fullPath='c:\Python34\python.exe', arguments='C:\Python34\Scripts\wfastcgi.py']"
Register the handler for this site.
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers "/+[name='Python_via_FastCGI',path='*',verb='*',modules='FastCgiModule',scriptProcessor='c:\Python34\python.exe|C:\Python34\Scripts\wfastcgi.py',resourceType='Unspecified']"
Configure the handler to run your Django application.
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='C:\Python34\python.exe', arguments='C:\Python34\Scripts\wfastcgi.py'].environmentVariables.[name='DJANGO_SETTINGS_MODULE',value='helloworld.settings']" /commit:apphost
Configure PYTHONPATH so your Django app can be found by the Python interpreter.
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='C:\Python34\python.exe', arguments='C:\Python34\Scripts\wfastcgi.py'].environmentVariables.[name='PYTHONPATH',value='C:\inetpub\wwwroot\helloworld']" /commit:apphost
Tell the FastCGI to WSGI gateway which WSGI handler to use.
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='C:\Python34\python.exe', arguments='C:\Python34\Scripts\wfastcgi.py'].environmentVariables.[name='WSGI_HANDLER',value='django.core.handlers.wsgi.WSGIHandler()']" /commit:apphost
You should see the following:
Creating a new Django application
From C:\inetpub\wwwroot, enter the following command to create a new Django project:
Python 2.7:
C:\Python27\Scripts\django-admin.exe startproject helloworld
Python 3.4:
C:\Python34\Scripts\django-admin.exe startproject helloworld
The django-admin command generates a basic structure for Django-based websites:
- helloworld\manage.py helps you to start hosting and stop hosting your Django-based website
- helloworld\helloworld\settings.py contains Django settings for your application.
- helloworld\helloworld\urls.py contains the mapping code between each url and its view.
Create a new file named views.py in the C:\inetpub\wwwroot\helloworld\helloworld directory. This will contain the view that renders the "hello world" page. Start your editor and enter the following:
from django.http import HttpResponsedef home(request): html = "<html><body>Hello World!</body></html>" return HttpResponse(html)
Replace the contents of the urls.py file with the following:
from django.conf.urls import patterns, urlurlpatterns = patterns('', url(r'^$', 'helloworld.views.home', name='home'),)
Finally, load the web page in your browser.
Shutting down your Azure virtual machine
When you're done with this tutorial, shutdown and/or remove your newly created Azure virtual machine to free up resources for other tutorials and avoid incurring Azure usage charges.
- 在IIS上部署Django 之 Microsoft Azure
- 在IIS上部署Django 之 实战
- 在iis上部署django时遇到的问题
- 在Microsoft Azure上使用CentOS虚拟机部署Mongo数据库高可用集群
- Microsoft Azure 部署网站
- 在Windows Azure平台上部署服务
- 在Windows Azure平台上部署服务
- 在Windows Azure上部署Linux虚拟机
- 部署在windows azure上的openvpn
- 在Azure上部署squid的教程
- 如何在 Azure 上部署 Kubernetes 集群
- WCF 部署在IIS上
- Django部署在ubuntu上
- 在IIS上部署基于django WEB框架的python网站应用
- 在IIS上部署基于django WEB框架的python网站应用
- 在Windows Azure上使用WAS和IIS托管服务
- Django 现可在 Windows Azure 上使用
- Silverlight在IIS上部署笔记
- 手机号码归属地最新数据库2015年3月(附带采集更新程序)
- 猫猫学IOS(三十二)UI之Quartz2D矩阵操作和图片剪切
- 在mac上编译htk
- http://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.zh-cn.html
- junit单元测试环境配置
- 在IIS上部署Django 之 Microsoft Azure
- 黑马程序员-------------网络编程
- 支持向量机SVM学习
- 创建一个图形的拷贝----(缩小和放大)
- 初识三层
- RHEL6.4 配置本地yum的源
- QT在界面中显示动态图片
- 新建表时创建pojo
- HTML5弹性图片