AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-535406

sogu's questions

Martin Hope
sogu
Asked: 2020-04-07 15:49:19 +0800 CST

SQLite 工作,但 PostgreSQL 迁移数据库导致错误 - Django 3.0

  • 2

情况

  • 我已经用几个应用程序构建了 Django 3.0 项目。
  • 我已经根据以下课程创建了帐户应用程序,它是github
  • 比我创建了一个身份验证应用程序acc
  • 所有这些都在SQLite数据库中完成
  • 以前我已经为早期应用程序尝试了一个PostgreSQL数据库,它运行良好
  • 但是现在当我在 settings.py 文件中将SQLite切换到PostgreSQL时出现错误,我尝试登录
  • 如果我将 settings.py 切换回SQLite ,一切正常(例如:身份验证、使用用户登录、用户使用自己的设置在网站上执行操作)
  • 我使用 decorators.py 来保持登录用户访问登录和注册页面,当我切换到 postgresql 时会出错。我只在这里使用HttpResponse错误消息包含

装饰器.py

from django.http import HttpResponse
from django.shortcuts import redirect

def unauthenticated_user(view_func):
    def wrapper_func(request, *args, **kwargs):
        if request.user.is_authenticated:
            return redirect('home')
        else:
            return view_func(request, *args, **kwargs)

    return wrapper_func

def allowed_users(allowed_roles=[]):
    def decorator(view_func):
        def wrapper_func(request, *args, **kwargs):

            group = None
            if request.user.groups.exists():
                group = request.user.groups.all()[0].name

            if group in allowed_roles:
                return view_func(request, *args, **kwargs)
            else:
                return HttpResponse('Authorized')
        return wrapper_func
    return decorator

错误

如果我在 settings.py 使用PostgreSQL时登录。如果我注销一切正常。如果我使用 SQL lite,我可以登录并且一切正常

ValueError at /
The view accounts.decorators.wrapper_function didn't return an HttpResponse object. It returned None instead.
Request Method: GET
Request URL:    http://localhost...
Django Version: 3.0
Exception Type: ValueError
Exception Value: The view accounts.decorators.wrapper_function didn't return an HttpResponse object. It returned None instead.
Exception Location: /Users/.../python3.7/site-packages/django/core/handlers/base.py in _get_response, line 126
Python Executable:  /Users/.../bin/python3
Python Version: 3.7.3
.....

Request information
USER MYUSERNAME
GET No GET data
POST No POST data
FILES  No FILES data
COOKIES ...
...

试图解决

  • 我遵循的指南创建了我在迁移的 postgreSQL 数据库中也做过的用户组,但我仍然在评论部分收到与 USER1 相同的错误。
    • 这是视频底部的建议
    • “USER1我找到了,我忘记更改用户组了!
    • --> USER2 转到管理面板,然后在您的用户部分中,在所选组部分中添加客户”。
    • 我确实做到了,但没有奏效,唯一的区别是我使用了迁移的 postgresql,他们使用了原始的 SQLight .
  • 我在两个数据库中都有数据和表,但一些老员工使用PostgreSQL ,所有东西都使用SQLite。
    • 我尝试使用本指南将SQLite迁移到PostgreSQL。
    • 我已成功创建 SQLite 数据库的副本
    • 但是当我将设置更改为 postgres 并尝试python manage.py migrate时说Running migrations: No migrations to apply.
    • python manage.py loaddata db.json
    • 用户已从 SQLite 迁移(我可以使用他们登录并得到错误,就像唯一的 SQlite 用户一样,如果我输入错误的用户或密码,它不允许我进入),但我没有看到任何数据表在 Postgresql 中,如果我用 IDE 查找它
  • 我在论坛上与其他人交谈过,但很多人说这是有问题的装饰器文件,但它只发生在数据库切换时。
  • 我创建了一个新的 postgresql 数据库,并尝试迁移所有内容(迁移尚未迁移所有内容)。比我尝试使用新帐户注册时,它在填写表单按下提交后给了我以下错误消息
DoesNotExist at /register/
Group matching query does not exist.
django sql postgresql
  • 1 个回答
  • 200 Views
Martin Hope
sogu
Asked: 2020-04-07 06:25:52 +0800 CST

AWS RDS 到 PgAdmin 保存属性时出错 无法连接到服务器:超时已过期

  • 1

