当我使用以下内容将文件发布到烧瓶服务器时使用原始.html我可以访问烧瓶请求全局中的文件:
<form id="uploadForm" action='upload_file' role="form" method="post" enctype=multipart/form-data>
<input type="file" id="file" name="file">
<input type=submit value=Upload>
</form>
Run Code Online (Sandbox Code Playgroud)
在烧瓶中:
def post(self):
if 'file' in request.files:
....
Run Code Online (Sandbox Code Playgroud)
当我尝试对Axios执行相同操作时,求助栏请求全局为空:
<form id="uploadForm" enctype="multipart/form-data" v-on:change="uploadFile">
<input type="file" id="file" name="file">
</form>
uploadFile: function (event) {
const file = event.target.files[0]
axios.post('upload_file', file, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
}
Run Code Online (Sandbox Code Playgroud)
如果我使用上面的相同uploadFile函数但是从axios.post方法中删除了头json,我在我的flask请求对象的表单键中获得了一个字符串值的csv列表(文件是.csv).如何获取通过axios发送的文件对象?
在VueJS中,我们可以使用v-if添加或删除DOM元素:
<button v-if="isRequired">Important Button</button>
Run Code Online (Sandbox Code Playgroud)
但有没有办法添加/删除dom元素的属性,例如以下有条件地设置所需的属性:
Username: <input type="text" name="username" required>
Run Code Online (Sandbox Code Playgroud)
通过类似的东西:
Username: <input type="text" name="username" v-if="name.required" required>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
Python新手来自Java(+ SWT/Windowbuilder),我很难解决如何在Python/Qt4(QtDesigner)/ PySide中正确编写大型桌面应用程序的问题.
我想在.ui文件之外的控制器类中保留任何视图逻辑(并且它是.py转换).首先,逻辑独立于GUI框架,其次是.ui和结果.py文件在任何更改时都会被覆盖!
我发现只有一些例子将动作代码添加到单片MainWindow.py(从ui生成)或MyForm.py(也是从.ui生成)中.我看不到任何方法将POPO控制器类链接到QtDesigner中的操作.
有人能指出我在可扩展的MVC/P方法中使用QtDesigner创建大规模应用程序的工作流程吗?
我有一个Flask应用程序,我试图通过Gunicorn服务.
我正在使用virtualenv和python3.如果我将我的venv cd激活到我的app base dir,那么运行:
gunicorn mysite:app
Run Code Online (Sandbox Code Playgroud)
我明白了:
Starting gunicorn
Listening at http://127.0.0.1:8000
DEBUG:mysite.settings:>>Config()
...
Failed to find application: 'mysite'
Worker exiting
Shutting down: master
Reason: App failed to load
Run Code Online (Sandbox Code Playgroud)
查看/ etc/nginx/sites-available我只有文件'default'.在已启用网站的情况下,我没有文件.
在我的nginx.conf文件中,我有:
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
Run Code Online (Sandbox Code Playgroud)
应用结构:
mysite #this is where I cd to and run gunicorn mysite:app
--manage.py
--/mysite
----settings.py
----__init__.py
Run Code Online (Sandbox Code Playgroud)
在manage.py为mysite的我有以下几点:
logger.debug("manage.py entry point")
app = create_app(app_name)
manager = Manager(app)
if __name__ == "__main__":
manager.run()
Run Code Online (Sandbox Code Playgroud)
在__init__.py档案中:
def create_app(object_name):
app = Flask(__name__)
#more setup …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建这种几何:
_ ___
| | |
|1| 3 |
|_|___|
|_2_|
Run Code Online (Sandbox Code Playgroud)
1盒子高而瘦,2盒子短而宽.我无法完全理解布局.当我将rowSpan和columnSpan从1和2装入0到1时,我看到底部框在正确的相对位置但是高度错误,并且框1的宽度错误.
这样qq帮助但没有完全解决我的问题:如何安排QGridLayout中的项目,如图所示?
import sys
from PyQt4 import QtGui
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
textEdit1 = QtGui.QTextEdit("LHS rectangle")
textEdit2 = QtGui.QTextEdit("Bottom rectangle")
textEdit3 = QtGui.QTextEdit("Central square")
self.gridLayout = QtGui.QGridLayout()
self.gridLayout.addWidget(textEdit1, 0, 0, 2, 0)
self.gridLayout.addWidget(textEdit2, 2, 1, 0, 2)
self.gridLayout.addWidget(textEdit3, 0, 1, 2, 2)
self.setLayout(self.gridLayout)
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud) 我试图使用Vuejs切换容器div的可见性我已经尝试了两种方法,但是对容器的可见性都没有任何影响.方法1:
<body>
<div class="checkbox" id = "selector">
<label><input type="checkbox" v-model="checked">Options</label>
</div>
<div class="container" id="app-container" v-if="checked">
<p>Text is visible</p>
</div>
<script src="path_to_/vue.js"></script>
<script>
var app = new Vue({
el: '#selector',
data: {
"checked": false
}
})
</script>
</body>
Run Code Online (Sandbox Code Playgroud)
我知道Vue.js加载好了,勾选复选框对文本可见性没有影响.
方法2:
<body>
<div class="checkbox" id = "selector">
<label><input type="checkbox" v-on:click="seen = !seen">Options</label>
</div>
<div class="container" id="app-container" v-if="seen">
<p>Text is visible</p>
</div>
<script src="path_to_/vue.js"></script>
<script>
var app = new Vue({
el: '#selector',
data: {
"seen": false
}
})
</script>
</body>
Run Code Online (Sandbox Code Playgroud)
再次勾选复选框无效.有任何想法吗?
在Datatables API说明中,您可以切换列可见性https://datatables.net/extensions/buttons/examples/column_visibility/columns.html:
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
{
extend: 'colvis',
columns: ':not(:first-child)'
}
]
} );
} );
Run Code Online (Sandbox Code Playgroud)
但是有没有办法通过鼠标点击选择一个列,就像选择一行一样 - 即让用户通过突出显示列来了解列的选择 - 并从javascript访问该列中的数据(例如,在该列之后添加另一列)选中列或删除所选列并重新加载表,计算列中数据的统计信息等.?)
我想循环遍历列表,列表从零开始,但列表起始索引为1,例如:
valueList = [1, 2, 3, 4]
secondList = ['a', 'b', 'c', 'd']
for i, item in enumerate(valueList, start=1):
print(secondList[i])
Run Code Online (Sandbox Code Playgroud)
代码失败,索引超出范围错误(我意识到这是因为我在列表的长度-1加上起始值,并且python列表为零索引,因此使用i以这种方式调用另一个中的第i个元素列表无效).以下工作,但增加大于零的测试看起来是非pythonic.
valueList = [1, 2, 3, 4]
secondList = ['a', 'b', 'c', 'd']
for i, item in enumerate(valueList, start=0):
if i > 0:
print(secondList[i])
Run Code Online (Sandbox Code Playgroud)
枚举不是正确的选择,还有另一种方式吗?
处理依赖于调用代码的最佳单元处理方式是什么,而调用代码又依赖于当前应用程序的配置?
例如
代码
from flask import current_app
def some_method():
app = current_app._get_current_object()
value = (app.config['APP_STATIC_VAR'])*10
return value
Run Code Online (Sandbox Code Playgroud)
test_code.py
class TestCode(unittest.TestCase):
def test_some_method(self):
app = create_app('app.settings.TestConfig')
value = some_method()
self.assertEqual(10, value)
Run Code Online (Sandbox Code Playgroud)
在执行上面的测试时,当执行app = create_app('app.settings.TestConfig')行时,出现“ RuntimeError:在应用程序上下文之外工作”错误。
在测试过程中调用app = create_app不会成功。在这种情况下,我需要在应用程序中读取配置时,进行单元测试的最佳方法是什么?
我可以通过使用df.astype()方法转换为'category'来转换pandas数据框中的所有文本功能,如下所示.但是我觉得类别难以使用(例如用于绘制数据),并且更愿意创建一个新的整数列
#convert all objects to categories
object_types = dataset.select_dtypes(include=['O'])
for col in object_types:
dataset['{0}_category'.format(col)] = dataset[col].astype('category')
Run Code Online (Sandbox Code Playgroud)
我可以使用这个hack将文本转换为整数:
#convert all objects to int values
object_types = dataset.select_dtypes(include=['O'])
new_cols = {}
for col in object_types:
data_set = set(dataset[col].tolist())
data_indexed = {}
for i, item in enumerate(data_set):
data_indexed[item] = i
new_list = []
for item in dataset[col].tolist():
new_list.append(data_indexed[item])
new_cols[col]=new_list
for key, val in new_cols.items():
dataset['{0}_int_value'.format(key)] = val
Run Code Online (Sandbox Code Playgroud)
但是有更好的(或现有的)方法吗?
python ×5
javascript ×3
flask ×2
pyqt ×2
vue.js ×2
ajax ×1
axios ×1
datatables ×1
file-upload ×1
gunicorn ×1
jquery ×1
nginx ×1
pandas ×1
pyqt4 ×1
pyqt5 ×1
pyside ×1
qt ×1
qt-designer ×1
unit-testing ×1
vuejs2 ×1