[Python] How can I execute a python flask web app with xampp?

Discussão em 'Python' iniciado por Stack, Fevereiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    I'm developing a web app in python with flask and I don't know how to test my app in xampp apache server. When I go to the xampp dashboard and open the .py file, the browser only shows me the .py code and doesn't execute anything. The .py file hasn't get html code. I want to know how to execute the .py file to see the .html and its funcionality in the browser. This is the code of the .py file:

    #C:\Python27\python.exe -u
    from flask import Flask, render_template, session, request, escape,
    url_for, redirect
    from hashlib import md5
    import MySQLdb, sys, pdb
    import cgi

    app = Flask(__name__)

    # if __name__ == '__main__':
    db = MySQLdb.connect(host="localhost", user="root",
    passwd="root", db="prueba")
    cur = db.cursor()
    app.secret_key = 'mysecretkey'


    class ServerError(Exception):
    pass

    # METODO DE LA PAGINA HOME DE ADMIN


    @app.route('/')
    def home():

    #Si esta la sesion iniciada, cargamos la pagina home con la sesion iniciada

    if 'username' in session:
    username_session = escape(session['username']).capitalize()

    return render_template('home.html',
    session_user_name=username_session, adminIs = True)

    #Si no esta la sesion iniciada, cargamos la pagina home sin la sesion iniciada

    return render_template('home.html')

    app.secret_key='A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'

    if __name__ == '__main__':
    app.run(debug=True)


    This code only shows one function to show the home page .html but I want the browser, when I go to one of the pages, show the .html (with embebed php code) the data I bring from mysql server.

    Continue reading...

Compartilhe esta Página