我正在尝试渲染文件home.html.该文件存在于我的项目中,但是jinja2.exceptions.TemplateNotFound: home.html当我尝试渲染它时,我会继续这样做.为什么Flask找不到我的模板?
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
Run Code Online (Sandbox Code Playgroud)
/myproject
app.py
home.html
Run Code Online (Sandbox Code Playgroud) 我已经安装了Python 3.4.0 版,我想用MySQL数据库做一个项目.我下载并尝试安装MySQLdb,但这个版本的Python没有成功.任何建议我如何解决这个问题并正确安装?
我最近下载了Glassfish 4.0,我想在NetBeans中使用它来制作一些Web应用程序,但是当我想启动domain1(asadmin> start-domain domain1)时,我不断收到此错误:"有一个进程已经使用了admin端口4848 - 它可能是GlassFish服务器的另一个实例".有什么线索可能是什么问题?
我想通过在html输入字段中输入他们的名字来为学生的信息制作某种搜索引擎,但我的代码有些麻烦.我虽然使用带有Python的Flask.这是我的project.py代码:
@app.route('/search', methods=['GET', 'POST'])
def search():
if request.method == "POST":
db = MySQLdb.connect(user="root", passwd="", db="cs324", host="127.0.0.1")
c=db.cursor()
c.executemany('''select * from student where name = %s''', request.form['search'])
for r in c.fetchall():
print r[0],r[1],r[2]
return redirect(url_for('search'))
return render_template('search.html')
Run Code Online (Sandbox Code Playgroud)
这是我的search.html代码:
{% extends "hello.html" %}
{% block content %}
<div class="search">
<form action="" method=post>
<input type=text name=search value="{{ request.form.search}}"></br>
<div class="actions"><input type=submit value="Search"></div>
</form>
</div>
{% for message in get_flashed_messages() %}
<div class=flash>
{{ message }}
</div>
{% endfor %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
当我点击搜索按钮时没有任何反应,我检查数据库它有一些数据,所以它不是空的,我找不到我在哪里弄错了,请帮忙?
我有一个 python 代码,需要登录用户,并对输入进行验证,例如检查密码是否正确或用户是否存在,但我不断收到此错误TypeError: 'long' object is not subscriptable ??
这是我的代码:
@app.route('/login', methods=['GET', 'POST'])
def login():
if g.user:
return redirect(url_for('hello'))
error = None
if request.method == 'POST':
db = MySQLdb.connect(user="root", passwd="", db="cs324", host="127.0.0.1")
c=db.cursor()
user = c.execute('''select * from user where
username = %s''', [request.form['username']])
if user is None:
error = ('Wrong username!')
elif not check_password_hash(user['password'],
request.form['password']):
error = ('Wrong password!')
else:
session['user_id'] = user['user_id']
return redirect(url_for('hello'))
return render_template('login.html', error=error)
Run Code Online (Sandbox Code Playgroud)
当检查密码和需要启动会话时,该错误似乎发生在该行。有什么线索我可以解决这个问题吗?
python ×4
mysql ×3
flask ×2
file ×1
glassfish ×1
java ×1
mysql-python ×1
python-3.4 ×1
python-3.x ×1
templates ×1