Django正在设置DigitalOchean Postgre“DATABASES={”ERORR

2024-09-27 21:34:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我遵循https://www.udemy.com/course/the-ultimate-beginners-guide-to-django-django-2-python-web-dev-website/learn/lecture/9517168#overview指南在带有Postgres数据库的数字海洋服务器上建立aDjango网站。你知道吗

教师遵循的指南是官方的数字海洋设置指南https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04#creating-and-configuring-a-new-django-project

在我尝试迁移服务器端的项目之前,一切都很好:

  • 我在终端中运行的第一个语法

    python manage.py makemigrations
    
  • 第一个错误

     File "manage.py", line 16
     ) from exc
          ^
     SyntaxError: invalid syntax
    
  • 我在终端上运行的第二个语法

    python3 manage.py makemigrations
    
  • 第二个错误

      Traceback (most recent call last):
      File "manage.py", line 21, in <module>
        main()
      File "manage.py", line 17, in main
        execute_from_command_line(sys.argv)
      File "/home/djangodeploy/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
        utility.execute()
      File "/home/djangodeploy/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 317, in execute
        settings.INSTALLED_APPS
      File "/home/djangodeploy/.local/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
        self._setup(name)
      File "/home/djangodeploy/.local/lib/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup
        self._wrapped = Settings(settings_module)
      File "/home/djangodeploy/.local/lib/python3.6/site-packages/django/conf/__init__.py", line 106, in __init__
        mod = importlib.import_module(self.SETTINGS_MODULE)
      File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 994, in _gcd_import
      File "<frozen importlib._bootstrap>", line 971, in _find_and_load
      File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 678, in exec_module
      File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
      File "/home/djangodeploy/portfolio-project/portfolio/settings.py", line 137, in <module>
        from .local_settings import *
      File "/home/djangodeploy/portfolio-project/portfolio/local_settings.py", line 5
        DATABASES = {
        ^
    IndentationError: unexpected indent
    
  • 我修改了原稿设置.py文件并将以下内容放在底部,如django local_settings import error

try:
    from .local_settings import *
except ImportError:
    pass
  • 我还尝试了导入设置更正(更改了用于发布的数据库数据的值)Django Local Settings
from settings import *

SECRET_KEY = 'MY_SECRET_KEY'

DEBUG = False

ALLOWED_HOSTS = ['164.143.264.187']

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'my_name',
        'USER': 'the_user_nameing_i_have',
        'PASSWORD': 'my_key',
        'HOST':'localhost',
        'POSRT': '6432',
    }
}

我仍然得到最初的错误。你知道吗

我的管理.py我尝试了两种选择



"""
# this commented out what the teacher has in his code
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "portfolio.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)
"""




# This is what I had
import os
import sys


def main():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'portfolio.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

根据普拉尼塔·甘地的评论更新1

  • 我已经卸载了服务器VENV中的所有4个库

  • 在本地机器上,我创建了一个要求.txt最初的venv as 普拉尼塔·甘地曾推荐过。然后把它放到服务器上,并试图将它安装到现在空的服务器venv上。

pip3 install -r requirements.txt

  • 我得到了以下信息:

Collecting Django==2.0.7
  Using cached https://files.pythonhosted.org/packages/ab/15/cfde97943f0db45e4f999c60b696fbb4df59e82bbccc686770f4e44c9094/Django-2.0.7-py3-none-any.whl
Collecting Pillow==5.0.0
  Using cached https://files.pythonhosted.org/packages/9a/2f/86941111d108fd060190c994f15881283b98693c1c370e74885cfc470eb3/Pillow-5.0.0-cp36-cp36m-manylinux1_x86_64.whl
Collecting psycopg2==2.7.4
  Using cached https://files.pythonhosted.org/packages/92/15/92b5c363243376ce9cb879bbec561bba196694eb663a6937b4cb967e230e/psycopg2-2.7.4-cp36-cp36m-manylinux1_x86_64.whl
Collecting psycopg2-binary==2.7.4
  Using cached https://files.pythonhosted.org/packages/5f/0b/aa7078d3f6d27d951c38b6a1f4b99b71b2caecebb2921b2d808b5bf0e2e0/psycopg2_binary-2.7.4-cp36-cp36m-manylinux1_x86_64.whl
Collecting pytz==2018.3
  Using cached https://files.pythonhosted.org/packages/3c/80/32e98784a8647880dedf1f6bf8e2c91b195fe18fdecc6767dcf5104598d6/pytz-2018.3-py2.py3-none-any.whl
Installing collected packages: pytz, Django, Pillow, psycopg2, psycopg2-binary
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/lib/python3.6/site-packages'
Consider using the `--user` option or check the permissions.

更新2

我已尝试强制安装基于 https://github.com/googlesamples/assistant-sdk-python/issues/236/moham96于2018年4月20日发表评论

您正试图将包安装到您没有写入权限的系统文件夹中。 您有三个选项(仅使用其中一个):

  • 1-安装虚拟环境以安装软件包(推荐):
python3 -m venv env
source ./env/bin/activate 
python -m pip install requirements.txt
  • 2-将软件包安装到用户文件夹:
python -m pip install --user requirements.txt
  • 3-使用sudo安装到系统文件夹(不推荐)
sudo python -m pip install requirements.txt

不幸的是,这些都没有解决我的问题。你知道吗


Tags: djangoinfrompyhttpsimporthomeexecute
1条回答
网友
1楼 · 发布于 2024-09-27 21:34:55

嗨,当课程提示时,您是否安装并激活了虚拟环境。我想可能是虚拟环境。你知道吗

你能在服务器终端找到你的venv或env文件夹吗?你知道吗

相关问题 更多 >

    热门问题