Apache interpreting python script as file

Asked

Viewed 124 times

1

I’m building a website and I want it to run a python script in the html action the issue is that my browser is interpreting the script as if it were a.py file to download

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Cadastro</title>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <style>
        .menunav, .navbar-brand{
         color:white;

        }
        body {
        background-color:#e0e0e0;

        }
        #painel{
         width:30%;
        height:30%;
        margin-left:36%;
        margin-top:10%;

        }
    </style>
</head>
<body>
<nav class="navbar navbar-dark bg-primary navbar-fixed-top">
    <div class="container">
        <a class="navbar-brand" href="index.html" >pyagenda</a>
    <ul class="nav navbar-nav">
        <li class="nav-item">
            <a href="index.html" class="menunav">Inicio</a>
        </li>
        <li class="nav-item">
            <a href="entrar.html" class="menunav">Entrar</a>
        </li>
        <li class="nav-item">
            <a href="atualizar.html" class="menunav">Atualizações</a>
        </li>
    </ul>
    </div>
</nav>
<div class="container" id="painel">
<div class="panel panel-primary">
   <div class="panel-heading">
       Cadastro:
   </div>
    <div class="panel-body">
        <form method="POST" action="cgi-bin/cadastrar.py">
            <div class="form-group">
                <label>Usuario:</label>
                <input type="text" class="form-control" maxlength="30" placeholder="Digite seu Usuario" name="usuario">
            </div>
            <div class="form-group">
                <label>Email:</label>
                <input type="email" class="form-control" maxlength="100" placeholder="Digite seu Email" name="email">
            </div>
            <div class="form-group">
                <label>Senha:</label>
                <input type="password" class="form-control" maxlength="10" placeholder="Digite Sua Senha" name="pass">
            </div>
            <div class="form-group">
                <label>Nome:</label>
                <input type="text" class="form-control" maxlength="80" placeholder="Digite Seu Nome" name="nome">
            </div>
            <div class="form-group">
                <button class="btn btn-primary" type="submit">Cadastrar</button>
            </div>
        </form>
    </div>

</div>
    </div>
</body>
</html>

html script

#!/usr/bin/python
import cgi
import mysql.connector
#construtores do form html
cadastro = cgi.FieldStorage()
usu = cadastro.getvalue("usuario")
senha = cadastro.getvalue("pass")
em = cadastro.getvalue("email")
nome = cadastro.getvalue("nome")

#código mysql
conn = mysql.connector.connect(user="root",password="root",host="localhost",database="agenda")
cursor = conn.cursor()

query =  ("""INSERT INTO cadastros
            (usuario,senha,email,nome)
            VALUES (%s,%s,%s,%s)""")
valores = (usu,senha,em,nome)
cursor.execute(query,valores)
conn.commit()
cursor.close()
conn.close()

register.py

I use Ubuntu as operating system

  • 1

    You put the script as CGI?

  • 1

    Apache does not directly interpret any executable file, unless it will use the "CGI port" (it is usually a folder named cgi-bin). You have to configure httpd.conf. Say, you’ve heard of mod_wsgi?

  • 1

    Install the mod_python

  • If you are doing it in windows it is simpler to just set up httpd.conf.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.