简体   繁体   中英

Python Flask, at change app.py Web server not connect

Some client (person) asked me to put jquery on a flask webserver in a Raspberry, honestly the folders of the web app are extrange, I asumme the flask is run automatically as a service each time the Raspberry switch on, the folder tree include the directories and files:

web 
|-WebDev
|  |-templates
|  |   |-index.html
|  |   |-main.html
|  |-static
|  |-__init__.py
|  |-__init__.pyc
|  |-app.py
|  |-app.pyc   
|-run.py

In tutorials I never see this type of flask web structure, I only know that in the app.py is the code that manage the request that index.html and main.html do.

The web site worked well, but I made changes on app.py for manage the ajax request for jquery and the enterely web page stop functioning, the web browser send the message that cannot connect with the site. Well, I test to put again the old code of the app.py copying the same file again, but the web page send the same problem, I dont know what happened, maybe the pyc file is the culprit?, the old pyc file was replaced when the new app.py was compiled. The flask service is running but the page in broswer not connect. How fix this?, What things do each file of the tree?, I really dont know what thing the client do.

run.py

from WebDev.app import service

if __name__ == '__main__':
    service.run(host='0.0.0.0', port=80, debug=True)

init .py

from flask import Flask
from flask_redis import FlaskRedis

service = Flask(__name__)

service.secret_key = 'any random string'

REDIS_URL = "redis://localhost:6379/0"

redis_store = FlaskRedis(service)

app.py

from flask import render_template, request, redirect, url_for, session
from subprocess import call
from hashlib import sha256
from . import service, redis_store
import re
import subprocess

#do stuff for each request

The problem is not the app.py code, maybe some procedure when change the app code that I missed

The thing work again with the old code, simply shutdown the Raspberry and mantains this at least a few minutes, and switch on again. Maybe some sockets or other things blocked or keep hang, I dont know, but with this method after a failed app.py execution, this is the only way that flask web page works again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM