小编Jim*_*Jim的帖子

无法在Django上运行服务器(连接被拒绝)

我终于(想)成功安装了PostgreSQL和de psycopg2(我用的是Windows).顺便说一句,是否有一些方法可以检查它是否正常工作?

嗯,现在的想法是我无法启动服务器,而我键入'python manage.py runserver'它出现了这个(在命令的末尾):

conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: Connection refused (0x0000274D/10061)
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 8000?
could not connect to server: Connection refused (0x0000274D/10061)
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 8000?
Run Code Online (Sandbox Code Playgroud)

我已经搜索了很多关于它的文档,例如在本主题中,但我找不到让它正常工作的方法.我在pg_hba和postgresql文件中尝试了几处更改,但没有退出.在这一刻,pg_hba看起来像:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host    all             all             127.0.0.1            md5
# IPv6 local connections:
host …
Run Code Online (Sandbox Code Playgroud)

python django postgresql

13
推荐指数
5
解决办法
3万
查看次数

迁移新用户模型时出错

刚刚在我创建了一个用户模型,models.py用于保存数据库中的用户.该模型如下所示:

class User(AbstractBaseUser, PermissionsMixin):
    username = models.CharField(_('username'), max_length=30, unique=True,
        validators=[
      validators.RegexValidator(re.compile('^[\w.@+-]+$'), _('Enter a valid username.'), _('invalid'))
    ])
    first_name = models.CharField(_('first name'), max_length=30, blank=True, null=True)
    last_name = models.CharField(_('last name'), max_length=30, blank=True, null=True)
    email = models.EmailField(_('email address'), max_length=255)
    is_staff = models.BooleanField(_('staff status'), default=False,)
    is_active = models.BooleanField(_('active'), default=False,)
    date_joined = models.DateTimeField(_('date joined'), default=timezone.now)

    USERNAME_FIELD = 'username'
    REQUIRED_FIELDS = ['email',]

    class Meta:
        verbose_name = _('user')
        verbose_name_plural = _('users')

    def get_full_name(self):
        full_name = '%s %s' % (self.first_name, self.last_name)
        return full_name.strip()

    def get_short_name(self):
        return …
Run Code Online (Sandbox Code Playgroud)

migration django models

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

标签 统计

django ×2

migration ×1

models ×1

postgresql ×1

python ×1