小编Dor*_*ora的帖子

能够检查数据库连接主机或名称(不是数据库名称而是设置)?姜戈

我不是要检查连接的 db 名称,我在 django 中设置了多个数据库,并且还使用它database route来创建一个,failover但我想知道是否可以获取连接主机的名称或指定给设置的名称。 .

例如

DATABASES = {
    'default': {  # trying to get this name 'default'
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'db_name',
        'USER': 'euser',
        'PASSWORD': 'password',
        'HOST': 'host', # trying to get this host name 'host'
        'PORT': 3306,
    },
    'node2': {  # trying to get this name 'node2'
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'db_name',
        'USER': 'euser',
        'PASSWORD': 'password',
        'HOST': 'host2',  # trying to get this host name 'host2'
        'PORT': 3306,
    },
}
Run Code Online (Sandbox Code Playgroud)

有没有可能得到我上面注释掉的那些名字?对于我的故障转移,如果正在使用另一个数据库,我会尝试发送电子邮件,但如果我能得到特别是host这样就更好了,这对我来说会更容易

PS题外话,名字可以改成 …

python mysql database django settings

2
推荐指数
1
解决办法
1268
查看次数

$ user-> getAuthPassword()和Auth :: user() - >密码之间有什么大不同?laravel 4

我正在网上学习这个登录教程,选择用户在登录后更改密码并给出注释

if ($validator->fails())
{
    return Redirect::route('account-change-password')
        ->withErrors($validator);
}
else
{
    $user = User::find(Auth::user()->id);

    $old_password = Input::get('old_password');
    $password = Input::get('password');

    if(Hash::check($old_password, $user->getAuthPassword()))
    {
        $user->password = Hash::make($password);

        if($user->save())
        {
            return Redirect::route('home')
                ->with('global', 'Your Password has been changed');
        }
    }
    else
    {
        return Redirect::route('account-change-password')
            ->with('global', 'Your old password is incorrect');
    }
}
Run Code Online (Sandbox Code Playgroud)

在else中的教程$user = User::find(Auth::user()->id);中立即使用,然后检查密码的if语句正在使用$user = User::find(Auth::user()->id);

当我在看完教程后尝试在我的上面做的时候我做了不同的事情.

if ($v->fails())
{
    return Redirect::route('account-change-password')
        ->withErrors($v)
        ->with('global', 'Please check the errors in red');
}
else
{
    if (Hash::check(Input::get('old_password'),Auth::user()->password))
    {
        $user = User::find(Auth::user()->id); …
Run Code Online (Sandbox Code Playgroud)

php authentication passwords if-statement laravel

1
推荐指数
1
解决办法
3546
查看次数

如何比较模型字段和选择中的unicode字符串?Django的

我不确定哪个部分我做错了但不知何故我试图比较两个值,我100%确定它们匹配但不知何故代码不会执行.

假设我有这个模型(请原谅模型和字段名称有点拼写错误)

class TestOne(models):
    gender = models.Charfield(max_length=10, choices=GENDER_CHOICES)
Run Code Online (Sandbox Code Playgroud)

我的选择

GENDER_CHOICES = (("MALE", "MALE"), ("FEMALE", "FEMALE"))
Run Code Online (Sandbox Code Playgroud)

我很确定我的gender领域是MALE针对该对象所以我正在做这个声明,检查它是否MALE有所作为.

if a.gender is `MALE`:
    # do something here
Run Code Online (Sandbox Code Playgroud)

但它永远不会真实地达到它.我查a.gender了一个unicode类型,所以我甚str(a.gender)至做了确保它也是一个字符串,但仍然没有运气.

我在这里做错了吗?

PS我打印过a.gender并确保输出结果MALE

提前致谢

python django unicode if-statement compare

1
推荐指数
1
解决办法
609
查看次数

open() "/root/project/static/*.css" 失败 (13: 权限被拒绝) nginx

我必须使用uwsgi, django, nginx 一切进行项目设置,似乎一切正常,但不知何故,我一直在获取错误,因为static files我一直在在线阅读并尝试了所有可能的方法,但我一直permission denied在我的静态文件夹中收到此错误。

有人可以让我知道我在权限上做错了什么以及我应该如何更改它吗?

这是我的 /var/log/nginx/error.log

open() "/root/project/static/*.css" failed (13: Permission denied), client: 2xx.xx.xx.xxx, server: _, request: "GET /static/*.css HTTP/1.1", host: "1xx.xx.xx.xxx"

这是我的 nginx site-available config

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # root /var/www/html;

    # Add index.php to the list if you are using PHP
    # index index.html index.htm index.nginx-debian.html;

    server_name _;

    #location = /favicon.ico { access_log off; log_not_found off; }

    #location /media  {
    #       root /root/project/mediafiles;
    #}


        location …
Run Code Online (Sandbox Code Playgroud)

django permissions ubuntu nginx django-staticfiles

1
推荐指数
1
解决办法
4512
查看次数

能够查询数组中的特定索引?猫鼬

例如,如果我有以下作为我的 documents

{
    "field": [
        "hello",
        "random wording",
        {
            "otherId": 3232,
            "otherId2": 32332
        }
    ],
}
Run Code Online (Sandbox Code Playgroud)

是否有可能让我们说有一个匹配的查询index 0index 2

我尝试进行查询,例如 model.find({field: "hello")似乎可以查询它。

但是,如果我想混搭,让我们说我想要做一个查询,无论比赛index 0index 2或假设中index 2的值实际上是一个object,我想查询所有"otherId2": 32332,而不是我需要整场比赛object

在此先感谢您的任何帮助或建议。

javascript arrays mongoose mongodb mongodb-query

1
推荐指数
1
解决办法
1340
查看次数

生产中Firebase的Cloud Functions上的mongodb错误

我开始与云功能玩弄了火力地堡,我做了本地所有的设置和运行firebase serve,并测试了我get,并post在MLAB MongoDB的设置。

我做了一个firebase deploy很好的部署,然后我回到家,准备玩更多游戏。我使用邮递员,并试图在生产中发布职位。我以某种方式收到Cloud Functions崩溃的错误

我可以看到似乎没有与此错误连接mongodb

MongoDB连接错误:{MongoNetworkError:首次连接时无法连接到服务器[dsxxxxx.mlab.com:xxxxx] [MongoNetworkError:getaddrinfo EAI_AGAIN dsxxxxxx.mlab.com:xxxxx]

名称:“ MongoNetworkError”,消息:“首次连接[MongoNetworkError:getaddrinfo EAI_AGAIN dsxxxxx.mlab.com:xxxxx]时,无法连接到服务器[xxxxx.mlab.com:xxxxx]”

有谁知道我所缺少的生产部署无法正常工作的信息?

在此先感谢您的帮助。

mongodb firebase google-cloud-functions

0
推荐指数
1
解决办法
433
查看次数