我尝试CURD使用Flask和SQLAlchemy.But Error连接到数据库时进行操作.
这是Error日志.
/usr/local/lib/python3.4/dist-packages/flask_sqlalchemy/__init__.py:819: UserWarning: SQLALCHEMY_DATABASE_URI not set. Defaulting to "sqlite:///:memory:".
'SQLALCHEMY_DATABASE_URI not set. Defaulting to '
/usr/local/lib/python3.4/dist-packages/flask_sqlalchemy/__init__.py:839: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning.
'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
Run Code Online (Sandbox Code Playgroud)
这是我的代码和设置
# database.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
sqldb = SQLAlchemy(app)
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql+pymysql://root:root@localhost/myDbName"
# create …Run Code Online (Sandbox Code Playgroud) 我是新手NativeScript,我尝试使用NativeScript和运行我的 HelloWord 应用程序Angular。我连接了我的 android 设备,然后我运行命令tns run android它如何我跟随错误。
Error: ENOTEMPTY: directory not empty, rmdir 'C:\Users\Admin\AppData\Local\Temp\runtimeDir11923-7308-1ed73lj.8p03\framework\app\libs\runtime-libs' at Object.fs.rmdirSync (fs.js:846:18)
at rmkidsSync (C:\Users\Admin\AppData\Roaming\npm\node_modules\nativescript\node_modules\temp\node_modules\rimraf\rimraf.js:247:11)
at rmdirSync (C:\Users\Admin\AppData\Roaming\npm\node_modules\nativescript\node_modules\temp\node_modules\rimraf\rimraf.js:237:7)
at fixWinEPERMSync (C:\Users\Admin\AppData\Roaming\npm\node_modules\nativescript\node_modules\temp\node_modules\rimraf\rimraf.js:150:5)
at rimrafSync (C:\Users\Admin\AppData\Roaming\npm\node_modules\nativescript\node_modules\temp\node_modules\rimraf\rimraf.js:216:26)
at C:\Users\Admin\AppData\Roaming\npm\node_modules\nativescript\node_modules\temp\node_moules\rimraf\rimraf.js:245:5
Run Code Online (Sandbox Code Playgroud)
我怎么了?你能帮忙吗?
webpack nativescript angular2-nativescript nativescript-angular
我尝试使用npm mongoose-paginate但是填充不能正常工作
这是我的 UsersSchema.js
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var usersSchema = new Schema({
name : String,
created_at : { type : Date, default : Date.now }
});
module.exports = mongoose.model('users',usersSchema);
Run Code Online (Sandbox Code Playgroud)
这是帖子架构
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var mongoosePaginate = require('mongoose-paginate');
var postsSchema = new Schema({
user : { type: Schema.Types.ObjectId, ref: 'users' },
post : String,
created_at : { type : Date, default : Date.now }
});
postsSchema.plugin(mongoosePaginate);
module.exports = mongoose.model('posts',postsSchema); …Run Code Online (Sandbox Code Playgroud) 我正试图在MongoDB中找到一条记录,并_id从结果中过滤.
这是我的代码:
#app.py
@app.route('/login', methods = ['GET', 'POST'])
def login():
if request.method == "POST":
password = request.form.get('password')
email = request.form.get('email')
db = get_db()
data = db.author.find_one({'email' : email, 'password' : password})
print(data)
return 'data'
else:
return render_template('login.html')
Run Code Online (Sandbox Code Playgroud)
输出:
{'password': '123123', 'name': '<my_name>', 'email': '<my_email>', '_id': ObjectId('<an_object_id_string>')}
Run Code Online (Sandbox Code Playgroud)
如何_id从输出中过滤字段?
我需要连接两个数据库.默认数据库是固定的,但另一个是动态的,它基于URL.
例如,如果url是:yourapp.myweb.com,那么第二个数据库名称将是yourapp
我尝试将数据库连接到init .py但它显示我跟随错误
builtins.AssertionError
AssertionError: A setup function was called after the first request was handled. This usually indicates a bug in the application where a module was not imported and decorators or other functionality was called too late.
To fix this make sure to import all your view modules, database models and everything related at a central place before the application starts serving requests.
Run Code Online (Sandbox Code Playgroud)
这是我的init .py
from flask import Flask,session
from flask_sqlalchemy import SQLAlchemy
import …Run Code Online (Sandbox Code Playgroud) 当我更新记录时,它会删除现有字段并添加新字段.
这是更新前的记录:
{ "_id" : ObjectId("56a356863aa433ae37dc2cee"), "browser" : "Chrome", "version" : 47}
Run Code Online (Sandbox Code Playgroud)
这是我执行的命令:
db.collection('profiles')
.update({
'_id' : obj("56a356863aa433ae37dc2cee") },
{"first_name" : first_name, "last_name" : last_name, "email" : email},
function (err, result) {
console.log(result);
});
Run Code Online (Sandbox Code Playgroud)
这是我执行update命令后的记录:
{ "_id" : ObjectId("56a356c9a08487ed3719e40a"), "first_name" : "kaushik", "last_name" : "makwana", "email" : "kdmakwana" }
Run Code Online (Sandbox Code Playgroud) 我想为我的项目创建饼图,所以我正在使用ChartJS,但是mapJS存在一些问题,如果我使用10到20个数据字段,时间图表看起来不错,但是当我申请更多时在一个图表中超过50到60个数据字段,因此该图表看起来更小而不是图例,并且如果有时数据字段太多而不是图表隐藏,则只能看到图例,图表消失了.
我想将高度或宽度设置为该图例,如果有更多数据,还应用于滚动条.
这是小提琴链接供您参考
https://jsfiddle.net/KDM1010/5um78rbk/
<canvas id="myChart" width="500" height="300"></canvas>
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'pie',
data: {
labels: ["lable_1", "lable_2", "lable_3", "lable_4", "lable_5", "lable_6", "lable_7", "lable_8", "lable_9", "lable_10", "lable_11", "lable_12", "lable_13", "lable_14", "lable_15", "lable_16", "lable_17", "lable_18", "lable_19", "lable_20", "lable_21", "lable_22", "lable_23", "lable_24", "lable_25", "lable_26", "lable_27", "lable_28", "lable_29", "lable_30", "lable_31", "lable_32", "lable_33", "lable_34", "lable_35", "lable_36", "lable_37", "lable_38", "lable_39", "lable_40", "lable_41", "lable_42", "lable_43", "lable_44", "lable_45", "lable_46", "lable_47", "lable_48", "lable_49", "lable_50"],
datasets: [{
backgroundColor: ["#2ecc71","#3498db","#95a5a6","#9b59b6","#f1c40f","#e74c3c","#34495e","#2ecc71","#3498db","#9a5a6","#9b59b6","#f1c40f","#e74c3c","#34495e","#2ecc71","#3498db","#95a5a6","#9b59b6","#f1c40","#e74c3c","#34495e","#2ecc71","#3498db","#95a5a6","#9b59b6","#f1c40f","#e74c3c","#34495e","#2ecc71","#3498db","#95a5a6","#9b59b6","#f1c40f","#e74c3c","#34495e","#2ecc71","#3498db","#955a6","#9b59b6","#f1c40f","#e74c3c","#34495e","#2ecc71","#3498db","#95a5a6","#9b59b6","#f1c40f,"#e74c3c","#34495e","#2ecc71","#3498db","#95a5a6","#9b59b6","#f1c40f","#e74c3c","#34495e"
],
data: [74, …Run Code Online (Sandbox Code Playgroud) 我试图用mongoengine和烧瓶从mongodb中获取数据.查询是完美的工作问题是当我将查询结果转换为json时,它只显示字段名称.
这是我的代码
view.py
from model import Users
result = Users.objects()
print(dumps(result))
Run Code Online (Sandbox Code Playgroud)
model.py
class Users(DynamicDocument):
meta = {'collection' : 'users'}
user_name = StringField()
phone = StringField()
Run Code Online (Sandbox Code Playgroud)
产量
[["id", "user_name", "phone"], ["id", "user_name", "phone"]]
Run Code Online (Sandbox Code Playgroud)
为什么它只显示字段名称?
我是Python和MongoDB的新手,我正在使用flask-python和MongoDB开始一个新项目.当我尝试使用该aggregate()函数返回数据时,它给出了以下错误:
命令游标'对象不可订阅.
这是我的查询代码:
Data = db.mytable.aggregate([ { "$group": {"_id": "$Name" ,"count": { "$sum": 1 }}}])
return Data['result']
Run Code Online (Sandbox Code Playgroud)
我也改变了这个:
Data = db.mytable.aggregate([ { "$group": {"_id": "$Name" ,"count": { "$sum": 1 }}}],userCursor= False)
Run Code Online (Sandbox Code Playgroud)
但它给了我以下错误:
error.pymongo.errors.OperationFailure:command SON([('aggregate','mytable'),('pipeline',[{'$ group':{'_ id':'$ Name','count':{' $ sum':1}}}]),('useCursor',False)])命名空间mydb.$ cmd失败:无法识别的字段'useCursor
注意:我使用的是MongoDB 3.2和Python3
我是新来的Angular。我尝试使用Nodejs和创建 CRUD 操作Angular。我正在使用NodejsandExpress作为后端和Angular前端。
当我使用 routerLink 在页面上导航时,它工作正常,但是当我在页面上导航然后刷新页面时,它会显示页面未找到错误。
我知道那里发生了什么,Express 应用程序中没有定义路线,所以我刷新页面,它显示 404 错误。
如何使其与 Angular 和 Express 路线配合使用?
这是我的代码。
app.js( 服务器 )
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({extended : false}));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname,'dist/MEAN-blog')));
app.get('/',(req,res) =>{
res.sendFile(path.join(__dirname,'dist/MEAN-blog/index.html'));
});
app.post('/register',(req,res) =>{
var u = new User(req.body);
u.save();
res.send(u).status(200);
})
var server = http.createServer(app);
server.listen(8080,'0.0.0.0',() =>{
console.log('Server is running …Run Code Online (Sandbox Code Playgroud) javascript node.js http-status-code-404 angular-ui-router angular
mongodb ×5
flask ×4
javascript ×3
node.js ×3
python-3.x ×3
pymongo ×2
python ×2
sqlalchemy ×2
angular ×1
chart.js ×1
css ×1
jquery ×1
json ×1
mongoengine ×1
mongoose ×1
nativescript ×1
pie-chart ×1
webpack ×1