我在我的expressjs项目中使用Ejs模板引擎,尽管将我的对象传递到我的视图blog.ejs文件,但我blogpost not defined在我的ejs文件中收到错误.错误发生在我的<% blogpost.forEach(function(blogpost) { %>行.我认为这与如何通过对象及其属性有关,但我遵循指南,它看起来是正确的.
routes.js:
//blog
router.route('/blog')
// START POST method
.post(function(req, res) {
var blogpost = new Blogpost(); // create a new instance of a Blogpost model
blogpost.title = req.body.title; // set the blog title
blogpost.author = req.body.author; // set the author name
blogpost.content = req.body.content; // set the blog content
blogpost.date = req.body.date; // set the date of the post
//Save Blog Post
blogpost.save(function(err) {
if (err)
res.send(err);
res.json({ message: 'Blog created.' …Run Code Online (Sandbox Code Playgroud) 我有一些jQuery逻辑设置,用户可以在其中提交多个字段值,这些字段值应该作为我的数据库中的单个记录创建.我以前解决这个问题的方法是将我的值映射到随后与该.bulkCreate方法一起使用的变量,但我不知道MYSQL不支持使用此方法自动递增字段.结果我决定采用我的逻辑,而是使用该.create方法创建一个for循环.不幸的是,我收到此错误消息:TypeError: this.build(...).save is not a function在行models.DiscoverySource.create(sources).为什么在我不使用构建方法时会出现此消息?
.post(function(req, res){
console.log(req.body.discoverySource);
var sources = _.map(req.body.discoverySource, function (source) {
return {
discoverySource: source,
organizationId: req.body.organizationId
};
});
console.log("These are the" + sources); //outputs "These are the [object Object],[object Object], [object Object]
console.log(sources[0].discoverySource); //outputs correctly first value
console.log(sources[0].organizationId); //outputs correctly the first value
for (i=0; i < sources.length; i++){
models.DiscoverySource.create(sources)
.then(function(){
return models.DiscoverySource.findAll();
}).then(function(discoverySource){
console.log(discoverySource);
res.redirect('/app');
}).catch(function(error){
res.send(error);
console.log('Error during Post: ' + error);
});
} …Run Code Online (Sandbox Code Playgroud) 我有一个场景,我试图查询具有两个关联表(引用和用户)的父表(文档),它们彼此没有关系,但与父表有关系。在 SQL 中,这个查询看起来像这样并正确输出我正在寻找的数据:
select *
from `document`
left join `user`
on `document`.`user_id` = `user`.`user_id`
left join `reference`
on `document`.`reference_id` = `reference`.`reference_id`
where `user`.`organization_id` = 1;
Run Code Online (Sandbox Code Playgroud)
但是,嵌套的关联必须按层次顺序关联,以便查询工作。由于嵌套关联彼此不相关,因此出现关联错误。我怎样才能避免这个错误?请问required: false对此有何影响?
models.Document.findAll({
order: 'documentDate DESC',
include: [{
model: models.User,
where: { organizationId: req.user.organizationId },
include: [{
model: models.Reference,
}]
}],
})
Run Code Online (Sandbox Code Playgroud)
错误:
未处理的拒绝错误:引用与用户无关!
协会:
Document:
associate: function(db) {
Document.belongsTo(db.User, {foreignKey: 'user_id'}),
Document.belongsTo(db.Reference, { foreignKey: 'reference_id'});;
}
Run Code Online (Sandbox Code Playgroud)
Reference:
associate: function(db){
Reference.hasMany(db.Document, { foreignKey: 'reference_id' });
}
Run Code Online (Sandbox Code Playgroud)
我应该只链接查询吗?
我在成功的身份验证中加载页面时会出现一条 flash 消息,我正在尝试弄清楚如何将它水平居中放置在任何设备上。我现在用的是TailwindCSS调整DIV的位置,并试图fixed和absolute确保它出现我上面的内容,而是使用类似的属性,left:50%它也远远超过了移动和margin:auto不居中该元素。有没有更好的方法来解决我想要做的事情?是否可以使用 TailwindCSS 或者我必须为此编写一些 CSS?
代码:
<div>
<div className="mx-auto sm:w-3/4 md:w-2/4 absolute" id="signin-success-message">
<div className="bg-green-200 px-6 py-4 my-4 rounded-md text-lg flex items-center w-full">
<svg viewBox="0 0 24 24" className="text-green-600 w-10 h-10 sm:w-5 sm:h-5 mr-3">
<path fill="currentColor" d="M12,0A12,12,0,1,0,24,12,12.014,12.014,0,0,0,12,0Zm6.927,8.2-6.845,9.289a1.011,1.011,0,0,1-1.43.188L5.764,13.769a1,1,0,1,1,1.25-1.562l4.076,3.261,6.227-8.451A1,1,0,1,1,18.927,8.2Z"></path>
</svg>
<span class="text-green-800">{ body ? body : '' }</span>
</div>
</div>
<div>
...
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我手动添加了两个额外的控制器(UINavigationControllerDelegate&UIImagePickerController)到a UIViewController,我收到一个错误后添加UIImagePickerController说,
Multiple inheritance from classes UIViewController and UIImagePickerController
我不确定如何解释和解决这个问题.
由于这个错误,当我使用该image.delegate方法并将其设置为等于时,我也会看到一个self
Type ViewController does not conform to protocol UIImagePickerControllerDelegate
码:
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerController {
@IBAction func pickImage(sender: UIButton) {
var image = UIImagePickerController()
image.delegate = self
image.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
image.allowsEditing = false
self.presentViewController(image, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud) 我试图将我的私有 github 存储库克隆到我的 EC2 实例,但看来我可能采取了错误的步骤来允许 Github 连接到 EC2 实例。在git clone git@github.com:username/repo.git我在路径中创建的文件夹中运行/var/www/app时,我被告知要验证 Githbuc.com 主机并提供两个 RSA 密钥指纹(我假设是我的存储库中的指纹),然后向我发送一个错误:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)
在运行命令之前,git clone我将在我的 SSH 密钥中找到的 SSH 密钥复制.pem到我的 Github SSH 密钥。我使用这些 EC2 凭证通过 SSH 连接到实例。这是使用错误的密钥吗?我知道 EC2 实例也有公钥.ssh/authorized_keys,但我觉得这些与用于通过 SSH 连接到实例的公钥相同。
我是不是少了一步?我需要在/var/www/app目录中初始化 git 或在git clone命令之前配置任何内容吗?
任何帮助都会很棒。谢谢你!
我正在尝试正确查询所有符合我的续集查询的图像以及连接到特定查询的描述,但是我收到一个createdAt列的错误,该列不在我的表中.如何在查询中指定要使用的列?
这是查询(模式和颜色被正确地拉入查询):
router.get('/:pattern/:color/result', function(req, res){
console.log(req.params.color);
console.log(req.params.pattern);
Images.findAll({
where: {
pattern: req.params.pattern,
color: req.params.color
}
});
//console.log(image);
//console.log(doc.descriptions_id);
res.render('pages/result.hbs', {
pattern : req.params.pattern,
color : req.params.color,
image : image
});
});
Run Code Online (Sandbox Code Playgroud)
这是我的表:
CREATE TABLE `images` (
`id` int(5) NOT NULL AUTO_INCREMENT,
`pattern` varchar(225) DEFAULT NULL,
`color` varchar(225) DEFAULT NULL,
`imageUrl` varchar(225) DEFAULT NULL,
`imageSource` varchar(225) DEFAULT NULL,
`description_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `description_id` (`description_id`),
CONSTRAINT `images_ibfk_1` FOREIGN KEY (`description_id`) REFERENCES `description` (`description_id`)
) ENGINE=InnoDB AUTO_INCREMENT=47 …Run Code Online (Sandbox Code Playgroud) 我一直在阅读大量的sequelize-cli文档,似乎无法弄清楚如何将列添加到我现有的模型中.我有一个名为的模型,models/team.js并希望添加一个名为role_name模型的列sequelize model:create --name team --attributes role_name:string,但是我收到一条消息要覆盖而不是修改:
Loaded configuration file "config/config.json".
Using environment "development".
The file /Users/user/Desktop/Projects/node/app-repo/app/models/team.js already exists. Run "sequelize model:create --force" to overwrite it.
Run Code Online (Sandbox Code Playgroud)
我不想覆盖使我认为这不是正确使用命令的文件.它还让我想知道cli是否无法实现这一点,必须在迁移文件级别进行调整.
我获取了一些每日日期格式的 csv 数据,并将该数据重新采样为每月数据,现在想要使用 matplotlib 进行可视化。但是,当我尝试绘制重新采样的时间序列数据时,我遇到了以下错误,并且不确定如何继续。我尝试参考两者df.index但df.index.values没有成功
KeyError: "None of [DatetimeIndex(['2019-02-28', '2019-03-31',\n '2019-04-30', '2019-05-31', '2019-06-30', '2019-07-31',\n '2019-08-31', '2019-09-30', '2019-10-31', '2019-11-30',\n '2019-12-31', '2020-01-31'],\n dtype='datetime64[ns]', freq=None)] are in the [columns]"
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
# Libraries
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
df = pd.read_csv('tv-sales.csv', parse_dates=['Date'], index_col='Date')
df.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 365 entries, 2019-02-01 to 2020-01-31
Data columns (total 6 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Spend 365 non-null float64
1 Traffic …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Sequelize CLI工具运行数据库迁移,但是遇到一个问题,该工具未处理我的ENV变量。在github存储库中,它说在版本2.0.0(我在2.4.0中)中,您可以config/config.js像这样直接访问ENV变量process.env.DB_HOSTNAME,但是我收到一条错误消息,指示未传递任何值来自变量
错误:
Unable to connect to database: SequelizeAccessDeniedError: ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: NO)
Run Code Online (Sandbox Code Playgroud)
config.js:
module.exports = {
"development": {
"username": process.env.LOCAL_USERNAME,
"password": process.env.LOCAL_PASSWORD,
"database": process.env.LOCAL_DATABASE,
"host": "127.0.0.1",
"dialect": "mysql",
"migrationStorageTableName": "sequelize_meta"
},
}
Run Code Online (Sandbox Code Playgroud)
.env:
LOCAL_DATABASE="db_name"
LOCAL_USERNAME="root"
LOCAL_PASSWORD="test"
Run Code Online (Sandbox Code Playgroud) sequelize.js ×5
express ×3
mysql ×2
node.js ×2
amazon-ec2 ×1
associations ×1
css ×1
ejs ×1
git ×1
github ×1
ios ×1
matplotlib ×1
pandas ×1
python ×1
ssh ×1
swift ×1
tailwind-css ×1