简短描述:AWS RDS 将服务器连接到 PgAdmin 4、PostgreSQL 11

完成:我已经完成了与此人或此aws 指南类似的操作,但最后当我单击保存时,它不接受我。而是给出以下

错误:

Error saving properties 
Unable to connect to server: 
timeout expired

我试图解决的问题:

  • 实例在创建后 2 小时处于活动状态
  • 我还允许在 AWS 数据库客户端“YES”之外访问数据库
  • 这个堆栈溢出答案并没有提供结果https://stackoverflow.com/a/37903485/10270590实际上在刷新我的安全组之后就像指南说我的整个数据库消失了
  • 我有家庭 wi-fi,所以没有公司防火墙或任何这些问题无法连接到 AWS RDS 实例
  • 在阅读之前的服务器故障帖子时,我查找了我的
    • RDS/数据库:什么是空的
    • RDS/安全组:空,我有这个消息:
Your account does not support the EC2-Classic Platform in this region. 
DB Security Groups are only needed when the EC2-Classic Platform is supported. 
Instead, use VPC Security Groups to control access to your DB Instances.

  • 我已经尝试过这个问题无法连接到有 2 个好的答案的公共 postgresql rds 实例,但即使在进行了更改后它们也给出了相同的错误
    • https://serverfault.com/a/656119/535406
    • https://serverfault.com/a/880710/535406
sql postgresql amazon-web-services amazon-rds
  • 2 个回答
  • 18697 Views
Martin Hope
sogu
Asked: 2020-03-27 07:20:23 +0800 CST

nginx 失败,而网站仍然可以正常工作

  • 0

描述

  • 我根据本指南构建了我的 Django3、gunicorn、nginx、Ubuntu 18.04、Digital Ocean 项目。我只有一个问题,它不显示 CSS 和所有其他静态文件,如图像。在整个指南之前,nginx 已经按照指南所说的给出了正确的答案,而且目前 html 站点仍然在线并正在运行
  • 为了解决这个问题,我正在使用另一个指南来让我的静态文件显示在我的网站上。我已经完成了创建者推荐的所有步骤,但在

我试过的

  • 在以下 [1.2.3...] 命令的每个步骤之后,我执行了以下命令来刷新:

    • python3 manage.py collectstatic
    • sudo nginx -t && sudo systemctl restart nginx
    • sudo systemctl restart gunicorn
  • 1.运行:sudo ln -s /etc/nginx/sites-available/ch-project /etc/nginx/sites-enabled

  • 1.结果:ln: failed to create symbolic link '/etc/nginx/sites-enabled/ch-project': File exists

  • 2.运行:/etc/nginx/sites-enabled/my-project

  • 2.结果:-bash: /etc/nginx/sites-enabled/my-project: Permission denied

  • 3.运行:systemctl status nginx.service

  • 3.结果:
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2020-03-26 13:27:08 UTC; 13s ago
     Docs: man:nginx(8)
  Process: 11111 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 11111 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
 Main PID: 11111 (code=exited, status=0/SUCCESS)
  • 4.运行:sudo nginx -t
  • 4.结果:
nginx: [emerg] open() "/etc/nginx/sites-enabled/myproject" failed (2: No such file or directory) in /etc/nginx/nginx.conf:62
nginx: configuration file /etc/nginx/nginx.conf test failed
    1. 否则 Nginex 应该没问题,因为网站上的 html 加载并运行良好。这个堆栈溢出帖子说我也许应该对安全性做一些事情,nginx.conf但在那种情况下,他们谈论的是一个 worldpres 网站,所以我不知道如何在这里实现它。
    1. 我之前尝试过这个堆栈溢出帖子的答案,下面是它有一个子帖子来进一步配置 RUN 的答案:sudo nginx -c /etc/nginx/sites-enabled/default -t
  • 6.结果:
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/sites-enabled/default:21
nginx: configuration file /etc/nginx/sites-enabled/default test failed
django python nginx ubuntu-18.04
  • 1 个回答
  • 924 Views
Martin Hope
sogu
Asked: 2020-03-25 11:30:32 +0800 CST

启动 gunicorn.service 失败:未找到单元 gunicorn.service。乌本托 18.04

  • 0

