Jump to content

[Python] Criar E Executar Teste Simples (Cgi)


Sadness
 Share

Recommended Posts

1- Criar diretório "cgi-local" na nossa hospedagem

Exemplo (public_html):

/home/LOGIN_FTP/public_html/cgi-local

 

2- Acessar o diretório

cd public_html

3- Criar o diretório cgi-local

mkdir cgi-local

4- Acessar o cgi-local:

cd cgi-local

5- Criar o arquivo testetlthings.py:

vi testetlthings.py

6- Colar o seguinte código:

#!/usr/bin/pythonprint 'Content-type: text/html'printprint '<html><head>'print '<title>Teste TMoore Tutorials (Python CGI)</title>'print '</head><body>'print '<h1>Teste Locaweb</h1>'print 'Python via CGI funcional.'print '</body></html>'

7- Guardar e sair do arquivo da seguinte forma

<Esc> :wq! <Enter>

8- Dar permissões ao arquivo/diretório

chmod 755 -R ~/public_html/cgi-local

9- Testar o acesso através do navegador:

http://oteudominio.com.pt/cgi-local/testetlthings.py

Atenção:

Por vezes dá o seguinte erro

i2l6m4h8qn4wisqqnib.png

 

Caso dê o erro anterior terão de executar o seguinte script

-bash-4.1$ python testetlthings.py

Deste modo serão informados da linha onde está o erro, neste caso ao executar o script através do interpretador não irá haver problemas

-bash-4.1$ python testetlthings.pyContent-type: text/html<html><head><title>Teste TMoore Tutorials (Python CGI)</title></head><body><h1>Teste Locaweb</h1>Python via CGI funcional.</body></html>

Finalmente, testamos novamente se desta vez funcionou:

http://oteudominio.com.pt/cgi-local/testetlthings.py

O resultado deverá ser algo do género

 

4i89hjvjktr59jzs0q2.png

Cumprimentos,

Sadness.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...