Это мой код app.py:
from flask import Flask
app = Flask(__name__)
from flask import redirect, render_template as rt, url_for, request, flash
import sqlite3
from sqlite3 import Error
con = sqlite3.connect('database.db')
@app.route('/')
def nullPage():
return redirect('/home/')
@app.route('/home/')
def homePage():
return rt('homePage.html')
@app.route('/home/signup/', methods=["get", "post"])
def signUp():
return rt('signUp.html')
@app.route('/home/login/', methods=["get", "post"])
def logIn():
return rt('logIn.html')
@app.route('/home/logedin/', methods=["get", "post"])
def verLogIn():
if request.method == 'post':
passW = request.form['pass']
email = request.form['email']
try:
sql_table(con)
return "Thanks for loging in!"
except Error:
print(Error)
flash(
"An error has occured when talking to the database. Please try again later! Thank you for understanding.",
category='error')
def sql_table(con):
cursorObj = con.cursor()
cursorObj.execute(
"CREATE TABLE credentials(id integer PRIMARY KEY, email text, passWord text)"
)
con.commit()
return print("Commited")
if __name__ == "__main__":
app.secret_key = 'super secret key'
# app.config['SESSION_TYPE'] = 'filesystem'
# sess.init_app(app)
app.debug = True
app.run()
# print("Bye world")```
Это мой html код, который вызывает код метода POST:
<!-- @format -->
{% extends 'base.html' %} {% block head %}
<div></div>
<link
rel="stylesheet"
href="{{ url_for('static', filename='stylesheets/home.css') }}"
/>
{% endblock %} {% block body %}
<header>
<h1>
Hi, welcome to the WebEmailApp
</h1>
</header>
<section>
<form action="/home/signup/" method="post">
<input type="submit" value="Sign up!" id="signup" />
</form>
<div id="btn-sep"></div>
<form action="/home/login/" method="post">
<input type="submit" value="Log in!" id="login" />
</form>
</section>
{% endblock %}
Это мой html файл, который вызывается:
{% extends 'base.html' %} {% block head %}
<div></div>
<link
rel="stylesheet"
href="{{ url_for('static', filename='stylesheets/login.css') }}"
/>
{% endblock %} {% block body %}
<header>
<h1>Welcome to the log in page!</h1>
<h5>All the field are required!</h5>
</header>
<section>
<form action="/home/logedin/" method="post">
<label for="email">Email: </label>
<input type="email" name="email" id="email" /><br />
<label for="pass">Password: </label>
<input type="password" name="pass" id="pass" /><br />
<input type="submit" value="Log in" />
</form>
</section>
{% endblock %}
Это мой код ошибки:
- - [18/Apr/2020 17:08:02] "POST /home/logedin/ HTTP/1.1" 500 -
Traceback (most recent call last):
File "D:\Coding\EmailWebApp\pyenv\Lib\site-packages\flask\app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "D:\Coding\EmailWebApp\pyenv\Lib\site-packages\flask\app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "D:\Coding\EmailWebApp\pyenv\Lib\site-packages\flask\app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "D:\Coding\EmailWebApp\pyenv\Lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "D:\Coding\EmailWebApp\pyenv\Lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "D:\Coding\EmailWebApp\pyenv\Lib\site-packages\flask\app.py", line 1953, in full_dispatch_request
return self.finalize_request(rv)
File "D:\Coding\EmailWebApp\pyenv\Lib\site-packages\flask\app.py", line 1968, in finalize_request
response = self.make_response(rv)
File "D:\Coding\EmailWebApp\pyenv\Lib\site-packages\flask\app.py", line 2097, in make_response
raise TypeError(
TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.
Я ищу в Интернете эту ошибку, но все говорят, что есть функция без обратной строки, но у меня нет функций, которые ничего не возвращают. Также я подумал, что если я переустановлю python, проблема может исчезнуть go, но это не так. Я также пробовал другие вещи, которые я нашел в какой-то документации онлайн, но проблема все еще здесь. Я попытался переустановить свою IDE, но нет, сообщение об ошибке все еще не исчезло go.
Что я мог сделать?