반응형
에러 메시지:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1478, in full_dispatch_request
response = self.make_response(rv)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1566, in make_response
raise ValueError('View function did not return a response')
ValueError: View function did not return a response
그리고 내 코드 :
#Used for starting the flask server
from flask import Flask #Import flask mains
from flask import request #Import flask requests
from flask import render_template #Import flask render templates
import json, urllib #import api modules
import time #Imporing time in darlek voice
app = Flask(__name__)
@app.route('/')
def my_form():
return render_template("my-form.html") #Set render template
@app.route('/', methods=['POST'])
def my_form_post():
openwindow_at = float(request.form['open']) #When it reached ? open window
if request.form['scale'] == "kelvin": #Change figures
print("Do nothing") #Debug info
elif request.form['scale'] == "celcius":
openwindow_at = openwindow_at + int(273.15) #celcius to kelvin
elif request.form['scale'] == "fah": #Fah to kelvin
openwindow_at = (openwindow_at + 459.67) * 5 / 9 #F to kelvin
text = request.form['text'] #Get info from First page
url = "http://api.openweathermap.org/data/2.5/weather?q=" + text #Download the json
response = urllib.urlopen(url) #Download Json
data = json.loads(response.read()) #Parse json
print("Current Weather in " + text + " " + data['weather'][0]['description']) #Debug infomation
print("Temp: " + str(data['main']['temp'])) #Print temp
if data['weather'][0]['description'].find("rain") >= 0: #Check The weather
print("Test")
return "Shutting your window"
Close the window(Tom's job)
if float(data['main']['temp']) >= openwindow_at:
return "Opening your window"
#open the window (Tom's job)
if __name__ == '__main__':
app.debug = True #Uncomment to enable debugging
app.run() #Run the Server
그리고 my-form.html
은 다음과 같습니다.
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Enter a place</h1>
<form action="." method="POST">
<input type="text" name="text">
<input type="submit" name="my-form" value="Send">
<h1>Options</h1>
<p>Open window if temp is greater than<input type="textbox" name="open"></input> <input type="radio" name="scale" value="kelvin">Kelvin</input><input type="radio" name="scale" value="celcius">Celcius</input><input type="radio" name="scale" value="fah">FarenHeit</input></p>
</form>
</body>
</html>
while
루프를 넣으면 영원히로드됩니다.
그런 다음 페이지가 영원히로드되는 현재 온도보다 높은 온도를 입력하십시오. 그리고 위에 나열된 현재 코드를 사용하면 오류가 발생합니다.
해결 방법
다음은 응답을 반환하지 않습니다.
return a function ()
또는 return 'a string'
과 같은 것을 반환해야합니다.
이것은 문제를 해결할 수 있습니다
참조 페이지 https://stackoverflow.com/questions/25034123
반응형
'파이썬' 카테고리의 다른 글
파이썬 화면 출력을 텍스트 파일에 저장하는 방법 (0) | 2020.12.12 |
---|---|
파이썬 Python Regex-일치 항목의 위치와 값을 얻는 방법 (0) | 2020.12.12 |
파이썬에서 배열을 선언하고 채우는 방법은 무엇입니까? (0) | 2020.12.12 |
파이썬 Python 여러 줄 문자열에 대한 적절한 들여 쓰기 (0) | 2020.12.12 |
파이썬 람다 함수를 사용하여 중첩 된 목록에서 합계 찾기 (0) | 2020.12.11 |
댓글