AzureでPythonでDjangoでHelloWorldしたメモ

おじさんはVisualStudio2005まででこの14年間止まってた人なので、色々疲れた。

 

久々にマイクロソフトのサポートを使った。pythonでHelloWorldのやり方教えろとかいうサポート依頼、しかも電話希望。対応するの嫌だっただろうなw。

お疲れ様でした>>マイクロソフトの中の人様。

 

メモなんで心眼でよろ。VisualStudio2017、Djangoプロジェクト前提。

 

views.pyに追記:

def hello(request):
assert isinstance(request, HttpRequest)
s = 'HelloWorld … IT WORKED! YES!YES! '
return render(
request,
'app/hello.html',
{
'title':'Hello',
'message':'FirstHelloWorld.',
'hello':s
}
)

 

hello.htmlを{{hello}}を入れて適当に書く。titleとかmessageとか知らん。

 

urls.pyに追記:

url(r'^hello$', app.views.hello, name='hello'),

 

web.config@AzureWebServices:

<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="PYTHONPATH" value="D:\home\site\wwwroot" />
<add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
<add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log" />
<add key="DJANGO_SETTINGS_MODULE" value="お前のプロジェクト名.settings" />
</appSettings>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add name="Python CSS" path="*.css" verb="GET" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
<remove name="Python27_via_FastCGI" />
<remove name="Python34_via_FastCGI" />
<add name="PythonHandler" path="*" verb="*" modules="FastCgiModule"
scriptProcessor="D:\home\Python364x64\python.exe|D:\home\Python364x64\wfastcgi.py"
resourceType="Unspecified" requireAccess="Script"/>
</handlers>
<rewrite>
<rules>
<rule name="Static Files" stopProcessing="true">
<conditions>
<add input="true" pattern="false" />
</conditions>
</rule>
<rule name="Configure Python" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
<system.web>
<customErrors mode="Off" />
</system.web>
</configuration>

 

もしかしたらstatic/web.configに

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<remove name="Python FastCGI" />
</handlers>
</system.webServer>
</configuration>

 

static/app/content/bootstrap.min.cssを読めなくて嵌った。<add name="Python CSS" path="*.css" verb="GET" modules="StaticFileModule" resourceType="File" requireAccess="Read" />の部分。神はこちら⇣。ありがとう。ありがとう。

Django + IIS + wfastcgiで静的ファイル(CSS, JavaScriptなど)を配信する - メモ的な思考的な