我使用flask,当我调用此url时出现此错误:/login
这是我的登录方法:
@app.route('/login')
def login():
if authenticateForPanel():
return redirect(url_for("panel"))
else:
getParam = request.args.getlist('redirect_uri')
if getParam:
ref =getParam[0]
else:
ref="/panel"
return render_template( themesDir + g.blogOptions['active_theme']+'/login.html', blogOptions = g.blogOptions, ref=ref )
Run Code Online (Sandbox Code Playgroud)
追溯:
Traceback (most recent call last):
File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1701, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1689, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1358, in full_dispatch_request
rv = …Run Code Online (Sandbox Code Playgroud) 我想获取上传图像的大小来控制它是否大于最大文件上传限制.我试过这个:
@app.route("/new/photo",methods=["POST"])
def newPhoto():
form_photo = request.files['post-photo']
print form_photo.content_length
Run Code Online (Sandbox Code Playgroud)
它打印0在哪里我做错了?我应该从它的临时路径中找到这个图像的大小吗?$_FILES['foo']['size']Python中没有类似PHP的东西吗?
我想向mysql发送一个查询并获取一个数组.但是,无论如何我都做不到.这是我的代码:
@app.route('/auth',methods=['GET','POST'])
def auth():
username = request.form['username']
password = request.form['password']
cur = db.cursor()
cur.execute("SELECT * FROM tbl_user WHERE username = '%s' " % username)
results = cur.fetchall()
for row in results:
print row[0]
Run Code Online (Sandbox Code Playgroud)
它总是说,view function did not return a response.我究竟做错了什么?
我想制作一个多文件上传表单.我使用jQuery File Uploader.我的服务器端代码:
@app.route("/new/photogallery",methods=["POST"])
def newPhotoGallery():
print request.files
Run Code Online (Sandbox Code Playgroud)
我尝试了两件事:
正常提交表格:
当我正常提交表格时,会打印:
ImmutableMultiDict([('post_photo_gallery', FileStorage: u'' ('application/octet-stream'))])
使用AJAX提交表单:
当我使用AJAX提交表单时,它会打印:
ImmutableMultiDict([])
我的第一个问题是:为什么AJAX请求和正常请求之间存在差异.
我的第二个问题是:我如何处理这个application/octet-stream请求Flask/Python
我的第三个问题是:这是一个好用的方法application/octet-stream吗?
顺便说一下,我不太了解application/octet-stream.非常感谢你.
我初学者用python.I想将sql结果转换为list.Here是我的代码:
cursor = connnect_db()
query = "SELECT * FROM `tbl`"
cursor.execute(query)
options = list()
for i,row in enumerate(cursor.fetchall()):
options.append(row[i])
Run Code Online (Sandbox Code Playgroud)
我的表中有6列但是这段代码没有创建6个元素列表.我做错了什么?
我使用Flask并想要更改我的资产文件夹目录.这是我的文件夹结构:
/python
/static
/js
/img
/font
/css
/templates
/default
/css
/js
/img
/venv
app.py
Run Code Online (Sandbox Code Playgroud)
我想将静态文件夹(js,css,font,img)下的所有文件夹移动到该文件夹下default.但当我这样做我的CSS文件和其他(js etc.)无法加载页面.我应该设置属性到我的应用程序?我也试过这个:
app = Flask(__name__,static_path="/templates/default")
Run Code Online (Sandbox Code Playgroud)
但是无法做到.有另外一种方法吗?非常感谢.
更新:
当我删除上面一行中的前导斜杠时(static_path="templates/default")ValueError: urls must start with a leading slash
使用traceback 获得此错误:
Traceback (most recent call last):
File "app.py", line 17, in <module>
app = Flask(__name__,static_path="templates/default")
File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 481, in __init__
view_func=self.send_static_file)
File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 63, in wrapper_func
return f(self, *args, **kwargs)
File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 943, in add_url_rule
rule = self.url_rule_class(rule, …Run Code Online (Sandbox Code Playgroud) 我想在c中读取一个文件.我有一个.txt文件,它有这个内容:
file_one.txt file_two.txt file_three.txt file_four.txt
当我尝试使用fopen读取此文件时,我得到此输出:
file_one.txt file_two.txt file_three.txt file_four.txt\377
什么是\ 377是什么意思?这是我的代码.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char * argv[]){
FILE *filelist;
char ch;
filelist=fopen("file-path", "rt");
while (!feof(filelist)) {
ch = getc(filelist);
printf("%c",ch);
}
fclose(filelist);
return 0;
}
Run Code Online (Sandbox Code Playgroud)