我正在关注如何在 Ubuntu 18.04 指南上使用 Postgres、Nginx 和 Gunicorn 设置 Django。

我创建了以下文件 .socket

sudo nano /etc/systemd/system/gunicorn.socket

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target

我创建了以下文件 .service

sudo nano /etc/systemd/system/gunicorn.service

指南中的原始 RECOMENDED_FORMATTING-s

[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target


[Service]
User=sammyRECOMENDED_FORMATTING
Group=www-data
WorkingDirectory=/home/sammyRECOMENDED_FORMATTING/myprojectdirRECOMENDED_FORMATTING
ExecStart=/home/sammyRECOMENDED_FORMATTING/myprojectdirRECOMENDED_FORMATTING/myprojectenvRECOMENDED_FORMATTING/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/gunicorn.sock \
          myprojectRECOMENDED_FORMATTING.wsgi:application

[Install]
WantedBy=multi-user.target

我如何格式化我自己的版本我在服务器上的项目文件夹之外拥有我的虚拟环境

[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
User=SERVER_USER
Group=www-data
WorkingDirectory=/home/SERVER_USER/MAIN_PROJECT_FOLDER
ExecStart=/home/SERVER_USER/ven/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/home/SERVER_USER/MAIN_PROJECT_FOLDER/MAINAPPLICATION_FOLDER.sock \
          MAINAPPLICATION_FOLDER.wsgi:application

[Install]
WantedBy=multi-user.target

我也尝试过按照最初的建议保留这些

--bind unix:/run/gunicorn.sock \

比我尝试执行以下代码

sudo systemctl start gunicorn

错误信息 1

Failed to start gunicorn.service: Unit gunicorn.service not found.

我也试过2

sudo systemctl start gunicorn.socket

错误信息 2

Failed to start gunicorn.socket: Unit gunicorn.socket is not loaded properly: Invalid argument.
See system logs and 'systemctl status gunicorn.socket' for details.

为了解决这个问题,我尝试过

  • https://stackoverflow.com/questions/40711747/failed-to-start-gunicorn-service-unit-gunicorn-service-not-found这指向了我正在做的完全相同的指南,除了旧版本的 linux .
  • 这不是相同的代码,也没有回答https://askubuntu.com/questions/748836/unit-gunicorn-service-failed-to-load-no-such-file-or-directory
  • 运行:systemctl status gunicorn.socket结果:Warning: The unit file, source configuration file or drop-ins of gunicorn.socket changed on disk ● gunicorn.socket - gunicorn daemon Loaded: error (Reason: Invalid argument) Active: inactive (dead)
  • 运行:systemctl is-enabled gunicorn.socket结果:enabled
  • 运行:systemctl is-enabled gunicorn.service结果:Failed to get unit file state for gunicorn.service: No such file or directory
ubuntu django python gunicorn ubuntu-18.04
  • 1 个回答
  • 2639 Views
Martin Hope
sogu
Asked: 2020-03-19 09:40:13 +0800 CST

Digital Ocean 服务器 SSH 登录故障

  • 2

我做了什么

  1. 创造了一个新的数字海洋水滴和
  2. 根据本指南创建 SSH 密钥,在创建 Droplet 期间我已将其复制到
  3. 我从这里运行了以下代码
ssh root@your_server_ip
adduser sammy
usermod -aG sudo sammy
  1. 比我尝试以“sammy”身份登录
ssh sammy@your_server_ip

错误

  • Permission denied (publickey).
  • 如果我以 root 访问权限登录,那么我可以像以前一样进入

我尝试过的修复

  1. 清理放 shh 密钥文件夹,只有这个密钥在那里
  2. 我还没有找到任何答案,但我的问题有点像这样
  3. 这和这个不太相似。
  4. ssh -vvv root@my_ip从这里它推出像调试线我应该寻找什么?
  5. 我试图在 ubuntu 上阅读 sshd 服务器日志,这是最常见的消息
Disconnected from invalid user somefirstname43
Disconnected from invalid user someotherfirstname334
Disconnected from authenticating user root
Received disconnect from ID port ...
Accepted publickey for root from ID
Did not receive identification string from  ID port ....
Connection closed by authenticating user sammy ID port portnumber  <<----
ubuntu ssh digital-ocean
  • 2 个回答
  • 347 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve