0
index.html
からindex.py
をPython http.serverに変更する方法はありますか?誰かがmysite.comを読み込むと、index.htmlが読み込まれます。しかし、私はindex.pyでcgiスクリプトを実行したいと思います。それを行う方法はありますか?Python3 http.server:index.htmlをindex.pyに変更する
index.html
からindex.py
をPython http.serverに変更する方法はありますか?誰かがmysite.comを読み込むと、index.htmlが読み込まれます。しかし、私はindex.pyでcgiスクリプトを実行したいと思います。それを行う方法はありますか?Python3 http.server:index.htmlをindex.pyに変更する
はあなた.htaccess
でそれを設定します。
RewriteEngine On
AddHandler application/x-httpd-cgi .py
DirectoryIndex index.py
を例index.py
ため:
#!/usr/bin/python
print "Content-type: text/html\n\n"
print "test"
やPythonをテストするためのコマンドを実行するosモジュールを使用します。
import os
from django.shortcuts import render
def command_view(request):
output = os.popen('ls -l').read()
return render(request, 'command.html', {'output': output})
そして、コマンドの結果を<pre>
タグに入力します。
<pre>{{ output }}</pre>