Sirius3 hat geschrieben:@peddy: zeig Deinen ganzen Code hier, sonst raten wir ewig.
Nichts lieber als das.
Ich habe noch mal die Doku von Flask gewälzt und habe das gefunden.
Code: Alles auswählen
a = request.args.get('a', 0, type=int)
b = request.args.get('b', 0, type=int)
Note that we are using the get() method here which will never fail. If the key is missing a default value (here 0) is returned. Furthermore it can convert values to a specific type (like in our case int). This is especially handy for code that is triggered by a script (APIs, JavaScript etc.) because you don’t need special error reporting in that case.
Hier ist die App:
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# _____ _ _
# | |___ _| |_ _| |___ ___
# | | | | . | . | | | | -_|_ -|
# |_|_|_|___|___|___|_|___|___|
#
import os
import sqlite3
from flask import Flask, request, g, render_template
# _____ _ _ _
# | __|___| |_| |_|_|___ ___ ___
# |__ | -_| _| _| | | . |_ -|
# |_____|___|_| |_| |_|_|_|_ |___|
# |___|
app = Flask(__name__)
app.config.from_object(__name__)
app.config.update(dict(
DATABASE=os.path.join(app.root_path, 'wbt.db'),
DEBUG=True,
SECRET_KEY='development key',
USERNAME='admin',
PASSWORD='default'
))
app.config.from_envvar('FLASKR_SETTINGS', silent=True)
# ____ _ _
# | \ ___| |_ ___| |_ ___ ___ ___
# | | | .'| _| .'| . | .'|_ -| -_|
# |____/|__,|_| |__,|___|__,|___|___|
#
def connect_db():
rv = sqlite3.connect(app.config['DATABASE'])
rv.row_factory = sqlite3.Row
return rv
def get_db():
if not hasattr(g, 'sqlite_db'):
g.sqlite_db = connect_db()
return g.sqlite_db
@app.teardown_appcontext
def close_db(error):
if hasattr(g, 'sqlite_db'):
g.sqlite_db.close()
# _____ _
# | __ |___ _ _| |_ ___ ___
# | -| . | | | _| -_|_ -|
# |__|__|___|___|_| |___|___|
#
# Index
# -----
@app.route('/')
def index():
return render_template('layout.html')
# Training
# --------
@app.route('/training', methods=['GET', 'POST'])
def show_training():
if request.method == 'GET':
db = get_db()
cur = db.execute("select * from trainings where id=:t_id", {'t_id': request.args['id']})
training = cur.fetchone()
#pic_suffix = 'trainings/' + training[2] + '/Folie' + request.args['page'] + '.PNG'
#next_url = '&id=' + request.args['id'] +'&page=' + request.args['page'] +'&user=' + request.args['user']
#q_user = request.args['user']
#q_id = request.args['id']
q_page = request.args.get('page', 0, type=int)
return q_page
#return render_template('show_training.html',
# training = training,
# pic_suffix = pic_suffix,
# next_url = next_url
#)
elif request.method == 'POST':
pass
# Users
# -----
@app.route('/users')
def show_users():
db = get_db()
cur = db.execute("select * from users order by name, first_name asc")
entries = cur.fetchall()
return render_template('show_users.html', entries=entries)
# User Startpage
# --------------
@app.route('/user/<hash_value>')
def user_startpage(hash_value):
db = get_db()
cur = db.execute("""select t.name, ut.completed
from users as u
join users_trainings as ut on u.ID = ut.U_ID
join trainings as t on ut.T_ID = t.ID
where u.hash='{}'""".format(hash_value))
trainings = cur.fetchall()
cur = db.execute("select first_name, name from users where hash='{}'".format(hash_value))
user_name = cur.fetchone()
return render_template('show_user_trainings.html', trainings=trainings, user_name=user_name)
# _____ _
# | |___|_|___
# | | | | .'| | |
# |_|_|_|__,|_|_|_|
#
if __name__ == '__main__':
app.debug = True
app.run()
TypeError
TypeError: 'int' object is not callable
Traceback (most recent call last)
File "/Users/patrick/Coding/wbt/venv/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/patrick/Coding/wbt/venv/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/patrick/Coding/wbt/venv/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/patrick/Coding/wbt/venv/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/Users/patrick/Coding/wbt/venv/lib/python2.7/site-packages/flask/app.py", line 1478, in full_dispatch_request
response = self.make_response(rv)
File "/Users/patrick/Coding/wbt/venv/lib/python2.7/site-packages/flask/app.py", line 1577, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "/Users/patrick/Coding/wbt/venv/lib/python2.7/site-packages/werkzeug/wrappers.py", line 827, in force_type
response = BaseResponse(*_run_wsgi_app(response, environ))
File "/Users/patrick/Coding/wbt/venv/lib/python2.7/site-packages/werkzeug/test.py", line 855, in run_wsgi_app
app_iter = app(environ, start_response)
TypeError: 'int' object is not callable
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.
You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:
dump() shows all variables in the frame
dump(obj) dumps all that's known about the object
Brought to you by DON'T PANIC, your friendly Werkzeug powered traceback interpreter.